poker source code Archive

PSxP 2 free pokerstars HUD and Tracker released

Posted September 14, 2013 By martin

 

download PSxP2T with Tourney Tracker and seat HUDs

(you must be saving Pokerstars Hand History  and Tourney Summary files for this to work)

(playchip friendly, free of spam, free to everyone)

psxp2instr

folds to bet % preflop, flop, turn, river

the 4 green and orange bars
the top bar is preflop, next is flop, next is turn, and the bottom green and black bar is river.
these controls start “borderless” and have a border around them when the first bet is called by them or folded to by them.
the green represents “folds to a bet” when a bet is made by someone and that player folds to that bet
the orange represents “calls a bet” when a bet is made by someone and that player calls that bet.
green is (folds to bet / (calls bet + folds to bet))

preflop aggression

the black and orange vertical bar on the left
the red bar represents the percentage of preflop raises (PFR) in the hands he was involved in (vp$ip)
so if a player has a vp$ip of 20 and a PFR of 10, the orange bar will be half way (50% preflop aggression)
orange is (pfr / vp$ip)

preflop raise (PFR)

the silver number just right of the preflop aggression bar
this number is the percentage of total hands dealt that the player raised preflop
if the player opened his 2 hole cards with a bet or raise then the hand is counted, otherwise it is not
((preflop bets + preflop raises) / total hands dealt) * 100

voluntarily put money in pot (vp$ip)

the yellow number just right of the preflop aggression bar
this number is the percentage of total hands dealt that the player made the descision to put chips in the pot
includes calling the limp or raise while in the small blind
does not include checking while in the big blind
((preflop calls + preflop bets) / total hands dealt) * 100

move all huds

the top left box
drag the form by this box and all forms will move
you can save all the positions to start up next time, as they are now, on the settings page

players name and move all HUDS

the white top center label
the player’s name that the HUD’s stats represent
the data is collected after the hand, so if a player changes seats, it will show up in the following hand
drag here to  move this HUD only

winning percent

the light blue number below the players name
the percentage of pots the player wins vs loses
includes uncalled wins
(wins + uncalled wins) / (wins + uncalled wins + losses) * 100

 hand count

the gray, top right number
the amount of collected hands that the data on that HUD represents
could be the players entire history or just the current session, whichever is loaded

 playing style

the white abbreviated styles below the hand count
breaks the players style down to 1 of 49 different styles of torque (loose to tight) and aggression (passive to aggressive)

Torque  
sLsuper loosevp$ip of 61 or more
vLvery loosevp$ip of 51 to 60
Lloosevp$ip of 41 to 50
avaveragevp$ip of 31 to 40
Ttightvp$ip of 21 to 30
vTvery tightvp$ip of 11 to 20
sTsuper tightvp$ip of 10 or less

 

aggression      
sPsuper passivePFR of 10 or less
vPvery passivePFR of 11 to 20
PpassivePFR of 21 to 30
avaveragePFR of 31 to 40
AaggressivePFR of 41 to 50
vAvery aggressivePFR of 51 to 60
sAsuper aggressivePFR 61 or greater

 sees Flop, Turn, River

the dark gray, light gray, and white bar on the right
the white bar represents ALL flops, it will fill if the player has seen 1 or 350 flops, it is the entire length always
the control is there to see how often his flops see turns and rivers
the light gray is the percentage of flops that the player is still in on the turn
the dark gray bar is the percentage of flops that the player is still in on the river
these bars are overlapped (the river covers turn, the turn covers flop) and they all start at the left of the control
so if a player saw 3 flops, 2 of them went to the turn, and 1 of them went to river, it would be look like it is split into thirds.,

 aggression factor

red and aqua bar on the right
total bets vs total calls

wins and losses

blue and yellow bar on the bottom right
dark blue = showdown wins
light blue = uncalled wins
yellow = showdown losses

 hudstreetpanel

choice of 1 of 3 different views per seat (H, N, S buttons on right)

3views

psxp2play

12 Comments so far. Join the Conversation
   

Free Pokerstars HUD and Tracker released today

Posted August 25, 2013 By martin

This application will truly give you an upper hand in your games at Pokerstars.

Free of Malware,  Free of Spam,  Free to everyone.

Download beta version 082513

September 3 2013 – PokerStars Approves PSxPoker as an acceptable Program and will add it to their site next month!

3 Comments so far. Join the Conversation
   

YOU MUST BE SAVING TOURNEY SUMMARY FILES IN POKERSTARS TO USE THIS

the tourney tracker area in PSxP2 is looking better every day
free of spam, free to everyone, it will be added this week

psxp2-tourney-tracker-game-type

