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

Board games

A board game’s pieces sit on a map of cells and move a move at a time, by rules of how each piece may go. A picker (a cursor) chooses the piece and where it goes. The computer opponent is a <think>.

Moves

Checkers’ red pieces:

<group name="red" class="red" char="r">
  <sprite name="man"> ... </sprite>
  <sprite name="king"> ... </sprite>
  <moves>
    <forced />
    <step><x>-1</x><y>-1</y></step>
    <step><x>1</x><y>-1</y></step>
    <jump class="white"><x>-1</x><y>-1</y></jump>
    <jump class="white"><x>1</x><y>-1</y></jump>
    <promote sprite="king"><row>1</row></promote>
  </moves>
  <moves sprite="king"> ... all four ways ... </moves>
</group>

The picker

Any object on a map of cells, usually a cursor on a map of its own laid over the board (same tile and place), so it walks over the pieces without blocking them.

Verb Does Refused when
<pick class="red" /> takes up the piece of that class in its cell (picking again takes another) that piece has no move, or a run of jumps is under way
<pick class="red"><only /></pick> takes up the one piece with a move, wherever it is, and goes to it none or several can move, or one is held
<place /> makes the held piece’s move that ends in the picker’s cell no move ends there, or the piece must jump on
<drop /> puts the held piece back nothing held, or a run of jumps has begun
<put class="black" /> puts a new piece (a copy of the first one written) in its cell the cell is taken or the rules forbid it (below)

All are self verbs. Since a refused verb ends its list, what is written after <place /> (passing the turn) runs only when the move is over. Whose turn it is is the game’s own: Checkers keeps it in a variable and in the cursor’s looks.

The mouse. A <track /> on a map of cells puts the object in the cell under the pointer. <onto> narrows it to useful cells:

<hop direction="right"><onto class="hslot" /><onto class="vslot" /></hop>
<track><onto class="hslot" /></track>

A hop with <onto> goes to the nearest cell holding one of those classes: left and right along its row; up and down to the nearest row ahead that has one, nearest the column kept (as a text cursor keeps its column). Refused when there is none. A track with <onto> takes the one nearest the pointer.

Marks

<marks> on the picker (after its <moves>) show the play with objects of their own, copies made and taken away as the play changes:

<marks sprite="redheld">
  <held object="heldmark" />                       <!-- the cell of the piece held -->
  <moves object="movemark" variable="options.moves" />  <!-- each cell it can go to -->
  <movable object="movablemark" class="red" />     <!-- each piece of the class with a move -->
  <put object="putmark" class="black" />           <!-- each cell a piece can be put -->
  <last object="lastmark" />                       <!-- where the last move began and ended -->
</marks>

Pieces put, not moved

What a piece’s <moves> say decides where <put> may go:

In <moves> A put goes Game
<flank class="white" /> only where a line of white pieces is trapped against one of its own; the trapped pieces turn (<straight />: no slants) Reversi
<fall /> to the lowest free cell of the picker’s column Four in a Row
nothing (<moves />) any free cell Tic-Tac-Toe
<on class="hslot" /> only on a piece of that class, taking its place Dots and Boxes