3 Cards Rummy

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    3 Cards Rummy

    index.php (rename page as u like)

    Code:
    <?php
    
    /*Coder- HaWK ENTERPRISES
    shared by:- Vishal
    
    */
    
    session_start();
    
    $default = false;
    
    $round1 = false;
    
    $round2 = false;
    
    if(!isset($_POST[&#39;mode&#39;])){
    
        $default = true;
    
    }else{
    
        if($_POST[&#39;mode&#39;] == &#39;round1&#39; && isset($_POST[&#39;bet&#39;]))
    
            $round1 = true;
    
        if($_POST[&#39;mode&#39;] == &#39;round2&#39; && isset($_POST[&#39;submit&#39;]))
    
            $round2 = true;
    
    }
    
    
    
    if($default){
    
        ?>
    
        <form action="" method="post">
    
            <input type="hidden" name="mode" value="round1">
    
            Bet <input type="text" size="2" name="bet"><input type="submit" name="submit" value="bet">
    
        </form>
    
        <?
    
    }
    
    if($round1){
    
        $card_points = array(2,3,4,5,6,7,8,9,10,10,10,10,1);
    
        $card_values = array(2,3,4,5,6,7,8,9,10,&#39;J&#39;,&#39;Q&#39;,&#39;K&#39;,&#39;A&#39;);
    
        $card_order = array(2,3,4,5,6,7,8,9,10,11,12,13,1);
    
        $card_suits = array(&#39;H&#39;,&#39;S&#39;,&#39;C&#39;,&#39;D&#39;);
    
        $card_html = array("H"=>&#39;&hearts;&#39;,"S"=>&#39;&spades;&#39;,"C"=>&#39;&clubs;&#39;,"D"=>&#39;&diams;&#39;);
    
        $bet = preg_replace(&#39;/[0-9]/&#39;,&#39;&#39;,$_POST[&#39;bet&#39;]);
    
        $deck = array();
    
        foreach($card_suits as $idx=>$suit){
    
            foreach($card_values as $idxv=>$value){
    
                $deck[] = array(&#39;points&#39; => $card_points[$idxv],&#39;suit&#39;=>$suit,&#39;value&#39;=>$value,&#39;order&#39;=>$card_order[$idxv],&#39;str&#39;=>$card_html[$suit].$value);
    
                
    
            }
    
        }
    
        shuffle($deck);
    
    
    
        $dealer[] = array_pop($deck);
    
        $dealer[] = array_pop($deck);
    
        $dealer[] = array_pop($deck);
    
            foreach($dealer as $vs)
    
             $sortAux[] = $vs[&#39;order&#39;];
    
            array_multisort($sortAux, SORT_ASC, $dealer);
    
            
    
    
    
        $player[] = array_pop($deck);
    
        $player[] = array_pop($deck);
    
        $player[] = array_pop($deck);
    
        $sortAux = null;
    
            foreach($player as $vs)
    
             $sortAux[] = $vs[&#39;order&#39;];
    
            array_multisort($sortAux, SORT_ASC, $player);
    
    
    
        display($dealer,true);
    
        echo &#39;
    
    &#39;;
    
        display($player);
    
    
    
        $_SESSION[&#39;p&#39;] = serialize($player);
    
        $_SESSION[&#39;d&#39;] = serialize($dealer);
    
        $_SESSION[&#39;b&#39;] = serialize($bet);
    
        ?>
    
        <form action="" method="post">
    
            <input type="hidden" name="mode" value="round2">
    
            <input type="submit" name="submit" value="fold"> <input type="submit" name="submit" value="raise">
    
        </form>
    
        <?
    
    }
    
    if($round2){
    
    
    
        if($fold){
    
            header(&#39;Location:?&#39;);
    
            exit;
    
        }
    
    // other functions
    
        $dealer = unserialize($_SESSION[&#39;d&#39;]);
    
        $player = unserialize($_SESSION[&#39;p&#39;]);
    
        $bet = unserialize($_SESSION[&#39;b&#39;]);
    
        $bonusbet = 0;
    
        $dealer_score = display($dealer);
    
        echo &#39;
    
    &#39;;
    
        $player_score = display($player);
    
        
    
        if($dealer_score > 20 && $dealer_score > $player_score){
    
            echo &#39;Dealer does not qualify&#39;;
    
            echo &#39;You get your money back&#39;;
    
        }else{
    
            echo &#39;You lose your money&#39;;
    
        }
    
        if($dealer_score > $player_score){
    
            echo &#39;You win.
    &#39;;
    
            if($player_score == 0){
    
                $bonusbet = $bet * 25;
    
            }elseif($player_score > 0 && $player_score <= 6){
    
                $bonusbet = $bet * 4;
    
            }elseif($player_score > 6 && $player_score <= 10){
    
                $bonusbet = $bet;
    
            }elseif($player_score > 10 && $player_score <= 12){
    
                $bonusbet = $bet*4;
    
            }
    
            if($player_score == 0){
    
                $bet = $bonusbet + ($bet * 4);
    
            }elseif($player_score > 0 && $player_score <= 5){
    
                $bet = $bonusbet + ($bet * 2);
    
            }elseif($player_score > 5 && $player_score <= 19){
    
                $bet = $bonusbet + $bet;
    
            }
    
            echo &#39;Your Score:&#39;.$bet;
    
        }
    
        echo &#39;
    [url="?"]New[/url]&#39;;
                     }
    
    function display($hand,$isDealer = false){
    
        $score = null;
    
        for($i=0;$i<3;$i++){
    
            if($isDealer)
    
                echo &#39;<div style="border:1px solid black;width:50px;display:inline;padding:2px;"></div>&#39;;
    
            else
    
                echo &#39;<div style="border:1px solid black;width:38px;display:inline;padding:2px;">&#39;.$hand[$i][&#39;str&#39;].&#39;</div>&#39;;
    
        }
    
        if($isDealer == false)
    
            $score = calculate_score($hand);
    
        if($score != null) echo $score;
    
        return $score;
    
    }
    
    function calculate_score($hand){
    
        
    
        $card2suit = false;
    
        $card2suitb = false;
    
        $card3suit = false;
    
        $pairA = false;
    
        $pairB = false;
    
        $triple = false;
    
        //suited run check
    
        if($hand[0][&#39;suit&#39;] == $hand[1][&#39;suit&#39;]){
    
            $diff = $hand[1][&#39;order&#39;] - $hand[0][&#39;order&#39;];
    
            if($diff == 1){
    
                $card2suit = true;
    
            }
    
        }
    
        if($hand[1][&#39;suit&#39;] == $hand[2][&#39;suit&#39;]){
    
            $diff = $hand[2][&#39;order&#39;] - $hand[1][&#39;order&#39;];
    
            if($diff == 1){
    
                $card2suitb = true;
    
            }
    
        }
    
        if($card2suit && $card2suitb) $card3suit = true;
    
        
    
        if($hand[0][&#39;value&#39;] == $hand[1][&#39;value&#39;]) $pairA = true;
    
        if($hand[1][&#39;value&#39;] == $hand[2][&#39;value&#39;]) $pairB = true;
    
        
    
        if($pairA && $pairB) $triple = true;
    
        
    
        if($card3suit || $triple) return 0;
    
        if($card2suit || $pairA) return $hand[2][&#39;points&#39;];
    
        if($card2suitb || $pairB) return $hand[0][&#39;points&#39;];
    
        
    
        return $hand[0][&#39;points&#39;]+$hand[1][&#39;points&#39;]+$hand[2][&#39;points&#39;];
    
    }
    
    ?>

    Games Rules /Informations

    Code:
    Description and Objective
    
    
    
    The game of Vegas Three Card Rummy is played between the Dealer and the Player with a 52-card deck. The Player is dealt three cards face up and the Dealer is dealt three cards face down. The goal of Vegas Three Card Rummy is to get fewer points than the Dealer.
    
    
    
    The Dealer&#39;s hand must have 20 points or less to qualify. If the Dealer does not qualify, the Player wins even money on the Ante and the Raise is returned. The payout for the Bonus Bet is determined independently from the Dealer&#39;s hand.
    
    Vegas Three Card Rummy Rules:
    
    
    
        * Cards are dealt from a single deck.
    
        * Both Dealer and Player receive three cards. The Dealer&#39;s cards are dealt face down.
    
        * The Bonus Bet is paid based on the pay table located below.
    
        * Cards are shuffled after every hand.
    
    
    
    Card Values
    
    
    
    Cards 2 through 10 = face value
    
    
    
    Jack, Queen, King = 10 points
    
    
    
    Aces = 1 point
    
    
    
    Any Pair = 0 points
    
    
    
    Any Triple = 0 points
    
    
    
    Two-card Suited Run = 0 points
    
    
    
    Three-card Suited Run = 0 points
    
    
    
    Note - Ace, King is not a suited run
    
    
    
    Important - When a hand can be scored as either a pair or a two-card suited run and neither leads to a lower score, the two-card suited run will always be used to determine the score. When a hand can be scored as either a pair or a two-card suited run, the two-cards that will be chosen will result in the lowest possible score for a given hand.
    
    The Ante Wager
    
    
    
    After placing an Ante wager the Player is dealt 3 cards face up and the Dealer receives 3 cards face down. If the Player does not believe their hand can beat the Dealer, the Player can fold the hand and forfeit the Ante wager.
    
    
    
    If the Player believes the hand can beat the Dealer&#39;s hand, the Player must Raise with a wager equal to the Ante amount. After Raising, the Dealer&#39;s cards will be revealed. To qualify the Dealer&#39;s hand must contain 20 points or less. If qualified, the Dealer&#39;s hand will be compared to the Player&#39;s hand, the winner having the lowest point total in their hand. If the Dealer has the lowest point total the Player loses both the Ante and Raise bets. If the Dealer does not qualify, the Player wins even money on the Ante and the Raise wager is returned. If the Player has the lowest point total the Ante is paid 1:1 and the Raise wager is paid according to the pay-table (see below).
    
    The Bonus Bet
    
    
    
    The Bonus Bet is won if the Player&#39;s hand contains 12 points or less. The Bonus Bet wager is a not measured against the Dealer&#39;s hand, it is paid out based on the point total of the hand dealt, (see pay-table below). If the Player wagers on the Ante and folds the hand the Bonus Bet wager is also forfeited.
    
    
    
    Bonus Bet Payouts
    
    
    
    A-2-3 Suited Run
    
        
    
    
    
    100:1
    
    
    
    0
    
        
    
    
    
    25:1
    
    
    
    1-6
    
        
    
    
    
    2:1
    
    
    
    7-10
    
        
    
    
    
    1:1
    
    
    
    11-12
    
        
    
    
    
    4:1
    
    
    
    Payouts - Raise Bet
    
    
    
    Winner
    
        
    
    
    
    Score
    
        
    
    
    
    Payouts
    
    
    
    Player
    
        
    
    
    
    0
    
        
    
    
    
    4:1
    
    
    
    Player
    
        
    
    
    
    1-5
    
        
    
    
    
    2:1
    
    
    
    Player
    
        
    
    
    
    6-19
    
        
    
    
    
    1:1
    
    
    
    Player/Dealer Tie
    
        
    
    
    
    Any
    
        
    
    
    
    Push
    
    
    
    The Player can win if:
    
    
    
        * Ante- If the Player 3-card point total is less than the Dealer. Or if the Player Raises and the Dealer does not qualify with 20 points or less.
    
        * Raise - If the Player&#39;s 3-card point total is less than the Dealer&#39;s point total and the Dealer qualifies by having 20 points or less.
    
        * Bonus Bet - If the Player is dealt 12 points or less.
    
    
    
    The Player loses if:
    
    
    
        * Ante - If the Player folds or if the Dealer has a lower point total than the Player
    
        * Raise - If the Dealer has a lower point total than the Player.
    
        * Bonus Bet - If the Player does not receive a point total of 12 points or less.
    
    
    
    Player Actions/Button Descriptions:
    
    
    
    Bet - To place an Ante wager, the Player must click on the Ante circle and then the chip value that they wish to wager. To place a Bonus Bet wager the Player must click on the Bonus Bet diamond and then on the desired chip value they wish to wager.
    
    
    
    Deal - Press Deal to begin the game once the wagers have been placed. The Player is dealt three cards face up and the Dealer is dealt three cards face down.
    
    
    
    Raise - If the Player feels they can beat the Dealer, click Raise to continue. The Raise amount will be equal to the Ante. The Dealer&#39;s cards are then revealed and compared to the Player&#39;s hand to determine a winner.
    
    
    
    Fold - Clicking on the Fold button ends the current game and forfeits the Ante and Bonus Bet wagers.
    sigpic

    #2
    nice but a bit complicated for non card players to understand
    :p:p:p

    Comment

    Working...
    X