XMLGameEngine

XMLGameEngine is a VGDL (video game description language) and an engine for running games completely contained within an XML file.

View the Project on GitHub beefviper/XMLGameEngine

Cards

Cards are made by a <deck>, lie in objects that are piles, and are carried between piles by a hand. Rules of a card game (what is a pair, who wins a trick) are written in the game from general parts; there is no tag for any one game.

Deck

<deck name="cards" pile="stock">
  <face><width>63</width><height>93</height><scale>1</scale><color>color.white</color><edge>color.grey</edge></face>
  <back><color>color.darkblue</color><edge>color.lightgrey</edge><pattern><row>*.....*.</row> ... </pattern></back>
  <color char="y">color.gold</color>                 <!-- colours for the court pictures -->
  <suit name="hearts">
    <color>color.red</color>
    <row>.***...***.</row> ...                       <!-- the pip -->
    <index><row>.**.**.</row> ... </index>           <!-- the corner pip -->
    <large><row>....******....</row> ... </large>    <!-- the ace's pip -->
  </suit>
  ... three more suits ...
  <rank name="3">
    <index><row>.*****.</row> ... </index>
    <pips><row>.*.</row> <row>...</row> ... <row>.v.</row></pips>
  </rank>
  <rank name="K"><index> ... </index><picture><half /><row>***...</row> ... </picture></rank>
</deck>

Piles

A <pile> on an object (or each member of a group) makes it a place that holds cards.

<object name="stock">
  <sprite name="spot"> ... </sprite>
  <pile faces="down"><deals into="waste">1</deals><refill from="waste" /></pile>
</object>
<group name="columns">
  ...
  <pile>
    <fan><y>21</y><hidden><y>6</y></hidden></fan>
    <dealt>1<more>1</more></dealt>
    <takes><othercolor /><down /><empty><rank>K</rank></empty></takes>
    <run />
    <showtop />
  </pile>
</group>
Part Means
faces="up", "down" every card laid there turns that way (none: each keeps its own)
<fan> each card’s offset from the one under it; <hidden> a face-down card’s; <width> the most it may spread across
<dealt>N</dealt> takes N in the deal, a card a round, the last face up; <more>1</more> on a group deals each member after the first one more (Klondike’s staircase)
<takes> what it takes on top: <one />, <samesuit />, <othercolor />, <up />, <down />, <matches /> (same suit or rank), <wild> ranks, <sum>13</sum>, <empty> with the ranks and suits it starts with. No <takes>: takes nothing; an empty <takes />: takes anything
<run /> a face-up card may be taken with all those on it
<showtop /> a face-down card left on top turns up
<sorted /> keeps its cards suit by suit in rank order
<lift>16</lift> the card a hand points at is drawn lifted by that much
<deals into="waste">1</deals> taking from it deals that many onto that pile (no into=: into the taking hand’s own pile)
<refill from="waste" /> taken from empty, turns that pile back into itself; <shuffle /> shuffles instead, <leave>1</leave> leaves that many

The hand

An object with <hand /> points at a pile (at a card of it) and carries cards. Its verbs are self verbs:

Verb Does Refused when
<take /> takes the card pointed at and those on it; on a stock, deals it is not a run the pile gives, or face down
<lay /> lays what it holds on the pile pointed at the pile does not take it (laying back where they came from is always allowed)
<lay pile="foundations" /> lays on the first of those piles that takes it none takes it
<drop /> puts what it holds back  
<deal />, <deal pile="stock" faces="down" /> deals one card from the pile pointed at, or from that pile into its own, turned that way  
<redeal /> a new hand: every card gathered, shuffled, dealt by each pile’s <dealt>  
<reveal pile="dealer" /> turns that pile’s cards face up  
<shuffle pile="stock" /> gathers every card into that pile face down and shuffles  
<collect pile="trick" into="stock" /> moves a pile’s cards onto another face down, out of play until the next deal  

Moving the hand. <hop> goes left and right to the nearest pile at the same height, and up and down through a fanned pile’s face-up cards, then to the next row of piles. <track /> points at the top card under the pointer; held cards follow it, so press, drag and release (on="release") move cards as Space twice does. Moved by the mouse, the hand takes and lays only over a pile or card.

Players’ cards

Crazy Eights gives each player a pile of their own:

<object name="mine">
  <pile faces="up"><fan><x>56</x><width>768</width></fan><dealt>7</dealt><sorted /></pile>
</object>
<object name="stock">
  <pile faces="down"><deals>1</deals><refill from="discard"><shuffle /><leave>1</leave></refill></pile>
</object>
<object name="discard">
  <pile faces="up"><dealt>1</dealt><takes><matches /><wild><rank>8</rank></wild></takes></pile>
</object>
<object name="hand"> ... <hand pile="mine" /> ... </object>

Points

Patterns

What a set of cards can make is written once in the game, beside <styles>, lowest first. Each <pattern> is parts that must all hold: <same>N</same> (N of one rank; two <same>s: two ranks), <run>N</run> (N worths in a row, any of a card’s worths counting), <suited>N</suited> (N of one suit).

<patterns name="poker">
  <pattern name="pair"><same>2</same></pattern>
  <pattern name="twopair"><same>2</same><same>2</same></pattern>
  <pattern name="three"><same>3</same></pattern>
  <pattern name="straight"><run>5</run></pattern>
  <pattern name="flush"><suited>5</suited></pattern>
  <pattern name="fullhouse"><same>3</same><same>2</same></pattern>
  <pattern name="four"><same>4</same></pattern>
  <pattern name="straightflush"><run>5</run><suited>5</suited></pattern>
</patterns>

A pile scores by them with <score patterns="poker"><with pile="board"><full>5</full></with><best>5</best></score>: with that pile’s cards (<full>: how many it holds once dealt), the best five of all. Live numbers:

Melds

<score patterns="rummy"><melds /><best>10</best></score> splits the cards into groups that each make a pattern with all their cards, leaving the fewest points over. The pile is laid out in its groups. Live deadwood is the points left over by the best <best> cards.

<patterns name="rummy">
  <pattern name="set"><same>3</same></pattern>
  <pattern name="run"><run>3</run><suited>3</suited></pattern>
</patterns>

Tricks

<object name="trick">
  <pile faces="up"><fan><x>64</x></fan>
    <trick><breaks><suit>hearts</suit></breaks><trumps><suit>spades</suit></trumps></trick>
    <points><each suit="hearts">1</each><each suit="spades" rank="Q">13</each></points>
  </pile>
</object>
<object name="hand"> ... <hand pile="mine"><seat>1</seat><team>1</team></hand> ... </object>

Covering and pairs

Pyramid: a hand’s <holds>2</holds> may take the top card of another pile while holding, from that many piles in all; <drop /> puts each back. A pile’s <takes><sum>13</sum></takes> takes all the cards held when their worths add up to that. So a pick is <take /> then <lay pile="pairs" />, else <drop />.

The computer

<think object="cpuhand" button="f12" /> on a hand with its own pile plays cards by rules of thumb, not a search: every half second it points the hand at what it will do and presses the button, and the game’s own actions do the move.