Computer Science Canada

Poker Hand Values

Author:  berf [ Thu Jun 22, 2006 1:29 pm ]
Post subject:  Poker Hand Values

This is what i have so far, this procedure is what i use to determine the value of the hand
code:
procedure Sort_Hand
    var card_value : int
    var card_suit : int
    % var hold_num : array 1 .. NUM_CARDS of int

    for s : 1 .. NUM_OF_PLAYERS
        Hand_Clear

        for h : 1 .. NUM_CARDS

            card_value := ((playershand (s, h) - 7001) mod 13)
            hand (h) := card_value + 2

            card_suit := (playershand (s, h) - 7001) div 13

            hold_num (hand (h)) := hold_num (hand (h)) + 1

        end for

    end for
end Sort_Hand
procedure Check_Hand_Value
    var pair, three_of_a_kind : int := 0
    var value : string := ""
    var high_card : int := 0
    for find : 2 .. 14

        if hold_num (find) = 2 then
            pair := pair + 1
            value := "a Pair"

        elsif hold_num (find) = 3 then
            three_of_a_kind := 1
            value := "Three of a Kind"

        elsif hold_num (find) = 4 then

            value := "Four of a Kind"

        elsif pair = 1 and three_of_a_kind = 1 then
            value := "a Fullhouse"

        elsif pair = 2 then
            value := "Two Pair"

        else
            for hc : 1 .. NUM_CARDS
                if hand (hc) > high_card then
                    hand (hc) := high_card
                    value := intstr (high_card)
                end if
            end for
        end if

    end for

    put "The hand is ", value
end Check_Hand_Value


The pair,three of a kind, etc. work but Im not sure how to get the high card to work. I know how it needs to be done (set variable to 0, if hand(hc) > high_card) hand(hc) := high_card) im just not sure how to put it into that loop. I hope you can understand my problem. Any help would be great

Author:  Clayton [ Thu Jun 22, 2006 2:46 pm ]
Post subject: 

in your hand value procedure just add a for loop to check for the high card after or before you check for combinations of cards in the hand Very Happy


: