Notices

Overclockers Forums > Software > Programming Tips and Tricks
Programming Tips and Tricks
Forum Jump

A little logic problem

Post Reply New Thread Subscribe Search this Thread
 
 
Thread Tools
Old 03-21-02, 01:54 AM Thread Starter   #1
Cluster



Join Date: Dec 2001
Location: Canuckistan

 
A little logic problem


I'm making a game of poker in pascal and i'm stuck on a logic problem.

I need to find a way to check the cards to find out if the cards fit into one of 8 winning categories. But with 7 cards there's alot of winning combinations just starting at the first with a pair. The eight winning combinations are pair (10,J,Q,K,A only), 2 pair, flush, straight, 3ofakind, full house, 4 of a kind, royal flush.

My idea was to setup an array and a bunch of if statements to check the cards to see if there are any card combinations matching the winning combinations. But soon realized that there are 1000's. I need an easier way to do this. Any help would be greatly appreciated.

__________________
Multi VM/SMP Folding Guide | Ram Timing Guide | Folding working on Alzheimer's cure
GPU Countdown to new years - Fold for a cure!
Asus M3A79-T ~ Phenom 9850 ~ Cell Shock DDR-1066 ~ HIS HD4850
Phenom 9850 Rank : PiFast (1st) | wPrime32 (1st) | wPrime1024 (1st) | SPi1M (1st) | SPi32M (2nd)
Cluster is offline   QUOTE Thanks
Old 03-21-02, 09:05 AM   #2
JigPu
Inactive Pokémon Moderator

 
JigPu's Avatar 

Join Date: Jun 2001
Location: Vancouver, WA

10 Year Badge
 
Well... Let me have a try...

You could keep an array containing the number of each kind of card that each player has. Then, you could consult the array to check for a pair (possibly 3 of a kind... or a straight... I don't play poker, so I don't know).

You could even have two arrays, one to do what I just suggested with card values (2 - Ace), and the other keeping track of the number of cards with a cirtian symbol (heart, club, ect.).

Hope it helps with a few of them...
JigPu

__________________
.... ASRock Z68 Extreme3 Gen3
.... Intel Core i5 2500 ........................ 4 thread ...... 3300 MHz ......... -0.125 V
2x ASUS GTX 560 Ti ............................... 1 GiB ....... 830 MHz ...... 2004 MHz
.... G.SKILL Sniper Low Voltage ............. 8 GiB ..... 1600 MHz ............ 1.25 V
.... OCZ Vertex 3 ................................. 120 GB ............. nilfs2 ..... Arch Linux
.... Kingwin LZP-550 .............................. 550 W ........ 94% Eff. ....... 80+ Plat
.... Nocuta NH-D14 ................................ 20 dB ..... 0.35 C°/W ................ 7 V


"In order to combat power supply concerns, Nvidia has declared that G80 will be the first graphics card in the world to run entirely off of the souls of dead babies. This will make running the G80 much cheaper for the average end user."
"GeForce 8 Series." Wikipedia, The Free Encyclopedia. 7 Aug 2006, 20:59 UTC. Wikimedia Foundation, Inc. 8 Aug 2006.
JigPu is offline   QUOTE Thanks
Old 03-21-02, 05:21 PM   #3
vandersl
Member



Join Date: Apr 2001

 
Never thought about this before, but this approach might be worth a look...

Define 3 criteria arrays:

(1) The first represents the number of each card value in the hand. That is, a 13-element array, where the value in each location is the number of cards of that value in the hand (2 thru Ace). This array is useful for checking for pairs, 3-of-a-kind, or 4-of-a-kind.

(2) The second represents whether the hand contains one or more cards of each value. This is really the same as the first array. It it useful for checking for straights (i.e. 5 locations in a row each with a value of '1').

(3) The third represents the number of cards of each house in the hand. That is, a 4 element array representing the number of clubs, hearts, etc. This one is useful for checking for flushes.

Populate the arrays for the hand, then perform the scan (in order of highest possible hand on down):
- you have a flush if one of the arrays in (3) has 5 cards in it
- you have a straight if the array in (2) has 5 non-zero values in a row
- you have 4-of-a-kind if one of the locations in (1) is 4
- you have full house if one of the locations in (1) is 3 and another is 2
- etc

One good thing about this approach is you don't need to break the 7 cards into all possible 5-card hands.
vandersl is offline   QUOTE Thanks
Old 03-21-02, 05:50 PM   #4
Kendan
Senior Punk

 
Kendan's Avatar 

