/**
  * Shuffle the deck and give each player a set number of cards
  * @return void
  */
 public function deals()
 {
     // Shuffle the deck
     $this->deck->shuffle();
     // Iterate through the array of players
     foreach ($this->players as $player) {
         //  Give each player the set number of cards
         for ($i = 0; $i < $this->numCards; $i++) {
             $player->receiveCard($this->deck->getCard());
         }
     }
 }
Exemple #2
0
        }
    }
    public function getHandValue()
    {
        $panier = 0;
        foreach ($this->hand as $card) {
            $panier += $card->getValue();
        }
        return $panier;
    }
}
class Bank extends Player
{
    public function __construct()
    {
        parent::__construct("Banque");
    }
}
//SCENARIO 1
$deck = new Deck();
$deck->shuffle();
$bank = new Bank();
$bank->take($deck->deal(2));
while ($bank->getHandValue() < 16) {
    $bank->take($deck->deal(1));
}
if ($bank->getHandValue() > 21) {
    echo "La banque perd " . $bank->getHandValue();
} else {
    echo "La banque a " . $bank->getHandValue();
}
            }
        }
    }
    public function shuffle()
    {
        shuffle($this->cards);
        return $this;
    }
    public function deal($n = 1)
    {
        $cards = array_splice($this->cards, 0, $n);
        return $cards;
    }
}
$d = new Deck();
list($carte) = $d->shuffle()->deal(1);
echo $carte;
class Card
{
    private $face, $color;
    public function __construct($face, $color)
    {
        $this->face = $face;
        $this->color = $color;
    }
    public function getFace()
    {
        return $this->face;
    }
    public function getColor()
    {
Exemple #4
0
 /**
  * Constructor sets up a new Deck instance
  * Also shuffles the deck
  *
  * {@link $_deck}
  */
 public function __construct()
 {
     $this->_deck = new Deck();
     $this->_deck->shuffle();
     $this->_players = array();
 }
Exemple #5
0
<?php

$iUtcStart = microtime(true);
require 'inc.cls.cardgame.php';
require 'inc.cls.pokertexasholdem.php';
card::$__tostring = function ($c) {
    return '<img suit="' . $c->suit . '" src="images/' . $c->suit . '_' . $c->short . '.gif" />';
};
$objDeck = new Deck();
$objDeck->shuffle();
$iPlayers = isset($_GET['players']) ? min(8, max(1, (int) $_GET['players'])) : 8;
?>
<!doctype html>
<html>

<head>
<title>PHP Poker Texas Hold'em Test</title>
<style>
table {
	border-collapse: collapse;
	width: 100%;
}
td {
	border: solid 2px white;
	padding: 10px;
}
.seat,
.flop {
	 text-align: center;
	 background-color: #ccc;
}
Exemple #6
0
 public function __construct($numCardsPerPlayer)
 {
     $this->numCardsPerPlayer = $numCardsPerPlayer;
     $this->deck = new Deck();
     $this->deck->shuffle();
 }
        text-align: center;
        vertical-align: middle;
        line-height: 100px;
        display: inline-block;
    }

    #card_color {
        color: red;
    }
</style>


<?php 
// Create a deck and shuffle it
$Deck = new Deck();
$Deck->shuffle();
// Create new players
$player_bob = new Player('Bob');
$player_sue = new Player('Sue');
$player_brandon = new Player('Brandon');
//give players 3 cards
for ($i = 0; $i < 3; $i++) {
    $player_bob->give_card($Deck->get_cards());
    $player_sue->give_card($Deck->get_cards());
    $player_brandon->give_card($Deck->get_cards());
}
// Show all the cards each player has been dealt
echo '<h3>' . $player_bob->get_name() . '</h3>';
echo $player_bob->render();
echo '<br/>';
echo '<h3>' . $player_sue->get_name() . '</h3>';
Exemple #8
0
 /**
  * Shuffle the deck of cards
  *
  * @return $this
  */
 public function shuffle()
 {
     $this->deck = $this->deck->shuffle();
     return $this;
 }
Exemple #9
0
<?php

require_once "Game.php";
require_once "Deck.php";
$numGames = 100000;
$results = array();
$winningStates = array();
for ($i = 0; $i < $numGames; ++$i) {
    if ($i % 10000 == 0) {
        echo "{$i}...";
    }
    $d = new Deck();
    $d->shuffle();
    $g = new Game($d);
    $turns = $g->play();
    $results[] = $turns;
    if ($turns == 1) {
        echo "YOU WON!\n";
        $winningStates[] = $g->boardToString();
    }
}
echo "Final results:\n";
foreach ($results as $result) {
    echo "{$result},";
}
echo "\n";
echo "Average: " . array_sum($results) / count($results) . "\n";
var_dump($winningStates);