1
public class ChessEngineUCI : ChessEngine
5
private string[] options;
6
private bool waiting_for_move;
8
public ChessEngineUCI (string[] options)
10
this.options = options;
13
starting.connect (start_cb);
16
private void start_cb ()
21
public override void start_game ()
23
write_line ("ucinewgame");
26
public override void request_move ()
29
write_line ("position startpos moves" + moves);
31
write_line ("position startpos");
32
waiting_for_move = true;
33
write_line ("go wtime 30000 btime 30000");
36
public override void report_move (ChessMove move)
38
moves += " " + move.get_engine ();
41
public override void undo ()
45
waiting_for_move = false;
46
moves = moves.slice (0, moves.last_index_of (" "));
49
public override void process_input (char[] data)
52
int current = buffer.length;
53
buffer.resize ((int) (buffer.length + data.length));
54
for (int i = 0; i < data.length; i++)
55
buffer[current + i] = data[i];
62
for (offset = 0; offset < buffer.length && buffer[offset] != '\n'; offset++);
63
if (offset >= buffer.length)
66
buffer[offset] = '\0';
67
string line = (string) buffer;
69
debug ("Read from engine: '%s'", line);
71
string[] tokens = line.split (" ");
72
if (tokens.length > 0)
80
if (tokens.length != 1)
81
warning ("Unexpected arguments on uciok: %s", line);
87
if (tokens.length != 1)
88
warning ("Unexpected arguments on readyok: %s", line);
94
if (tokens.length < 2)
95
warning ("No move with bestmove: %s", line);
96
debug ("Engine moves %s", tokens[1]);
97
waiting_for_move = false;
108
warning ("Unknown command: '%s'", line);
113
buffer = buffer[offset+1:buffer.length];
117
private void configure ()
119
foreach (var o in options)
120
write_line ("setoption %s".printf (o));
121
write_line ("isready");