Keep(""),
'h' => Keep("
"),
'd' => Keep("
"),
'c' => Keep("
")));
## The default style for card tables.
SDV($HTMLStylesFmt['cards'], ' table.cards td { text-align:left; width:120px; } ');
SDVA($CardNames, array(
'a' => ' A', 'A' => ' A',
'k' => ' K', 'K' => ' K',
'q' => ' Q', 'Q' => ' Q',
'j' => ' J', 'J' => ' J',
't' => ' 10', 'T' => ' 10', '10' => ' 10',
'9' => ' 9', '8' => ' 8', '7' => ' 7', '6' => ' 6',
'5' => ' 5', '4' => ' 4', '3' => ' 3', '2' => ' 2',
'x' => ' x', 'X' => ' X'));
## handle inline display of suits
Markup('cdhs', 'inline',
'/(?<=\\s)([cdhs])(?=\\s)/',
"mu_cdhs]");
function mu_cdhs($m) {
return $GLOBALS['CardSuitHTML'][$m[1]];
}
## (:cards:)
Markup('cards', 'block',
'/\\(:cards\\s+(["\']?)(.+?)\\1\\s*:\\)/',
"mu_cards");
function mu_cards($m) {
return Keep(CardTable($m[2]));
}
## PlayerHand($spec) takes a spec like "A8765.QT.K9.AT87" and
## displays it in the form
## s A 8 7 6 5
## h Q 10
## d K 9
## c A 10 8 7
function PlayerHand($spec) {
global $CardSuitHTML, $CardNames;
$suit = array_keys($CardSuitHTML);
$s = array_shift($suit); $out = $CardSuitHTML[$s];
$i = 0;
while ($i < strlen($spec)) {
$c2 = substr($spec, $i, 2);
$c1 = $spec{$i};
if ($c2 == '.-')
{ $s = array_shift($suit); $i += 2; continue; }
else if ($c1 == '.') {
$s = array_shift($suit);
$out .= '
' . $CardSuitHTML[$s];
$i++;
continue;
}
else if ($c1 == '-') { $out = ''; $i++; continue; }
if (@$CardNames[$c2]) { $out .= $CardNames[$c2]; $i += 2; continue; }
if (@$CardNames[$c1]) { $out .= $CardNames[$c1]; $i++; continue; }
$i++;
}
while ($suit)
{ $s = array_shift($suit); $out .= '
' . $CardSuitHTML[$s]; }
return $out;
}
## Display a hand or set of hands (board) in a table. The board is
## represented as a space-separate list of hands -- each hand can
## be prefixed with one of N: S: E: W: to indicate the player.
## If the first hand doesn't have a prefix, N: is assumed,
## subsequent hands w/o prefix are one position clockwise from the
## previous hand.
function CardTable($spec) {
$hands = preg_split('/\\s+/', trim($spec));
$player = 'W';
while ($hands) {
$phand = array_shift($hands);
if (!preg_match('/^(([NESW]):)?(.*)$/i', $phand, $match)) continue;
$player = (@$match[2])
? strtoupper($match[2])
: substr('NESW', strpos('WNES', $player), 1);
if ($match[3] != '-')
$board[$player] = PlayerHand($match[3]);
}
$out = "
' . $board['N'] . ' | ||
' . @$board['W'] . ' | ' . @$board['E'] . ' | |
' . $board['S'] . ' |