[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Poker game in VB 2008

Posted on 2010-09-10
2
Medium Priority
?
1,064 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:Justin Alcorta
[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 41

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 21

Accepted Solution

by:
alainbryden earned 2000 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…
Suggested Courses

656 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