Next: , Previous: , Up: Programming with libtarot   [Contents][Index]


4.4 XML representation of games

The XML representation of a game is simply the collection of events that constitue it. Here is the Relax-NG schema for the games:

<?xml version="1.0" encoding="utf-8"?>
<!-- tarot implements the rules of the tarot game
Copyright (C) 2019  Vivien Kraus

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, version 3 of the License.

This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.
-->

<grammar xmlns="http://relaxng.org/ns/structure/1.0"
         ns="http://planete-kraus.eu/tarot">
  <start>
    <element name="game">
      <zeroOrMore>
        <interleave>
          <ref name="event" />
        </interleave>
      </zeroOrMore>
    </element>
  </start>
  <define name="event">
    <choice>

      <!-- SETUP -->
      <element name="setup">
        <attribute name="n-players" />
        <attribute name="with-call" />
      </element>

      <!-- DEAL or DEAL-ALL -->
      <element name="deal">
        <attribute name="to" />
        <zeroOrMore>
          <ref name="card" />
        </zeroOrMore>
      </element>
      <element name="deal-all">
        <zeroOrMore>
          <ref name="player" />
        </zeroOrMore>
      </element>

      <!-- BID -->
      <element name="bid">
        <attribute name="bid" />
      </element>

      <!-- DECL -->
      <element name="decl">
        <attribute name="slam" />
      </element>

      <!-- CALL -->
      <element name="call">
        <attribute name="card" />
      </element>

      <!-- DOG -->
      <element name="dog">
        <oneOrMore>
          <ref name="card" />
        </oneOrMore>
      </element>

      <!-- DISCARD -->
      <element name="discard">
        <zeroOrMore>
          <ref name="card" />
        </zeroOrMore>
      </element>

      <!-- HANDFUL -->
      <element name="handful">
        <zeroOrMore>
          <ref name="card" />
        </zeroOrMore>
      </element>

      <!-- CARD -->
      <ref name="card" />
    </choice>
  </define>

  <define name="card">
    <element name="card">
      <attribute name="card" />
    </element>
  </define>

  <define name="player">
    <element name="player">
      <attribute name="player" />
    </element>
  </define>
</grammar>

The validation for game events is volutarily under-specified, because it ultimately needs to understand the game rules.

There are no code to export to xml or import from xml as of yet.


Next: , Previous: , Up: Programming with libtarot   [Contents][Index]