Skip to content

Instantly share code, notes, and snippets.

@kentasaito
Created April 22, 2014 04:07
Show Gist options
  • Save kentasaito/11165052 to your computer and use it in GitHub Desktop.
Save kentasaito/11165052 to your computer and use it in GitHub Desktop.
テキサスホールデム
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<?php
class Deck {
private $cards;
public function __construct($label = FALSE, $has_cards = FALSE)
{
$this->label = $label === FALSE ? 'deck' : $label;
$this->cards = [];
if ($has_cards === TRUE)
{
$this->cards = range(52, 103);
// $this->cards = range(0, 51);
shuffle($this->cards);
}
}
public function draw()
{
$suits = ['s', 'h', 'd', 'c'];
$kazu = ['01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12', '13'];
echo $this->label.'<br />';
foreach ($this->cards as $card)
{
if ($card < 52)
{
echo '<img src="img/'.$suits[floor($card / 13) % 4].$kazu[$card % 13].'.gif" />';
}
else
{
echo '<img src="img/ug0.gif" />';
}
}
echo '<br />';
}
public function pop()
{
return array_pop($this->cards);
}
public function push($card, $open = FALSE)
{
array_push($this->cards, $card % 52 + ($open === FALSE ? 52 : 0));
}
}
class Table {
private $ninzu;
private $yamafuda;
private $tefuda;
private $sutefuda;
private $bafuda;
public function __construct($ninzu = 2)
{
$this->ninzu = $ninzu;
$this->yamafuda = new Deck('山札', TRUE);
for ($i = 0; $i < $this->ninzu; $i++)
{
$this->tefuda[] = new Deck('プレイヤー'.($i + 1));
}
$this->sutefuda = new Deck('捨札');
$this->bafuda = new Deck('場札');
}
public function draw($label = FALSE)
{
echo '<strong>'.$label.'</strong><br />';
// $this->yamafuda->draw();
echo '<table><tr>';
for ($i = 0; $i < $this->ninzu; $i++)
{
echo '<td>';
$this->tefuda[$i]->draw();
echo '</td>';
}
echo '</tr></table><table><tr>';
echo '<td>';
$this->sutefuda->draw();
echo '</td>';
echo '<td>';
$this->bafuda->draw();
echo '</td>';
echo '</tr></table>';
echo '<hr />';
}
public function preflop()
{
for ($j = 0; $j < 2; $j++)
{
for ($i = 0; $i < $this->ninzu; $i++)
{
$this->tefuda[$i]->push($this->yamafuda->pop(), TRUE);
}
}
}
public function flop()
{
$this->sutefuda->push($this->yamafuda->pop());
for ($i = 0; $i < 3; $i++)
{
$this->bafuda->push($this->yamafuda->pop(), TRUE);
}
}
public function turn()
{
$this->sutefuda->push($this->yamafuda->pop());
$this->bafuda->push($this->yamafuda->pop(), TRUE);
}
public function river()
{
$this->sutefuda->push($this->yamafuda->pop());
$this->bafuda->push($this->yamafuda->pop(), TRUE);
}
}
$table = new Table(4);
$table->preflop();
$table->draw('プリフロップ');
$table->flop();
$table->draw('フロップ');
$table->turn();
$table->draw('ターン');
$table->river();
$table->draw('リバー');
?>
<a href="">Reload</a>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment