Archive for July 1st, 2013

PSxP just moved here

Posted July 1, 2013 By martin

under-construction-sign

we just moved so please give me time to do some stuff.

wtehg wetrhgwhteg wethgwehy wethwteh wethwtehg ewthweth ewsrthwtehg te eryjheryh eryjh etyr jert yj treyj ery j etryj etry j eryjh ery je ryj etry jer yh gbrju rtny r 6yetn 6 hy juyh nj 57yt r6uj yth fj uynt j 45ytnh fd ju6 jyh rej u6 yh t  6jury hj u6 jmntyh h j6uy nt j6uj ytnh  y5tj r ytj t ujki7 6km yjnh  gko ,mgki jn  kgmj h  dhgfj hk m jnh bg dhfjgku  hugmgj fnhb gr try htujy ituy mki yjnhtbrg vtvry hturyit uyo mkiy jnthb rgv yhtu rjiytukm yjn htb rgh trnjy mku ytjn thbyg ry hbtu rnytmu yt knjthb r tmkyj nthb r ht njytmk jn thbr gv yhbnj ymk tn rthbr gv bhtj nytmk tjnthb rgv bht jny

weth

4 Comments so far. 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