psxp2-tourney-tracker-days

psxp2-tourney-tracker-graph1

psxp2-tourney-tracker-list

psxp2-tourney-tracker-graph2

psxp2-tourney-tracker-graph3

3 Comments so far. Join the Conversation
   

PSxP chat server will be released next week

Posted July 19, 2013 By martin

 

server

The chat server allows communication between multiple PSxP apps. This server is intended for morale,  support, and to discuss both good and bad decisions AFTER they are made. THIS IS  NOT FOR COLLUSION. The person who runs the server  will distribute their address to the persons of his/her choice and only those persons can connect to the conference. The chat server has an installed bot to manage the conference environment on the rich text chat panels on PSxP. Many text-based commends include KICK, SEEN, MSG, READ, WEATHER, PRIVATEMSG,  etc.

VB.NET ip chat and socket Source code help on request.

1 Comment. Join the Conversation
   

VB.NET vs C#

Posted July 13, 2013 By martin

Here in the real world where work actually gets done for actual monetary compensation, developers choose Visual Basic for one reason and one reason only: It’s the programming equivalent to the Leatherman Pocket Multitool. Visual Basic (for Applications) is employed in the MS Office Object Model (from Office 2000 up to and including the new 2012. Visual Basic (for Applications) is employed in the ArcGIS software suite API. VBA is embedded in dozens of other high-end and industry-specific software products for built-in extensibility as well. Visual Basic is employed in Windows Scripting Host (WSH/wscript) and the Command-Based Scripting Host (cscript), and VBScript is processed/executed in HTML markup by all webbrowsers worth having. In Legacy Visual Basic (6 and earlier) VB also exposed OOP, and in DotNET VB exposes OOP plus DotNET. The syntaxes, array functions, and other basic language behaviors are absolutely identical across these multiple and various platforms meaning that if you VB then you do all of the above. If you’re a Visual Basic developer, all of the above is right at your fingertips as long as you’re willing/able to learn the variant engine capabilities.

C# doesn’t offer half of this. In fact, C# only offers DotNET. C# is however, as others have mentioned, an internationally standardized syntax as opposed to a company proprietary language. C# also enjoys an avid following in non-DotNET circles, with multiple interpreters available for Linux/Unix; if you develop on DotNET with C# though, you’re as tied to Windows with DotNET as you would be with Visual Basic. There is a (allegedly functional) product called Mono to extend DotNET onto Linux/Mac platforms, but Mono sucks hard and loud; many proponents will screech that it’s VB that sucks and therefore the Mono project doesn’t support it as well as C#, but if you’ve ever actually tried to use Mono you’d have learnt really fast that System.Windows.Forms doesn’t work well in Mono in any language and System.Net.Security is almost entirely nonexistent (at least if you want/need to work with any SSL over 1.0 and/or use any crypto newer than 10 years old).

On the whole “$10,000.00 USD per year more for developing with C#” question, because the VB developer can literally do anything the C# developer can do and then a whole lot more, the VB developer gets to write his/her own ticket (very, very literally) when working with/for anybody who relies on Microsoft Products like Windows, MS Office, (and ESRI products, and other VBA-embedded products). The C# developer without any ability to do anything but prattle nonsense about how lowly and worthless VB skills are, on the other hand, literally can’t do anything but weigh in heavily on topics he/she knows little/nothing about and then say nasty things like, “I don’t know what you’re talking about and I don’t think you do either,” when they get called on it. So in the end, you should never, never, never select a programming language for any development based on which language is better than another; you should find a competent developer who can tell you his/her own reasons for preferring one language over the other and then let them do it their own way because that way you’ll get the best possible final product out of them.

 

entire thread on msdn forums

Be the first to comment
   

 

GUI for 5 Card Poker Hand

Brad Steinburg

VB.NET Source Code to evaluate a poker hand

C# Source Code to evaluate a poker hand

1 Comment. Join the Conversation
   

this took me awhile to figure out and I’ve had to change it on occasion after some pokerstars updates, besides the PS updates, it’s never failed.

I included the GetText declarations because It’s simple to first grab any text you may be typing in the pokerstars chat enter area at the moment the sub fires, save it as a string somewhere, and then replace it after the sub has sent the programmed chat. This will keep any text you’re typing to the table from being wiped out by the Sub.

use the sub like this:  SendChatToPokerstarsTable(“nice hand”)

Martin Carter – psxpoker.com
PrivateConst WM_SETTEXT = &HC 
PrivateConst WM_GETTEXT = &HD 
PublicConst WM_CHAR = &H102

PublicDeclareFunction GetWindowTextLength Lib“user32.dll”Alias“GetWindowTextLengthA” (ByVal hWnd AsLong) AsLong

PublicDeclareFunction GetWindowText Lib“user32.dll”Alias“GetWindowTextA” (ByVal hWnd AsLong, ByVal prmstrString AsString, ByVal nMaxCount AsLong) AsLong

PublicDeclareFunction FindWindow Lib“user32”Alias“FindWindowA” (ByVal lpClassName AsString, ByVal lpWindowName AsString) AsInteger

PublicDeclareFunction FindWindowEx Lib“user32”Alias“FindWindowExA” (ByVal hWnd1 AsInteger, ByVal hWnd2 AsInteger, ByVal lpsz1 AsString, ByVal lpsz2 AsString) AsInteger

PublicDeclareFunction SendMessageSTRING Lib“user32”Alias“SendMessageA” (ByVal hwnd AsInteger, ByVal wMsg AsInteger, ByVal wParam AsInteger, ByVal lParam AsString) AsInteger

DeclareFunction sendmessagebynum& Lib“user32”Alias“SendMessageA” (ByVal hWnd AsInteger, ByVal wMsg AsInteger, ByVal wParam AsInteger, ByVal lParam AsInteger)

PublicSub SendChatToPokerstarsTable(ByVal Chat)

Dim pokerstarstableframeclass AsLong = FindWindow(“pokerstarstableframeclass”, vbNullString)

Dim pokerstarschateditorclass AsLong = FindWindowEx(pokerstarstableframeclass, 0&, “pokerstarschateditorclass”, vbNullString)

If pokerstarschateditorclass = 0 Then

Exit Sub

Else

Call SendMessageSTRING(pokerstarschateditorclass, WM_SETTEXT, 0&, Chat)

Call sendmessagebynum(pokerstarschateditorclass, WM_CHAR, 13, 0)

EndIf

EndSub

 

You can also loop thru a textbox and instantly send multilines of text to the table.

Dim ChatLines() AsString = Split(TextBox1.Text, vbNewLine)

ForEach line In ChatLines

If line = “” Then line = “.”

 SendChatToPokerstarsTable(line)

Next

PLEASE DONT SPAM THE TABLES WITH THESE CODES! THIS IS FOR “NICE HAND” or “PAYOUTS AS FOLLOWS…” ETC!

6 Comments so far. Join the Conversation
   



bluebar

   Displaying large amounts of data in small areas with the visual benefit of status bars or “bar graphs” is great. Doing this within a poker app requires the graphs to have two, three, four, or even five data values to display for each player’s action. I searched for a control that would handle the problem but had no results. here is my solution.

In each example above, I made three labels…

  • set each back color to the desired color
  • set the text alignment to left-center
  • set the heights to the desired height of the entire control
  • set the widths to the desired width of the entire control
  • set the locations the same

You can make a fourth label, 2 pixels larger, that is bordered for the background and make these three borderless for a nice affect.
You can use picture boxes and stretch images to create an even better effect. Whatever you have time for. ( I have made some very nice controls with this method)

 

 

Private Sub DisplayIt(lbl1 As Label, lbl2 As Label, lbl3 As Label, val1 As Integer, val2 As Integer, val3 As Integer)

Martin Carter – psxpoker.com

 ‘the percentage of graph used by each label, times 200 pixels (the width of the control)

lbl1.Width = val1 / (val1 + val2 + val3) * 200

lbl2.Width = val2 / (val1 + val2 + val3) * 200

lbl3.Width = val3 / (val1 + val2 + val3) * 200

 ‘the position of the 2nd and 3rd labels

lbl2.Left = (lbl1.Left + lbl1.Width)

lbl3.Left = (lbl2.Left + lbl2.Width)

 
‘print the values on the labels

lbl1.Text = Math.Round(val1 / (val1 + val2 + val3) * 100) & “%”

lbl2.Text = Math.Round(val2 / (val1 + val2 + val3) * 100) & “%”

lbl3.Text =Math.Round(val3 / (val1 + val2 + val3) * 100) & “%”

End Sub

 

‘use the sub like this…

 

PrivateSub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click

Call DisplayIt(Label1, Label2, Label3, 11, 17, 5)

‘remember to handle the “isnumeric” exeption when passing the values

‘if 1 value is 0 then the other 2 labels will fill the control with the correct %

 EndSub

 

I use these controls to display “wins-uncalled wins-losses”, “bets preflop-flop-turn-river”, “in hand UTG-UTG+1-mid-mid+1-hijack-cutoff-button”. etc.

Be the first to comment
   

pokerstars HUD and Tracker

Posted July 7, 2013 By martin

toppic4

This is a free Pokerstars HUD project currently under development by us.

psxp2play

The App is always changing and growing to allow us to understang more and more about our game. It allows us to compare our play against other winning and losing players, and allows us to find and fix leaks in our game. As always it is free of malware, free of spam, and free to everyone. If you are a vb.net programmer and have a question about it, ask anything, anytime, it will get answered.

2 Comments so far. Join the Conversation
   

 This will search the Pokerstars hand history folders on your comp and trigger an event when the size of one of those hand history files changes.

I set the timer to 3 seconds and get NO processor spike at all and it catches every append to pokerstars HH files in as many tables you are on. If you plan on parsing hands just split the string in the streamreader with (vbnewline & vbnewline & vbnewline) .  Add it to an array. You will have an array of every hand played in that HH file to parse any info you need after each hand completes. You could also use lastindexof for the latest completed hand.

 

 


Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick 'Martin Carter – psxpoker.com Dim dir As String dir = System.Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) 'this is the pokerstars default directory Dim MyHHpath As String = dir & "\PokerStars\HandHistory\" 'create the array to put all the directories in to search for HH files.
Dim DirList As New ArrayList 'get the subdirectories If (System.IO.Directory.Exists(dir & "\PokerStars\HandHistory")) Then GetDirectories(MyHHpath, DirList) 'this is a folder i also save HH files in DirList.Add(System.Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments).ToString & "\HH") lstDirFile.Items.Clear() For Each x In DirList Dim files() As System.IO.FileInfo Dim dirinfo As New System.IO.DirectoryInfo(x.ToString) files = dirinfo.GetFiles("HH*Hold'em*.txt", IO.SearchOption.AllDirectories) For Each file In files 'skip the holdem omaha mixed games If file.ToString.Contains("Omaha") = True Then GoTo skipOmahaFile 'path and filename Dim FileN As String = dirinfo.ToString & "\" & file.ToString Dim filex As New FileInfo(FileN) sizeInBytes2 = filex.Length 'i use this to only add files modified today (ext.letfof is a function... ext.leftof("blah","ah") returns "bl" Dim Lastwrite As Date = eXt.LeftOf(filex.LastWriteTime, " ") 'add the size in bytes and filename to list a If Lastwrite = eXt.LeftOf(Now, " ") Then lstDirFile.Items.Add(sizeInBytes2.ToString & ", " & FileN) End If SkipOmahaFile: Next Next If lstDirFile.Items.Count = 0 Then Exit Sub Else ' populate list b from list a if its empty If lstDirFile2.Items.Count = 0 Then For i = 0 To lstDirFile.Items.Count - 1 lstDirFile2.Items.Add(lstDirFile.Items.Item(i)) Next Else 'start compare and refresh list here 'loop thru list a For i = 0 To lstDirFile.Items.Count - 1 'loop thru list b For x = 0 To lstDirFile2.Items.Count - 1 'If the 2 filenames are the same If eXt.RightOf(lstDirFile.Items.Item(i), ", ") = eXt.RightOf(lstDirFile2.Items.Item(x), ", ") Then 'if the sizes dont match then a hand has just completed If eXt.LeftOf(lstDirFile.Items.Item(i), ", ") <> eXt.LeftOf(lstDirFile2.Items.Item(x), ", ") Then 'here is the file that changed and it is read into memory Dim sr As New IO.StreamReader(eXt.RightOf(lstDirFile.Items(i), ", ").ToString) Dim Sr2 As String = sr.ReadToEnd 'your event would go here
End If End If Next Next 'now move the items from list a to list b for the next timer trigger to compare again lstDirFile2.Items.Clear() For i = 0 To lstDirFile.Items.Count - 1 lstDirFile2.Items.Add(lstDirFile.Items.Item(i)) Next End If End If End Sub

 

