>I was very impressed by Mike's script. Do you have one for annotating
games.

>I have a server I would like to ssh to and just leave annotating games
during the night without a graphical interface.

>Thanks a lot.

>I'm also interested to learn about any helpful documentation on
scid/scripting.

>cheers
>R

Here's another example for our scid scripting cookbook:

--8<---------------cut here---------------start------------->8---
#!/bin/bash
# annotate <database> <engine> <seconds> \
exec tcscid "$0" "$@"
package require Expect

proc analyze { position engine seconds } {
  set variation ""; set engine_id ""; set eval ""
  log_user 0
  set timeout $seconds
  exp_spawn "$engine"
  exp_send "uci\n"
  exp_send "position fen $position\n"
  exp_send "go movetime ${seconds}000\n"
  expect {
    timeout {
      puts stderr "timeout"
      exp_send "quit\n"
    }
    "bestmove" {
      exp_send "quit\n"
    }
    -re "id name \[^\r\n\]+" {
      regsub ".*id name " $expect_out(buffer) "" engine_id
      exp_continue
    }
    -re "score mate \[0-9\]+" {
      regsub ".*score " $expect_out(buffer) "" eval
      exp_continue
    }
    -re "score cp -*\[0-9\]+" {
      regsub ".*score cp " $expect_out(buffer) "" eval
      # convert cenipawn and adjust sign
      if {[sc_pos side] == "black"} { set eval [expr {- $eval}] }
      set eval [format "%+.2f" [expr {$eval / 100.0}]]
      exp_continue
    }
    -re "pv \[^\r\n\]+" {
      regsub ".*pv " $expect_out(buffer) "" variation
      # engine output is e7e8q, addSan requires e7e8Q
      set fix_promotions {"q" "Q" "r" "R" "n" "N" "b " "B "}
      set variation [string map $fix_promotions $variation]
      exp_continue
    }
  }
  exp_close
  exp_wait
  return [list $variation $engine_id $eval]
}

set database [lindex $argv 0]
set engine [lindex $argv 1]
set seconds [lindex $argv 2]

sc_base open $database
set numGames [sc_base numGames]
for {set i 1} {$i <= $numGames} {incr i} {
  sc_game load $i
  sc_move forward 6
  while {[sc_pos isAt end] == 0} {
    puts stderr "Game $i/$numGames, move [sc_pos moveNumber], [sc_pos side]"
    set result [analyze [sc_pos fen] $engine $seconds]
    puts stderr $result

    set variation [lindex $result 0]
    set engine_id [lindex $result 1]
    set eval [lindex $result 2]

    sc_var create
    sc_move addSan $variation
    sc_pos setComment "$engine_id: $eval"
    sc_var exit
    sc_move forward
  }
  puts [sc_game pgn]
}
--8<---------------cut here---------------end--------------->8---

./annotate blitzgames stockfish 5 | tee annotated.pgn

*Mike
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Scid-users mailing list
Scid-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/scid-users

Reply via email to