Solved

Poker game in VB 2008

Posted on 2010-09-10
2
1,041 Views
Last Modified: 2012-05-10
Hi everyone,

I am planning to make a Texas Holdem Poker game in VB. I am looking forward to some basic application where five card are selected at random and displayed on the screen and then users will have their two card in their hand (physically). Then the application will ask the users to enter their cards in hand and then the system calculated if they have won or not.

I have some idea about the basics like I will need 2 classes one for cards and one for the deck and two methods, one for shuffle and one for deal.
I also have all the card images etc available.

But before starting I was wonder if I could look at some sample codes. I am not sure where to start from.

Any help to guide me in the right direction will be highly appreciated.

Thanks
0
Comment
Question by:justind39
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 40

Expert Comment

by:Kyle Abrahams
ID: 33649699
If you're going to do this right, you're going to want to have multiple classes.

Table:  holds people, public cards, etc.

People:  account info, username, private cards, etc

Deck - 52 cards.  shuffle will be a randomize function, put them on a stack or in a list randomly so that all 52 are contained.

Deal as per the rules, just taking off the front card and allocating it to the person.

If you are going to give them physical cards . . . what's to say I don't have aces all the time?  What's the finaly application?


           
0
 
LVL 20

Accepted Solution

by:
alainbryden earned 500 total points
ID: 33649850
I was helping a friend create a texas holdem game the other day so I'll help you out. The included code should be incredibly easy to translate from java pseudocode to VBA:

  • Define a deck of cards as a 4*13 2D boolean array, and a card object as a two integer pair.

  • As you randomly generate a card (S=rand(1,4) for suit and  V=rand(2,14) for value), you mark the appropriate array index  Deck[S-1][V-2] = true, and on future random generations, ensure that the  card has not already been drawn)

  • Have a function that sorts your hand as you did, and then checks for  hands from highest to lowest value based on flush, straight, pair  determinations. As soon as a winning is found, you can break and return  the appropriate multiplier.
  • When you create a hand, you should sort it in ascending order. A hand can be easily defined using two 5 element arrays. One array of face values (where 2=2, 3=3, ..., Jack=11, Queen=12, King=13, Ace=14). The other array is the suits (which can just be a single character or a number from 0 to 3)
Based on the above infrastructure, the following segments of code can be used to computer a hand:
hasFlush:
bool flush = true;
for( int i = 0; i < 4, flush == true; i++)
   if( suitArray[i] != suitArray[i+1] ) flush = false;
//We assume a flush until a test tells us otherwise.

hasStraight (requires valArray to be in ascending order):
bool straight = true;
for( int i = 0; i < 3, straight == true; i++)
   if( (valArray[i]+1) != valArray[i+1] ) straight = false;
if( straight == true && (valArray[3]+1) != valArray[4] && (valArray[3]+9) != valArray[4]) straight = false;
//Because there's a special case for a wheel straight the final test is done after the loop.

Count pairs, 3 of a kinds, and 4 of a kinds (requires valArray to be in ascending order):
int pairCount = 0, matchCount = 0, maxMatch = 0, maxPair = 0;
for( int i = 0; i < 4; i++)
{
   if( valArray[i] == valArray[i+1] )
   {
      if( matchCount == 0 ) pairCount++;
      matchCount++;
      maxMatch = matchCount > maxMatch ? matchCount : maxMatch;
      maxPair = valArray[i] > maxPair ? valArray[i] : maxPair;
   }
   else
      matchCount = 0;
}


Final Result:
if( straight == true && flush == true && valArray[0] == 10) //return Royal Flush
if( straight == true && flush == true) //return Straight Flush
if( maxMatch == 4) //return Four of a Kind
if( pairCount == 2 && maxMatch == 3) //return Full House
if( flush == true ) //return Flush
if( straight == true ) //return Straight
if( pairCount == 1 && maxMatch == 3) //return 3 of a Kind
if( pairCount == 2 && maxMatch == 2) //return 2 Pair
if( pairCount == 1 && maxMatch == 2 && maxPair >= 10) //return High Pair


Hope that's a solid start. Good Luck.

--
Alain
0

Featured Post

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
FTP recursive download files 5 26
Count text color with conditional formating in Excel 4 67
vb6 Where condition on dbo 2 29
2 Global Vars, 1 List Box 4 29
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
With User Account Control (UAC) enabled in Windows 7, one needs to open an elevated Command Prompt in order to run scripts under administrative privileges. Although the elevated Command Prompt accomplishes the task, the question How to run as script…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

737 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question