O
O
Old Odessa2015-11-23 00:56:50
C++ / C#
Old Odessa, 2015-11-23 00:56:50

Where to dig, game 21 points?

Please tell me the best way to implement.
You need to write a game - 21 points in C ++ in the console. For a game between two people.
36 cards, ace -11 points, jack 2, queen 3, king 4. Digital, respectively, at face value 6-10.
each in turn takes out a card, or adds another, or opens, or he has 21. The one who has either more, or 21, or less bust wins.
I just started learning programming, and I don't know where to dig.
As I understand it, I need an array of 36 cards, and in it to arrange a random sample and a function that will execute this sample. The function must be called in a loop until one player either has a bust, or he reveals the cards, or two busts. mess in my head. help with the algorithm, and with how exactly to implement the program.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
MiiNiPaa, 2015-11-23
@MiiNiPaa

Create an array of 36 cards including all possible cards. Then stir it. Then just take out the cards one by one.
PS If you need C++, remove the C tag

D
Duha666, 2015-11-23
@Duha666

If the cards are dealt not in turn, but as in blackjack. I can suggest the following variant of writing. If not, then I think you can fix it yourself.
Player #1 draws cards. We make an infinite loop. In it we ask what the player wants now - to stop or take. If we take it, then we call some getNewCard () function, which I will describe below. She will return the points for the card. If the bust or the player said to stop, then exit the loop. By the way, when iterating, the number of points can be equated to -1, it will be easier.
Similarly for player #2. Then we compare the result.
Now about the getNewCard() function. She needs to know which cards have already been dealt. Therefore, you can store at least an array of 36 card values ​​(for the first time, this option will do, it is easier to understand) and another array in which we store whether this card was issued. We still keep how many cards are left. When the function is called, we generate a random number from 0 to the number of remaining cards. Then we count in the array such an unused card. We mark it used, return its number of points.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question