I collect 77 different data values from 9 players per hand and store that data on a list of 7000+ players. I parse about 2300 hands per minute on a laptop with this code. Don’t forget to handle exceptions.

1 Comment. Join the Conversation
   

Evaluate a Poker Hand C#

Posted July 1, 2013 By martin
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace FiveCardArray_CSharp
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            string[] CardValues = { "2", "3", "4", "5", "6", "7", "8", "9", "10", "Jack", "Queen", "King", "Ace" };
            string[] CardSuits = { "Hearts", "Spades", "Clubs", "Diamonds" };
            foreach (string value in CardValues)
            {
                ddlValue1.Items.Add(value);
                ddlValue2.Items.Add(value);
                ddlValue3.Items.Add(value);
                ddlValue4.Items.Add(value);
                ddlValue5.Items.Add(value);
            }
            foreach (string value in CardSuits)
            {
                ddlSuit1.Items.Add(value);
                ddlSuit2.Items.Add(value);
                ddlSuit3.Items.Add(value);
                ddlSuit4.Items.Add(value);
                ddlSuit5.Items.Add(value);
            }
        }
        private static int GetSuit(string DropDownSuit)
        {
            int retVal = 4;
            switch (DropDownSuit)
            {
                case "Clubs":
                    retVal = 0;
                    break;
                case "Diamonds":
                    retVal = 1;
                    break;
                case "Hearts":
                    retVal = 2;
                    break;
                case "Spades":
                    retVal = 3;
                    break;
            }
            return retVal;
        }
        private static int GetFace(string DropDownFace)
        {
            int retVal = 13;
            switch (DropDownFace)
            {
                case "Ace":
                    retVal = 0;
                    break;
                case "2":
                    retVal = 1;
                    break;
                case "3":
                    retVal = 2;
                    break;
                case "4":
                    retVal = 3;
                    break;
                case "5":
                    retVal = 4;
                    break;
                case "6":
                    retVal = 5;
                    break;
                case "7":
                    retVal = 6;
                    break;
                case "8":
                    retVal = 7;
                    break;
                case "9":
                    retVal = 8;
                    break;
                case "10":
                    retVal = 9;
                    break;
                case "Jack":
                    retVal = 10;
                    break;
                case "Queen":
                    retVal = 11;
                    break;
                case "King":
                    retVal = 12;
                    break;
            }
            return retVal;
        }
        private void btnGetHand_Click(object sender, EventArgs e)
        {
            if (ddlSuit1.Text == "" | ddlSuit2.Text == "" | ddlSuit3.Text == "" | ddlSuit4.Text == "" | ddlSuit5.Text == "" |
              ddlValue1.Text == "" | ddlValue2.Text == "" | ddlValue3.Text == "" | ddlValue4.Text == "" | ddlValue5.Text == "")
            {
                MessageBox.Show("All boxes need to have a value.");
            }
            else
            {
                lblHandDisplay.Text = CreateHand();
            }
        }
        private string CreateHand()
        {
            string retHand = "";
            int[,] hand = new int[3, 12];
            //1st Card
            hand[GetSuit(ddlSuit1.Text), GetFace(ddlValue1.Text)] = 1;
            //2nd Card
            hand[GetSuit(ddlSuit2.Text), GetFace(ddlValue2.Text)] = 1;
            //3rd Card
            hand[GetSuit(ddlSuit3.Text), GetFace(ddlValue3.Text)] = 1;
            //4th Card
            hand[GetSuit(ddlSuit4.Text), GetFace(ddlValue4.Text)] = 1;
            //5th Card
            hand[GetSuit(ddlSuit5.Text), GetFace(ddlValue5.Text)] = 1;
            if (IsFlush(hand) && IsStraight(hand))
            {
                retHand = "Straight Flush";
            }
            else if (IsFourOfAKind(hand))
            {
                retHand = "4 of a Kind";
            }
            else if (IsThreeOfAKind(hand) && IsPair(hand))
            {
                retHand = "Full House";
            }
            else if (IsFlush(hand))
            {
                retHand = "Flush";
            }
            else if (IsStraight(hand))
            {
                retHand = "Straight";
            }
            else if (IsThreeOfAKind(hand))
            {
                retHand = "3 of a Kind";
            }
            else if (IsTwoPair(hand))
            {
                retHand = "2 Pairs";
            }
            else if (IsPair(hand))
            {
                retHand = "a Pair";
            }
            else
            {
                retHand = "Nothing";
            }
            return retHand;
        }
        private bool IsFlush(int[,] hand)
        {
            bool retVal = false;
            int fCount = 0, x = 0, y = 0;
            do
            {
                if (hand[x, y] == 1)
                {
                    fCount++;
                }
                y++;
                if (fCount == 5)
                {
                    retVal = true;
                    break;
                }
                else if (fCount != 5 && y == 13 && x < 4)
                {
                    y = 0;
                    x++;
                    fCount = 0;
                }
                else if (fCount != 5 && y == 13 && x == 4)
                {
                    break;
                }
            }
            while (x < 4 && y < 13);
            return retVal;
        }
        private bool IsFourOfAKind(int[,] hand)
        {
            bool retVal = false;
            int fKCount = 0, x = 0, y = 0;
            do
            {
                do
                {
                    if (hand[x, y] == 1)
                    {
                        fKCount++;
                    }
                    x++;
                }
                while (fKCount < 5 && x < 4);
                if (fKCount == 4)
                {
                    retVal = true;
                    break;
                }
                else if (fKCount > 4)
                {
                    break;
                }
                else
                {
                    y++;
                    x = 0;
                    fKCount = 0;
                }
            }
            while (x < 4 && y < 13);
            return retVal;
        }
        private bool IsStraight(int[,] hand)
        {
            bool retVal = false;
            int sCount = 0, total = 0, x = 0, y = 0;
            do
            {
                total = 0;
                x = 0;
                do
                {
                    total = total + hand[x, y];
                    x++;
                }
                while (x < 4);
                if (total > 1)
                {
                    break;
                }
                else if (total == 1)
                {
                    sCount++;
                    if (sCount == 5)
                    {
                        retVal = true;
                        break;
                    }
                }
                else if (total == 0)
                {
                    sCount = 0;
                }
                y++;
            }
            while (y < 13);
            if (sCount == 5)
            {
                return retVal;
            }
            else
            {
                int Aces, Kings, Queens, Jacks, Tens;
                Aces = hand[0, 0] + hand[1, 0] + hand[2, 0] + hand[3, 0];
                Kings = hand[0, 12] + hand[1, 12] + hand[2, 12] + hand[3, 12];
                Queens = hand[0, 11] + hand[1, 11] + hand[2, 11] + hand[3, 11];
                Jacks = hand[0, 10] + hand[1, 10] + hand[2, 10] + hand[3, 10];
                Tens = hand[0, 9] + hand[1, 9] + hand[2, 9] + hand[3, 9];
                if (Aces + Kings + Queens + Jacks + Tens == 5)
                {
                    retVal = true;
                }
                return retVal;
            }
        }
        private bool IsThreeOfAKind(int[,] hand)
        {
            bool retVal = false;
            int x = 0, y = 0, tKCount = 0;
            do
            {
                do
                {
                    if (hand[x, y] == 1)
                    {
                        tKCount++;
                    }
                    x++;
                }
                while (tKCount < 4 && x < 4);
                if (tKCount == 3)
                {
                    retVal = true;
                    break;
                }
                else if (tKCount > 3)
                {
                    break;
                }
                else
                {
                    y++;
                    x = 0;
                    tKCount = 0;
                }
            }
            while (x < 4 && y < 13);
            return retVal;
        }
        private bool IsPair(int[,] hand)
        {
            bool retVal = false;
            int x = 0;
            int y = 0;
            int pCount = 0;
            do
            {
                do
                {
                    if (hand[x, y] == 1)
                    {
                        pCount = pCount + 1;
                    }
                    x = x + 1;
                }
                while (pCount < 3 && x < 4);
                if (pCount == 2)
                {
                    retVal = true;
                    break;
                }
                else if (pCount > 2 && y > 12)
                {
                    break;
                }
                else if (pCount <= 3)
                {
                    y++;
                    x = 0;
                    pCount = 0;
                }
            }
            while (x < 4 && y < 13);
            return retVal;
        }
        private bool IsTwoPair(int[,] hand)
        {
            bool retVal = false;
            int x = 0, y = 0, pCount = 0, p2Count = 0;
            do
            {
                do
                {
                    if (hand[x, y] == 1)
                    {
                        pCount++;
                    }
                    x++;
                }
                while (pCount < 3 && x < 4);
                if (pCount == 2)
                {
                    break;
                }
                else if (pCount > 2)
                {
                    break;
                }
                else
                {
                    y++;
                    x = 0;
                    pCount = 0;
                }
            }
            while (x < 4 && y < 13);
            y++;
            x = 0;
            if (pCount == 2)
            {
                do
                {
                    do
                    {
                        if (hand[x, y] == 1)
                        {
                            p2Count++;
                        }
                        x++;
                    }
                    while (p2Count < 3 && x < 4);
                    if (pCount == 2 && p2Count == 2)
                    {
                        retVal = true;
                        break;
                    }
                    else if (p2Count > 2)
                    {
                        break;
                    }
                    else
                    {
                        y++;
                        x = 0;
                        p2Count = 0;
                    }
                }
                while (x < 4 && y < 13);
                return retVal;
            }
            else
            {
                return retVal;
            }
        }
    }
}
1 Comment. Join the Conversation
   

