473,322 Members | 1,431 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

7 Cards

MC
Hi guys

Been trawling for ages now!!

Anyone seen any code for working out the best 5 card hand from 7 cards as in
Limit/No-Limit Poker. I am doing a project for myself to teach me .NET and
struggling.

Thought i'd cheat a bit.

MC
Nov 21 '05 #1
2 982

MC wrote:
Hi guys

Been trawling for ages now!!

Anyone seen any code for working out the best 5 card hand from 7 cards as in
Limit/No-Limit Poker.
You mean "as in Texas Hold 'em"
I am doing a project for myself to teach me .NET and struggling.

Thought i'd cheat a bit.


OK, so no complete answers from me :)

First, how are you modelling cards? I suggest a class or structure with
Suit and Rank methods that return values from Enums you define.

Check for each type of hand in turn, from best to worst - stop checking
when you get a match (a hand containing a three of a kind also contains
a pair, but we only care about the *best* match).

A lot of the hand checking is made easier by sorting the cards by rank.

To check for a straight, check for differences of one in appropriate
places.

If you find a straight, check the suits for a straight flush.

Checking for four of a kind is easy if the cards are rank sorted.

It might be useful to count the incidences of ranks. eg AAKQJJ7, count
the ranks, get an array like this:

(1): 2
(2): 0
....
(7): 1
....
(11): 2
(12): 1
(13): 2

With such an array, checking for FH / 3s / 2x2s / 2s is easy. A similar
suit-counting array makes checking for a flush very easy.

And that's it, really :)

--
Larry Lard
Replies to group please

Nov 21 '05 #2
MC
Thanks Larry

I sat down the other day and worked a lot of stuff out.

Best to worse TICK. dont that

Pairs, 3s, 4s, FH and flushes easy.

Straights not so, but I did some working out and managed it. Took me a good
three hours may I say.

My problem I got now though is when two players in my imaginary 4 player
game have both got same Pair for instance. I then need to weed out those two
card from the array and find the highest card left. What if they match so
then looking for next best card.

Ill get there. Its a good learning curve for me. Making me use the grey
matter that seems to have been rejected for sometime.

I do have another problem. I am using VS 2005 Beta 2. When i build and
publish the software no-one else seems to be able to install it. The error
says something along the lines. DotNetFX/WindowInstaller-KB884016-v2-x86.exe
has changed since it was initially published. I have tried adding the Dotnet
Framework to my distribute file also.

Someone suggested Bootstrapping. DOH!! Sorry I am a hobbiest and dont
understand.

Any ideas
MC
"Larry Lard" <la*******@hotmail.com> wrote in message
news:11**********************@g44g2000cwa.googlegr oups.com...

MC wrote:
Hi guys

Been trawling for ages now!!

Anyone seen any code for working out the best 5 card hand from 7 cards as
in
Limit/No-Limit Poker.


You mean "as in Texas Hold 'em"
I am doing a project for myself to teach me .NET and struggling.

Thought i'd cheat a bit.


OK, so no complete answers from me :)

First, how are you modelling cards? I suggest a class or structure with
Suit and Rank methods that return values from Enums you define.

Check for each type of hand in turn, from best to worst - stop checking
when you get a match (a hand containing a three of a kind also contains
a pair, but we only care about the *best* match).

A lot of the hand checking is made easier by sorting the cards by rank.

To check for a straight, check for differences of one in appropriate
places.

If you find a straight, check the suits for a straight flush.

Checking for four of a kind is easy if the cards are rank sorted.

It might be useful to count the incidences of ranks. eg AAKQJJ7, count
the ranks, get an array like this:

(1): 2
(2): 0
...
(7): 1
...
(11): 2
(12): 1
(13): 2

With such an array, checking for FH / 3s / 2x2s / 2s is easy. A similar
suit-counting array makes checking for a flush very easy.

And that's it, really :)

--
Larry Lard
Replies to group please

Nov 21 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: kelvSYC | last post by:
I'm trying to program something along the lines of a "trading card" idea: I have a single copy of the "card" in the program, yet there may be multiple "instances" of the "card", with differing...
3
by: RR | last post by:
We have cards that are numbered consecutively. These cards are given out to different people in different sized batches. One group might get 5, the next group might get 20. What is a good...
10
by: Arun Nair | last post by:
Can any one help me with this im not getting it even after reading books because there is not much of discussion anywhere a> Implement a calss that represents a playing card. The class should...
11
by: prince99 | last post by:
i am worlking on the cards class so it can do several things. My code is as before but need to change the things to solve given problem Create a new class Deck that represents a pack of 52...
2
by: RobcPettit | last post by:
Hi, could somebody in the right direction to write a program to deal cards. What I want to do is: With an 8 deck of cards. I know the player has an ace, the dealer has a 2, is deal every possible...
11
by: cazconv2007 | last post by:
hi i have homework due tomorrow been trying to do java homework all week and nothings happening really starting to stress out i dont understand what the program is meant to do or how to use three...
3
by: JayP | last post by:
I'm trying to shuffle a deck of card in C ++, with out having the same card twice. And I'm supposed to give each player 5 cards. And if they want, they can replace 3 cards. Right now I can assign 5...
8
by: garyrowell | last post by:
I have been at this programme for hours trying to work out what is wrong. Any help would be very much appricated. Here is the breif I received. The program This week you are going to write three...
1
by: Vneha | last post by:
import java.util.*; public class Deck { public static int numSuits = 4; public static int numRanks = 13; public static int numCards = numSuits * numRanks; private Card...
7
by: MonkeyHater | last post by:
Okay, so I am have a bit of trouble with my program. The program itself will deal two hands of cards, shuffle the deck, and then deal another two hands. At the moment I have most of the code down I...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.