Poker Program

A

Alias

I'm taking a C++ Class, and I'm supposed to be writing a program that
basically simulates poker, minus the straight flush, royal flush, and
full house.

Anyway, you input the number of players, and it checks for a pair,
three of a kind, four of a kind, two pair, a flush, and a straight.

If you've got two players or more, it deals player one's cards [1 - 5],
checks for a pair, three of a kind, etc, etc all the way through, and
tells you what the best thing you're holding is. Once it goes for the
second player, however, it deals fine [6 - 10], looks for a Pair
perfectly fine, but when it gets to the three of a kind, it identifies
cards 6, 7, and 8, but when it checks to figure out what card 9 is, it
crashes.

If that does't really make sense, it basically has a set matrix of
suits and face values, then assigns each one a "drawing order". Player
one gets cards that have the assigned drawing orders of 1 - 5, player 2
gets 6 - 10, etc.

Any help would be greatly appreciated.
 
A

Artie Gold

Alias said:
I'm taking a C++ Class, and I'm supposed to be writing a program that
basically simulates poker, minus the straight flush, royal flush, and
full house.

Anyway, you input the number of players, and it checks for a pair,
three of a kind, four of a kind, two pair, a flush, and a straight.

If you've got two players or more, it deals player one's cards [1 - 5],
checks for a pair, three of a kind, etc, etc all the way through, and
tells you what the best thing you're holding is. Once it goes for the
second player, however, it deals fine [6 - 10], looks for a Pair
perfectly fine, but when it gets to the three of a kind, it identifies
cards 6, 7, and 8, but when it checks to figure out what card 9 is, it
crashes.

If that does't really make sense, it basically has a set matrix of
suits and face values, then assigns each one a "drawing order". Player
one gets cards that have the assigned drawing orders of 1 - 5, player 2
gets 6 - 10, etc.

Any help would be greatly appreciated.

Seeing no code makes this difficult (hint...hint...)

<swag>
Are you aware that arrays are zero based in C++?
</swag>

Post compilable code.

HTH,
--ag
 
C

Calum Grant

Alias said:
I'm taking a C++ Class, and I'm supposed to be writing a program that
basically simulates poker, minus the straight flush, royal flush, and
full house.

Anyway, you input the number of players, and it checks for a pair,
three of a kind, four of a kind, two pair, a flush, and a straight.

If you've got two players or more, it deals player one's cards [1 - 5],
checks for a pair, three of a kind, etc, etc all the way through, and
tells you what the best thing you're holding is. Once it goes for the
second player, however, it deals fine [6 - 10], looks for a Pair
perfectly fine, but when it gets to the three of a kind, it identifies
cards 6, 7, and 8, but when it checks to figure out what card 9 is, it
crashes.

If that does't really make sense, it basically has a set matrix of
suits and face values, then assigns each one a "drawing order". Player
one gets cards that have the assigned drawing orders of 1 - 5, player 2
gets 6 - 10, etc.

Any help would be greatly appreciated.

There's a really efficient representation of a deck of cards for poker:

struct Hand
{
short suit[4];
};

Assuming a short is 16 bits. You can use one bit to represent each
card. Using various bitwise operations, this representation makes it
very efficient to determine different poker hands. But seeing how this
is a C++ class, you are probably supposed to represent your hands in a
more object-oriented way.

Calum
 
A

Andrew McDonagh

Calum said:
Alias said:
I'm taking a C++ Class, and I'm supposed to be writing a program that
basically simulates poker, minus the straight flush, royal flush, and
full house.

Anyway, you input the number of players, and it checks for a pair,
three of a kind, four of a kind, two pair, a flush, and a straight.

If you've got two players or more, it deals player one's cards [1 - 5],
checks for a pair, three of a kind, etc, etc all the way through, and
tells you what the best thing you're holding is. Once it goes for the
second player, however, it deals fine [6 - 10], looks for a Pair
perfectly fine, but when it gets to the three of a kind, it identifies
cards 6, 7, and 8, but when it checks to figure out what card 9 is, it
crashes.

If that does't really make sense, it basically has a set matrix of
suits and face values, then assigns each one a "drawing order". Player
one gets cards that have the assigned drawing orders of 1 - 5, player 2
gets 6 - 10, etc.

Any help would be greatly appreciated.

There's a really efficient representation of a deck of cards for poker:

struct Hand
{
short suit[4];
};

Assuming a short is 16 bits. You can use one bit to represent each
card. Using various bitwise operations, this representation makes it
very efficient to determine different poker hands. But seeing how this
is a C++ class, you are probably supposed to represent your hands in a
more object-oriented way.

Calum

whilst it may be efficient, you do lose all ability to assign a suit and
value type information. which results in code duplication at best and
error bugs due to invalid values at worst.
 
A

Alias

Turns out I'm just an idiot, and created an array of size 5 (since five
cards would be dealt) and the increment value (increment = i; array)
that would have values of anywhere up to 25. When I finally realized
what I did, I created a new variable to be 0-4 and that worked.

Thanks for the help, though!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,999
Messages
2,570,246
Members
46,839
Latest member
MartinaBur

Latest Threads

Top