Evaluate a Poker Hand VB.NET

Posted July 1, 2013 By martin

 

Public Class Form1
    Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        Dim CardValues As String() = {"2", "3", "4", "5", "6", "7", "8", "9", "10", "Jack", "Queen", "King", "Ace"}
        Dim CardSuits As String() = {"Hearts", "Spades", "Clubs", "Diamonds"}
        For Each value As String In CardValues
            ddlValue1.Items.Add(value)
            ddlValue2.Items.Add(value)
            ddlValue3.Items.Add(value)
            ddlValue4.Items.Add(value)
            ddlValue5.Items.Add(value)
        Next
        For Each value As String In CardSuits
            ddlSuit1.Items.Add(value)
            ddlSuit2.Items.Add(value)
            ddlSuit3.Items.Add(value)
            ddlSuit4.Items.Add(value)
            ddlSuit5.Items.Add(value)
        Next
    End Sub
    Private Function GetSuit(ByVal DropDownSuit As String) As Integer
        Dim retVal As Integer
        Select Case DropDownSuit
            Case "Clubs"
                retVal = 0
            Case "Diamonds"
                retVal = 1
            Case "Hearts"
                retVal = 2
            Case "Spades"
                retVal = 3
        End Select
        Return retVal
    End Function
    Private Function GetFace(ByVal DropDownFace As String) As Integer
        Dim retVal As Integer
        Select Case DropDownFace
            Case "Ace"
                retVal = 0
            Case "2"
                retVal = 1
            Case "3"
                retVal = 2
            Case "4"
                retVal = 3
            Case "5"
                retVal = 4
            Case "6"
                retVal = 5
            Case "7"
                retVal = 6
            Case "8"
                retVal = 7
            Case "9"
                retVal = 8
            Case "10"
                retVal = 9
            Case "Jack"
                retVal = 10
            Case "Queen"
                retVal = 11
            Case "King"
                retVal = 12
        End Select
        Return retVal
    End Function
    Private Sub btnGetHand_Click(sender As System.Object, e As System.EventArgs) Handles btnGetHand.Click
        If ddlSuit1.Text = "" Or ddlSuit2.Text = "" Or ddlSuit3.Text = "" Or ddlSuit4.Text = "" Or ddlSuit5.Text = "" Or _
            ddlValue1.Text = "" Or ddlValue2.Text = "" Or ddlValue3.Text = "" Or ddlValue4.Text = "" Or ddlValue5.Text = "" Then
            MsgBox("All boxes need to have a value.")
        Else
            lblHandDisplay.Text = CreateHand()
        End If
    End Sub
    Private Function CreateHand() As String
        Dim retHand As String = ""
        Dim hand(3, 12) As Integer
        '1st Card
        hand(GetSuit(ddlSuit1.Text), GetFace(ddlValue1.Text)) = 1
        '2nd Card
        hand(GetSuit(ddlSuit2.Text), GetFace(ddlValue2.Text)) = 1
        '3rd Card
        hand(GetSuit(ddlSuit3.Text), GetFace(ddlValue3.Text)) = 1
        '4th Card
        hand(GetSuit(ddlSuit4.Text), GetFace(ddlValue4.Text)) = 1
        '5th Card
        hand(GetSuit(ddlSuit5.Text), GetFace(ddlValue5.Text)) = 1
        If IsStraight(hand) = True AndAlso IsFlush(hand) = True Then
            retHand = "Straight Flush"
        ElseIf IsFourOfAKind(hand) = True Then
            retHand = "4 of a Kind"
        ElseIf IsThreeOfAKind(hand) = True AndAlso IsPair(hand) = True Then
            retHand = "Full House"
        ElseIf IsFlush(hand) = True Then
            retHand = "Flush"
        ElseIf IsStraight(hand) = True Then
            retHand = "Straight"
        ElseIf IsThreeOfAKind(hand) = True Then
            retHand = "3 of a Kind"
        ElseIf IsTwoPair(hand) = True Then
            retHand = "2 Pairs"
        ElseIf IsPair(hand) = True Then
            retHand = "a Pair"
        Else
            retHand = "Nothing"
        End If
        Return retHand
    End Function
    Private Function IsFlush(ByVal hand) As Boolean
        Dim retVal As Boolean = False
        Dim x As Integer = 0
        Dim y As Integer = 0
        Dim fCount As Integer = 0
        Do While x < 4 AndAlso y < 13
            If hand(x, y) = 1 Then
                fCount = fCount + 1
            End If
            y = y + 1
            If fCount = 5 Then
                retVal = True
                Exit Do
            ElseIf fCount <> 5 AndAlso y = 13 AndAlso x < 4 Then
                y = 0
                x = x + 1
                fCount = 0
            ElseIf fCount <> 5 AndAlso y = 13 AndAlso x = 4 Then
                Exit Do
            End If
        Loop
        Return retVal
    End Function
    Private Function IsFourOfAKind(ByVal hand) As Boolean
        Dim retVal As Boolean = False
        Dim x As Integer = 0
        Dim y As Integer = 0
        Dim fKCount As Integer = 0
        Do While x < 5 AndAlso y < 13
            Do While fKCount < 5 AndAlso x < 4
                If hand(x, y) = 1 Then
                    fKCount = fKCount + 1
                End If
                x = x + 1
            Loop
            If fKCount = 4 Then
                retVal = True
                Exit Do
            ElseIf fKCount > 4 Then
                Exit Do
            Else
                y = y + 1
                x = 0
                fKCount = 0
            End If
        Loop
        Return retVal
    End Function
    Private Function IsStraight(ByVal hand) As Boolean
        Dim retVal As Boolean = False
        Dim sCount As Integer = 0
        Dim total As Integer = 0
        Dim x As Integer = 0
        Dim y As Integer = 0
        Do While y < 13
            total = 0
            x = 0
            Do While x < 4
                total = total + hand(x, y)
                x = x + 1
            Loop
            If total > 1 Then
                Exit Do
            ElseIf total = 1 Then
                sCount = sCount + 1
                If sCount = 5 Then
                    retVal = True
                    Exit Do
                End If
            ElseIf total = 0 Then
                sCount = 0
            End If
            y = y + 1
        Loop
        If sCount = 5 Then
            Return retVal
        Else
            Dim Aces As Integer
            Dim Kings As Integer
            Dim Queens As Integer
            Dim Jacks As Integer
            Dim Tens As Integer
            Aces = hand(0, 0) + hand(1, 0) + hand(2, 0) + hand(3, 0)
            Kings = hand(0, 12) + hand(1, 12) + hand(2, 12) + hand(3, 12)
            Queens = hand(0, 11) + hand(1, 11) + hand(2, 11) + hand(3, 11)
            Jacks = hand(0, 10) + hand(1, 10) + hand(2, 10) + hand(3, 10)
            Tens = hand(0, 9) + hand(1, 9) + hand(2, 9) + hand(3, 9)
            If Aces + Kings + Queens + Jacks + Tens = 5 Then
                retVal = True
            End If
            Return retVal
        End If
    End Function
    Private Function IsThreeOfAKind(ByVal hand) As Boolean
        Dim retVal As Boolean = False
        Dim x As Integer = 0
        Dim y As Integer = 0
        Dim tKCount As Integer = 0
        Do While x < 4 AndAlso y < 13
            Do While tKCount < 4 AndAlso x < 4
                If hand(x, y) = 1 Then
                    tKCount = tKCount + 1
                End If
                x = x + 1
            Loop
            If tKCount = 3 Then
                retVal = True
                Exit Do
            ElseIf tKCount > 3 Then
                Exit Do
            Else
                y = y + 1
                x = 0
                tKCount = 0
            End If
        Loop
        Return retVal
    End Function
    Private Function IsPair(ByVal hand) As Boolean
        Dim retVal As Boolean = False
        Dim x As Integer = 0
        Dim y As Integer = 0
        Dim pCount As Integer = 0
        Do While x < 4 AndAlso y < 13
            Do While pCount < 3 AndAlso x < 4
                If hand(x, y) = 1 Then
                    pCount = pCount + 1
                End If
                x = x + 1
            Loop
            If pCount = 2 Then
                retVal = True
                Exit Do
            ElseIf pCount > 2 AndAlso y > 12 Then
                Exit Do
            ElseIf pCount <= 3 Then
                y = y + 1
                x = 0
                pCount = 0
            End If
        Loop
        Return retVal
    End Function
    Private Function IsTwoPair(ByVal hand) As Boolean
        Dim retVal As Boolean = False
        Dim x As Integer = 0
        Dim y As Integer = 0
        Dim pCount As Integer = 0
        Dim p2Count As Integer = 0
        Do While x < 4 AndAlso y < 13
            Do While pCount < 3 AndAlso x < 4
                If hand(x, y) = 1 Then
                    pCount = pCount + 1
                End If
                x = x + 1
            Loop
            If pCount = 2 Then
                Exit Do
            ElseIf pCount > 2 Then
                Exit Do
            Else
                y = y + 1
                x = 0
                pCount = 0
            End If
        Loop
        y = y + 1
        x = 0
        If pCount = 2 Then
            Do While x < 4 AndAlso y < 13
                Do While p2Count < 3 AndAlso x < 4
                    If hand(x, y) = 1 Then
                        p2Count = p2Count + 1
                    End If
                    x = x + 1
                Loop
                If pCount = 2 AndAlso p2Count = 2 Then
                    retVal = True
                    Exit Do
                ElseIf p2Count > 2 Then
                    Exit Do
                Else
                    y = y + 1
                    x = 0
                    p2Count = 0
                End If
            Loop
            Return retVal
        Else
            Return retVal
        End If
    End Function
End Class
1 Comment. Join the Conversation
   

Hit Counter provided by shuttle service from lax