<?xml version="1.0" encoding="ISO-8859-1" ?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">

<!-- Global type definitions -->

<xs:simpleType name="annotation">
  <xs:restriction base="xs:string">
    <xs:whiteSpace value="preserve"/>
  </xs:restriction>
</xs:simpleType>

<xs:simpleType name="movesquare">
  <xs:restriction base="xs:positiveInteger">
    <xs:minInclusive value="1"/>
    <xs:maxInclusive value="32"/>
  </xs:restriction>
</xs:simpleType>

<xs:simpleType name="fenturn">
  <xs:restriction base="xs:string">
    <xs:enumeration value="B"/>
    <xs:enumeration value="W"/>
  </xs:restriction>
</xs:simpleType>

<xs:simpleType name="fenlist">
  <xs:restriction base="xs:string">
   <xs:pattern value="(1|2|3|4|5|6|7|8|9|10|11|12|13|14|15|16|17|18|19|20|21|22|23|24|25|26|27|28|29|30|31|32(,)*)*"/>
  </xs:restriction>
</xs:simpleType>

<!-- Top level element -->
<xs:element name="game">
 <xs:complexType>
  <xs:sequence>
   
   <!-- PDN Headers come first, all are optional --> 
   <xs:element name="event" type="xs:string" minOccurs="0"/>
   <xs:element name="date" type="xs:date" minOccurs="0"/>
   <xs:element name="black" type="xs:string" minOccurs="0"/>
   <xs:element name="white" type="xs:string" minOccurs="0"/>
   <xs:element name="result" type="xs:string" minOccurs="0"/>
   <xs:element name="site" type="xs:string" minOccurs="0"/>
   <xs:element name="round" type="xs:string" minOccurs="0"/>
   <xs:any minOccurs="0"/> <!-- Allow extensibility -->
   
   <!-- If the game commences from a Setup position, there will be a FEN element.
		Otherwise the game is assumed to start from the start position 
   -->
   <xs:element name="fen" minOccurs="0">
    <xs:complexType>
     <xs:sequence>
	  <!-- turn is either "B" or "W" showing who's turn it is -->
	  <xs:element name="turn" type="fenturn"/>
	  <!-- "bm","wm","bk","wk" elements are comma separated list of squares occupied, 
	       bm = black men, wk = white kings, etc.
	       and look like "3,6,7,9,11,28". All are optional if none of those piece
		   types exists on the board. Nasty, I know.. will redo in version 2 
      -->
	  <xs:element name="bm" type="fenlist" minOccurs="0"/>
	  <xs:element name="bk" type="fenlist" minOccurs="0"/>
	  <xs:element name="wm" type="fenlist" minOccurs="0"/>
	  <xs:element name="wk" type="fenlist" minOccurs="0"/>
     </xs:sequence>
    </xs:complexType>
   </xs:element>

   <!-- (Anno)tation at the start of the game is optional -->
   <xs:element name="anno" type="annotation" minOccurs="0"/>
   
   <!-- Each move now follows, they must be in sequence. Note: it is possible
        to have no moves at all, just a fen element, and perhaps a start of game annotation. 
   -->
   <xs:element name="m" minOccurs="0" maxOccurs="unbounded">
    <xs:complexType>
     <xs:sequence>
	  
	  <!-- The following (optional) are internal data to Nemesis -->
      <xs:element name="depth_av" type="xs:decimal" minOccurs="0"/>
      <xs:element name="depth_max" type="xs:decimal" minOccurs="0"/>
      <xs:element name="value" type="xs:decimal" minOccurs="0"/>
      <xs:element name="knodes" type="xs:decimal" minOccurs="0"/>
      <xs:element name="time_taken" type="xs:decimal" minOccurs="0"/>
      <xs:element name="rate" type="xs:decimal" minOccurs="0"/>
      <xs:element name="pv" type="xs:string" minOccurs="0"/>
      <xs:element name="stat_date" type="xs:positiveInteger" minOccurs="0"/>
      <xs:any minOccurs="0"/> <!-- Allow extensibility -->
      
	  <!-- Anno(tation) against this move is also optional -->
	  <xs:element name="anno" type="annotation" minOccurs="0"/>
     
	 </xs:sequence>
	 <!-- Attributes "f" = 'from' square, "t" = 'to' final destination square
	      Note: Ambiguous from-to moves, although rare, cannot be resolved this way, 
	      will be fixed in version 2 
     -->
     <xs:attribute name="f" type="movesquare" use="required"/>
     <xs:attribute name="t" type="movesquare" use="required"/>
    </xs:complexType>
   </xs:element>
   <!-- End of move ("m") element -->

  </xs:sequence>
  <!-- xml game version -->
  <xs:attribute name="version" type="xs:decimal" use="optional" default="1.0"/>
 </xs:complexType>
</xs:element>
</xs:schema>