Sidonia Chess Programs  Online Documentation Incomplete First Draft
Chess Engine, Chess Interpreter, Game recorder, Game analysis
Interpreter Examples

Interpreter Examples

Hopefully the examples will illustrate the sort of things I can do with the Sidonia script interpreter. The first example shows how it can be used to filter out unwanted games from a PGN file (wrong player or wrong colour), and unwanted positions from an EPD file (wrong side to move) in order to create a very specific opening book.

The following Sidonia interpreter commands are illustrated.

  • foreachgame
  • pgntext
  • foreach_epd
  • epdtext
  • book
  • stm
  • addtext

Filtering a PGN file

Tim Hilton from my chess club had a game scheduled against Damion McCarthy. Tim would be playing white. I had combined PGN files containing games of tournaments in which Damian McCarthy had competed into one file called all.PGN. I now wanted to extract the games where Damian McCarthy had played and was black into another file.

1 if {[file exists McCarthy_is_black.pgn]} {file delete McCarthy_is_black.pgn}
2 
3 foreachgame {tag moves} all.pgn \
4 {
5  if {![string equal $tag(Black) {McCarthy, Damian}]} continue
6  addtext [pgntext tag $moves] McCarthy_is_black.pgn
7 }

Filtering an EPD file

I then copied the moves from McCarthy_is_black.pgn into an EPD file - a process which is not yet clean enough to descibe here - and then I extracted the black moves only (bo.epd) in order to create an opening book that would play black like Damian McCarthy.

1 if {[file exists bo.epd]} {file delete bo.epd}
2 foreach_epd epd McCarthy_is_black.epd \
3 {
4  set stm [stm $epd(position)]
5  if {[string equal $stm Black]} \
6  {
7  addtext [epdtext epd] bo.epd
8  }
9 }
10 
11 book bo.epd McCarthy_is_black.bin

Searching positions in a game

This example searches 2 ply deep for every position in the games and writes the number of nodes evaluated to an EPD file. This is from some testing of my implementation of Tomasz Michniewski's simple evaluation function, and so piece square tables and search function are appropriately initialised first.

1 uci {setoption name Piece Square Tables value Tomasz Michniewski}
2 uci {setoption name Evaluation Function value Michniewski SEF}
3 uci {setoption name Search Routine value Simplest Search}
4 
5 searchmode clear
6 searchmode depth 2
7 
8 foreachgame {tag moves} games.pgn \
9 {
10  foreach_position pos $moves [startpos] \
11  {
12  reset counters
13  set epd(position) $pos
14 
15  search $pos
16 
17  set epd(acn) [nodes evaluated]
18  ensure [epdtext epd] output.epd
19  }
20 }

Genetics

This example shows the use of some of the genetics functions, namely the use of person, DNA and cross. DNA is though of as being a number. DNA is mapped to names using the person function, and names are mapped back to DNA using the DNA function. To mate two partners and produce an offspring, the function cross is provided. This produces the DNA of a random offspring, which obtains half its DNA (bits) from each parent.

1 set dad [DNA Joe]
2 set mum [DNA Nancy]
3 set kid [cross $dad $mum]
4 
5 puts "[person $dad male]($dad) and [person $mum female]($mum) have a child called [person $kid ?]($kid)."

produces

Joe(443) and Nancy(133) have a child called Morgana(173).

Search

This example shows the use the interpreter's search function.

1 searchmode clear ;#< Start with an empty search mode
2 searchmode depth 4 ;#< Add in the required depth of search
3 
4 search [startpos] ;#< Search from the start position
5 
6 ensure "[bestmove] [score]" ensure "[SAN [pv] [startpos]]" #< With a beautified PV

produces

b1c3 18
Nc3 Nc6 Nf3 Nf6