Join Date: Aug 2001
Location: Dark side of hell

 
What about a straight flush?

__________________
Hello:sn:
Kendan is offline   QUOTE Thanks
Old 03-22-02, 01:52 AM Thread Starter   #5
Cluster



Join Date: Dec 2001
Location: Canuckistan

 
I missed the straight flush. Thanks.

Right now i got 2 arrays, a 13 value containing the face values. And a 4 value array with the suit.

Could you possibly write a piece of code, preferably in a procedure. I would want to call the procedure at the end of the hand to check for winners. I'd just like to see what it looks like. I haven't really dived that deep into arrays yet, but i'm getting there.

Thanks for the help guys.

__________________
Multi VM/SMP Folding Guide | Ram Timing Guide | Folding working on Alzheimer's cure
GPU Countdown to new years - Fold for a cure!
Asus M3A79-T ~ Phenom 9850 ~ Cell Shock DDR-1066 ~ HIS HD4850
Phenom 9850 Rank : PiFast (1st) | wPrime32 (1st) | wPrime1024 (1st) | SPi1M (1st) | SPi32M (2nd)
Cluster is offline   QUOTE Thanks
Old 03-22-02, 07:32 PM   #6
Istari1
Member

 
Istari1's Avatar 

Join Date: Mar 2002
Location: Raleigh NC

 
Quote:
Originally posted by Chris
I missed the straight flush. Thanks.

Right now i got 2 arrays, a 13 value containing the face values. And a 4 value array with the suit.

Could you possibly write a piece of code, preferably in a procedure. I would want to call the procedure at the end of the hand to check for winners. I'd just like to see what it looks like. I haven't really dived that deep into arrays yet, but i'm getting there.

Thanks for the help guys.
Just to give ya some push in the right direction, first sort the hand by face value. That will make your checking procedures easier. When you do this notice the combinations you get and you might see how you should now check for winning hands. If not I'll look back here and give ya another clue. (I dont like just giving answers, you learn more if ya figure it out yourself).

Istari
Istari1 is offline   QUOTE Thanks
Old 03-24-02, 07:21 PM   #7
Gresyth
Computer Abuser

 
Gresyth's Avatar 

Join Date: May 2001
Location: Houston, TX

 
This might help. I've learned to set up my data structure first and then figure out how to process the data afterwards.


deck
array(1..52)


player1
array(1..5)


player2
array(1..5)



player3
array(1..5)


player4
array(1..5)


player5
array(1..5)


the deck array for example:

elements 1 ,13 = clubs in ascending order
elements 14,26 = diamonds in ascending order
elements 27,39 = hearts in ascending order
elements 40,52 = spades in ascending order

player1 example

element 1 = numeric value of card
ie. 3 of diamonds = 15

element 2 = numeric value of card
ie. jack of spades = 49

element 3 = numeric value of card
ie. jack of clubs = 10

element 4 = numeric value of card
ie. ace of hearts = 39

element 5 = numeric value of card
ie ace of clubs = 13


write a sorting algorithim to look for multiplies of 13, 10, 3, 7, etc. to check for pairs, three of a kind, four of a kind.

I posted a bubble sort program and code in this thread

this ought to get you started.

__________________
RIP My brother. You were my best friend and the little brother I never had.
Maddman - December 29, 1962 - October 28, 2005

ASRock 970 EXTREME4
AMD FX-4170 Zambezi 4.2GHz/// Mugen 2 HS/Fan
Crucial 16GB DDR3 1333
SAPPHIRE HD 5770
128GB Crucial M4 SATA III SSD /// 2TB Storage
24" Viewsonic VX2433wm 1920x1080 LCD
Win 7 Pro x64 /// CM Silent Pro 700W
Fractal Design Define R3 Black


Partnership for an Idiot Free America
Gresyth is offline   QUOTE Thanks

Post Reply New Thread Subscribe


Overclockers Forums > Software > Programming Tips and Tricks
Programming Tips and Tricks
Forum Jump

Thread Tools Search this Thread
Search this Thread:

Advanced Search


Mobile Skin
All times are GMT -5. The time now is 10:11 PM.
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2013, vBulletin Solutions, Inc.
You can add these icons by updating your profile information to include your Heatware ID, Benching Profile ID or your Folding/SETI profile ID. Edit your profile!
X

Welcome to Overclockers.com

Create your username to jump into the discussion!

New members like you have made this the best community on the Internet since 1998!


(4 digit year)

Why Join Us?

  • Share experience
  • Max out your hardware
  • Best forum members anywhere
  • Customized forum experience

Already a member?