|
@@ -17,6 +17,7 @@ pub enum EngineMsg {
|
|
|
SetPiece(Bitboard),
|
|
|
Search(SearchInfo),
|
|
|
Print,
|
|
|
+ IsReady,
|
|
|
Ping,
|
|
|
Stop,
|
|
|
NewGame,
|
|
@@ -86,34 +87,41 @@ impl Engine {
|
|
|
while let Some(msg) = self.dequeue_message() {
|
|
|
match msg {
|
|
|
EngineMsg::SetBoard{ pos, moves } => {
|
|
|
- self.game = pos;
|
|
|
- self.game.zobrist = Some((self.zobrist_table.clone(), self.game.calculate_zobrist(&self.zobrist_table)));
|
|
|
- self.move_history.clear();
|
|
|
- self.move_history.increment(self.game.calculate_zobrist(&self.zobrist_table));
|
|
|
- for mov in moves {
|
|
|
- let m = self.game.parse_move(&mov);
|
|
|
- if let Ok(mm) = m {
|
|
|
- self.game.apply(mm);
|
|
|
- self.move_history.increment(self.game.calculate_zobrist(&self.zobrist_table));
|
|
|
- }
|
|
|
- else {
|
|
|
- println!("{}", self.game.beautiful_print());
|
|
|
- println!("error parsing move {}", mov);
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
+ self.set_position(pos, &moves);
|
|
|
},
|
|
|
EngineMsg::Search(ref info) => {
|
|
|
self.start_search(info);
|
|
|
},
|
|
|
EngineMsg::Print => {
|
|
|
println!("{}", self.game.beautiful_print());
|
|
|
+ },
|
|
|
+ EngineMsg::IsReady => {
|
|
|
+ println!("readyok");
|
|
|
}
|
|
|
_ => {}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ fn set_position(&mut self, pos: Game, moves: &Vec<String>) {
|
|
|
+ self.game = pos;
|
|
|
+ self.game.zobrist = Some((self.zobrist_table.clone(), self.game.calculate_zobrist(&self.zobrist_table)));
|
|
|
+ self.move_history.clear();
|
|
|
+ self.move_history.increment(self.game.calculate_zobrist(&self.zobrist_table));
|
|
|
+ for mov in moves {
|
|
|
+ let m = self.game.parse_move(&mov);
|
|
|
+ if let Ok(mm) = m {
|
|
|
+ self.game.apply(mm);
|
|
|
+ self.move_history.increment(self.game.calculate_zobrist(&self.zobrist_table));
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ println!("{}", self.game.beautiful_print());
|
|
|
+ println!("error parsing move {}", mov);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* blocks until a message is available
|
|
|
*/
|
|
@@ -157,6 +165,10 @@ impl Engine {
|
|
|
messages.push_back(msg);
|
|
|
return true;
|
|
|
}
|
|
|
+ if let EngineMsg::IsReady = msg {
|
|
|
+ println!("readyok");
|
|
|
+ return false;
|
|
|
+ }
|
|
|
else {
|
|
|
messages.push_back(msg);
|
|
|
}
|
|
@@ -244,6 +256,13 @@ impl Engine {
|
|
|
}
|
|
|
depth += 1;
|
|
|
}
|
|
|
+ else if let SearchResult::Cancelled(Some((bm, bv))) = search_result {
|
|
|
+ if best_move == Move::Nullmove {
|
|
|
+ best_move = bm;
|
|
|
+ best_val = bv;
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ }
|
|
|
else {
|
|
|
break;
|
|
|
}
|