Jump to content

Any Poker Players Out There?


troy_mccormick

Recommended Posts

Ok...I don't have any code yet...but I really don't know where to start.  Basically, I'm looking for pseudo code...

 

For those of you that play poker (Texas Hold'em to be specific), if a player goes all in during a tournament and there are multiple callers (or even raisers), there are multiple pots created.  What I'm looking to do would be how to track this during a game of poker...

 

I've still got nothing.  Even my explanation in words isn't very good...  How else can I explain it??

 

Thanks,

 

-Troy

Link to comment
Share on other sites

That's the logic you will have to figure out. So when the user goes all in, that is when you would need to have more than one pot, so that is when you'd use an array. Then when the game is over you'd use the rules of poker to distribute it. This is really more of a logical issue than PHP code, so it's hard to tell you how to do it.

 

All I can tell you is I have written tons of games. Blackjack was the funnest, figuring out how to do push/draw, insurance, split, etc. It was just a long time of testing and going over the logic. Make sure you use lots of comments. Write out some psuedo code first.

 

//How much does the player want to bid

//if it's all in, do this all-in stuff.

//otherwise just bid what they bid.

 

//game is over, is there multiple pots? no, okay just give it all to winner

//there is, figure out who gets what. etc.

Link to comment
Share on other sites

I think I'm going to show some code and ask for direction here.  I really can't nail down what it is I need to do to get side pots going...

 

For now let's just take a look at the call function:

<?php
function post_user_action($action, $cur_turn, $db, $raise_amt = 0) {
    // db = database connection
    // action = FOLD | CHECK | CALL | RAISE
    // cur_turn = SEAT ID of player who is currently up
    // raise_amt = raise amount if this is a raise...defaults to 0

    switch ($action) {
        case "call":
            $_SESSION["dtp_stat_call"]++;
            $new_turn = update_turn($cur_turn, $db);
            $query1 = "SELECT cur_top_bet, seat_" . $cur_turn . "_cur_stake AS stake, seat_" . $cur_turn . " AS player_id, is_side_pots, side_pots FROM tournament_tables WHERE table_id = " . $_SESSION["dtp_table_id"];
            $res1 = $db->query($query1);
            $row1 = $res1->fetch_assoc();
            $is_side_pots = $row1["is_side_pots"]; // is set to Y if there are side pots?
            $side_pots = $row1["side_pots"]; // contains serialized array of all side pot action

            $call_amt = $row1["cur_top_bet"] - $row1["stake"];
            $player_id = $row1["player_id"];

            $querya = "SELECT tour_id FROM tournament_tables WHERE table_id = " . $_SESSION["dtp_table_id"];
            $resa = $db->query($querya);
            $rowa = $resa->fetch_assoc();

            $query4 = "SELECT tour_chips FROM tournaments_entrants WHERE player_id = " . $_SESSION["dtp_player_id"] . " AND tour_id = " . $rowa["tour_id"];
            $res4 = $db->query($query4);
            $row4 = $res4->fetch_assoc();

            $player_chips = $row4["tour_chips"] - $call_amt;

            if ($player_chips <= 0) {
                $query2 = "UPDATE tournaments_entrants SET tour_chips = 0 WHERE player_id = " . $_SESSION["dtp_player_id"] . " AND tour_id = " . $rowa["tour_id"];
            } else {
                $query2 = "UPDATE tournaments_entrants SET tour_chips = tour_chips - $call_amt WHERE player_id = " . $_SESSION["dtp_player_id"] . " AND tour_id = " . $rowa["tour_id"];
            }
            $res2 = $db->query($query2);

            $query3 = "SELECT username FROM players WHERE player_id = $player_id";
            $res3 = $db->query($query3);
            $row3 = $res3->fetch_assoc();
            $player_name = $row3["username"];

            $query2 = "SELECT cur_hand_id FROM tournament_tables WHERE table_id = " . $_SESSION["dtp_table_id"];
            $res2 = $db->query($query2);
            $row2 = $res2->fetch_assoc();
            $hand_id = $row2["cur_hand_id"];

            if ($player_chips <= 0) {
                $call_amt = $row4["tour_chips"];
                $query = "UPDATE tournament_tables SET cur_turn = $new_turn, last_player_id = $player_id, seat_" . $cur_turn . "_status = 'ALL_IN', seat_" . $cur_turn . "_stake = seat_" . $cur_turn . "_stake + $call_amt, seat_" . $cur_turn . "_cur_stake = seat_" . $cur_turn . "_cur_stake + $call_amt, last_action_dtm = now() WHERE table_id = " . $_SESSION['dtp_table_id'];
                send_table_message($db, "BTSD$player_name called \$" . number_format($call_amt, 0, ".", ",") . " and is all in", $_SESSION["dtp_table_id"]);
                append_hand_history($hand_id, "$player_name called \$" . number_format($call_amt, 0, ".", ",") . " and is all in", $db);
            } else {
                $query = "UPDATE tournament_tables SET cur_turn = $new_turn, last_player_id = $player_id, seat_" . $cur_turn . "_status = 'CALL', seat_" . $cur_turn . "_stake = seat_" . $cur_turn . "_stake + $call_amt, seat_" . $cur_turn . "_cur_stake = seat_" . $cur_turn . "_cur_stake + $call_amt, last_action_dtm = now() WHERE table_id = " . $_SESSION['dtp_table_id'];
                send_table_message($db, "BTSD$player_name called \$" . number_format($call_amt, 0, ".", ","), $_SESSION["dtp_table_id"]);
                append_hand_history($hand_id, "$player_name called \$" . number_format($call_amt, 0, ".", ","), $db);
            }
            $res = $db->query($query);
            break;
    }

    //check for end of round
    is_end_of_round($db);

}
?>

My question to you would be, how would you implement the side pots?  I guess I just need the logic help since I can't seem to get it going...

 

Thanks a ton for your help thus far!  It's helped get my mind going a little bit...just need another kick and I should be good I bet  :D

 

-Troy

Link to comment
Share on other sites

Within the switch statement I also have the raise command.  It is below.

<?php
     case "raise":
            $_SESSION["dtp_stat_raise"]++;

            $new_turn = update_turn($cur_turn, $db);
            $query1 = "SELECT cur_top_bet, seat_" . $cur_turn . "_cur_stake AS stake, seat_" . $cur_turn . " AS player_id FROM tournament_tables WHERE table_id = " . $_SESSION["dtp_table_id"];
            $res1 = $db->query($query1);
            $row1 = $res1->fetch_assoc();

            $player_id = $row1["player_id"];
            $raise = $raise_amt;
            $top_bet = $raise_amt + $row1["stake"];
            $query = "UPDATE tournament_tables SET cur_top_bet = $top_bet, last_player_id = $player_id, cur_turn = $new_turn, seat_" . $cur_turn . "_status = 'RAISE', seat_" . $cur_turn . "_stake = seat_" . $cur_turn . "_stake + $raise, seat_" . $cur_turn . "_cur_stake = seat_" . $cur_turn . "_cur_stake + $raise, last_action_dtm = now() WHERE table_id = " . $_SESSION['dtp_table_id'];
            $res = $db->query($query);
            $querya = "SELECT tour_id FROM tournament_tables WHERE table_id = " . $_SESSION["dtp_table_id"];
            $resa = $db->query($querya);
            $rowa = $resa->fetch_assoc();

            $queryab = "SELECT tour_chips FROM tournaments_entrants WHERE player_id = " . $_SESSION["dtp_player_id"] . " AND tour_id = " . $rowa["tour_id"];
            $resab = $db->query($queryab);
            $rowab = $resab->fetch_assoc();

            if ($rowab["tour_chips"] - $raise <= 0) {
                $query2 = "UPDATE tournaments_entrants SET tour_chips = 0 WHERE player_id = " . $_SESSION["dtp_player_id"] . " AND tour_id = " . $rowa["tour_id"];
            } else {
                $query2 = "UPDATE tournaments_entrants SET tour_chips = tour_chips - $raise WHERE player_id = " . $_SESSION["dtp_player_id"] . " AND tour_id = " . $rowa["tour_id"];
            }
            $res2 = $db->query($query2);

            $query3 = "SELECT username FROM players WHERE player_id = $player_id";
            $res3 = $db->query($query3);
            $row3 = $res3->fetch_assoc();
            $player_name = $row3["username"];
            $query2 = "SELECT cur_hand_id FROM tournament_tables WHERE table_id = " . $_SESSION["dtp_table_id"];
            $res2 = $db->query($query2);
            $row2 = $res2->fetch_assoc();

            $hand_id = $row2["cur_hand_id"];

            if ($rowab["tour_chips"] - $raise <= 0) {
                // player is all in
                $queryb = "UPDATE tournament_tables SET seat_" . $cur_turn . "_status = 'ALL_IN' WHERE table_id = " . $_SESSION['dtp_table_id'];
                $resb = $db->query($queryb);
                send_table_message($db, "RSSD$player_name raised to \$" . number_format($top_bet, 0, ".", ",") . " and is all in", $_SESSION["dtp_table_id"]);
                append_hand_history($hand_id, "$player_name raised to \$" . number_format($top_bet, 0, ".", ",") . " and is all in", $db);
            } else {
                send_table_message($db, "RSSD$player_name raised to \$" . number_format($top_bet, 0, ".", ","), $_SESSION["dtp_table_id"]);
                append_hand_history($hand_id, "$player_name raised to \$" . number_format($top_bet, 0, ".", ","), $db);
            }

            $querybb = "SELECT * FROM tournament_tables WHERE table_id = " . $_SESSION["dtp_table_id"];
            $resbb = $db->query($querybb);
            $rowbb = $resbb->fetch_assoc();

            $update_status = array();
            for ($j = 1; $j <= 10; $j++) {
                if ($rowbb["seat_" . $j] != 0 && $rowbb["seat_" . $j . "_status"] != "FOLD" && $rowbb["seat_" . $j . "_status"] != "ALL_IN") {
                    if ($j == $cur_turn) {
                        $update_status[$j] = $rowbb["seat_" . $j . "_status"];
                    } else if ($rowbb["seat_" . $j . "_status"] != "FOLD" && $rowbb["seat_" . $j . "_status"] != "ALL_IN") {
                        $update_status[$j] = "WAITING";
                    } else {
                        $update_status[$j] = $rowbb["seat_" . $j . "_status"];
                    }
                } else if ($rowbb["seat_" . $j] != 0) {
                    $update_status[$j] = $rowbb["seat_" . $j . "_status"];
                } else {
                    $update_status[$j] = "EMPTY";
                }
            }

            $query = "UPDATE tournament_tables SET
                seat_1_status = '" . $update_status[1] . "',
                seat_2_status = '" . $update_status[2] . "',
                seat_3_status = '" . $update_status[3] . "',
                seat_4_status = '" . $update_status[4] . "',
                seat_5_status = '" . $update_status[5] . "',
                seat_6_status = '" . $update_status[6] . "',
                seat_7_status = '" . $update_status[7] . "',
                seat_8_status = '" . $update_status[8] . "',
                seat_9_status = '" . $update_status[9] . "',
                seat_10_status = '" . $update_status[10] . "'
                WHERE table_id = " . $_SESSION["dtp_table_id"];
            $res = $db->query($query);
            break;
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.