#include "move.h"
#include "move_do.h"
#include "move_legal.h"
+#include "move_gen.h"
#include "option.h"
#include "parse.h"
#include "san.h"
typedef struct {
int state;
bool computer[ColourNb];
+ bool playedAllMoves[ColourNb];
int exp_move;
int hint_move;
int resign_nb;
XB->node_rate = -1;
}
+
+static list_t move_list[1];
+
// xboard2uci_gui_step()
void xboard2uci_gui_step(char string[]) {
if (option_get_bool(Option,"Book")) {
game_get_board(Game,board);
book_disp(board);
+ } else { // [HGM] without book, print all legal moves
+ int i, gen=!list_size(move_list);
+ game_get_board(Game,board);
+ if(gen) gen_legal_moves(move_list,board);
+ for(i=0; i<list_size(move_list); i++){
+ if(gen) move_list->value[i] = 0;
+ move_to_san(move_list->move[i],board,move_string,256);
+ printf(" %s%6s\n", move_list->value[i]? "* " : "", move_string);
+ }
+ // this is necessary by the xboard protocol
+ printf("\n");
}
+ } else if (match(string,"exclude *") || match(string,"option Polyglot exclude move=*")) { // [HGM]
+
+ int i, all = !strcmp(Star[0], "all"), change=FALSE, cnt=0;
+ game_get_board(Game,board);
+ if(!list_size(move_list)) {
+ gen_legal_moves(move_list,board);
+ for(i=0; i<list_size(move_list); i++){
+ move_list->value[i] = 0;
+ }
+ }
+ move = move_from_san(Star[0],board);
+
+ for(i=0; i<list_size(move_list); i++){
+ if(all || move_list->move[i] == move)
+ change |= !move_list->value[i], move_list->value[i] = 1;
+ cnt += !move_list->value[i];
+ }
+ if(change && cnt) mess(); // do not relay to engine if no change or no moves left
+
+ } else if (match(string,"include *")) { // [HGM]
+
+ int i, all = !strcmp(Star[0], "all"), change = FALSE;
+ game_get_board(Game,board);
+ move = move_from_san(Star[0],board);
+
+ for(i=0; i<list_size(move_list); i++){
+ if(all || move_list->move[i] == move)
+ change |= move_list->value[i], move_list->value[i] = 0;
+ }
+ if(change) mess();
+
} else if (match(string,"black")) {
if (colour_is_black(game_turn(Game))) {
if(option_find(Uci->option,"UCI_DrawOffers")){
my_log("POLYGLOT draw from XB received");
uci_send_option(Uci,"DrawOffer","%s","draw");}
+ else if (option_get_bool(Option,"HandleDraws") && Uci->root_move_nb > 20) { // [HGM] PG draw handling
+ my_log("POLYGLOT draw from XB received");
+ if (Uci->best_score <= -option_get_int(Option,"ContemptScore"))
+ gui_send(GUI,"offer draw");}
} else if (match(string,"easy")) {
XB->ponder = FALSE;
game_clear(Game);
+ move_list->size = 0; // [HGM] clear all exclude moves
+
if (XB->analyse) {
State->computer[White] = FALSE;
State->computer[Black] = FALSE;
} else {
State->computer[White] = FALSE;
State->computer[Black] = TRUE;
+ State->playedAllMoves[White] = TRUE; // [HGM]
+ State->playedAllMoves[Black] = TRUE;
}
XB->new_hack = TRUE;
if (!game_init(Game,Star[0])) my_fatal("xboard_step(): bad FEN \"%s\"\n",Star[0]);
+ move_list->size = 0; // [HGM] clear all exclude moves
+
State->computer[White] = FALSE;
State->computer[Black] = FALSE;
} else if (match(string,"undo")) {
+ move_list->size = 0; // [HGM] clear all exclude moves
+
if (game_pos(Game) >= 1) {
game_goto(Game,game_pos(Game)-1);
} else if (match(string,"usermove *")) {
+ move_list->size = 0; // [HGM] clear all exclude moves
+
game_get_board(Game,board);
move = move_from_san(Star[0],board);
ASSERT(!XB->result);
XB->result = FALSE;
+ // [HGM] externally supplied move means we did not fully play the current stm
+ State->playedAllMoves[colour_is_white(game_turn(Game)) ? White : Black] = FALSE;
+
move_step(move);
no_mess(move);
}
}
+// disarm() // [HGM] cleanse a string of offending double-quotes
+
+static char*disarm(const char *s){
+ static char buf[25];
+ char *p = buf, *q;
+ strncpy(buf, s, 24);
+ q = buf + strlen(buf) - 1;
+ while(*q == '"') *q-- = '\0'; // strip trailing quotes
+ while(*p == '"') p++; // strip leading quotes
+ while((q = strchr(p, '"'))) *q = '\''; // replace internal quotes
+ return p;
+}
+
// send_xboard_options()
static void send_xboard_options(){
gui_send(GUI,"feature done=0");
gui_send(GUI,"feature analyze=1");
+ gui_send(GUI,"feature exclude=1");
gui_send(GUI,"feature colors=0");
gui_send(GUI,"feature draw=1");
gui_send(GUI,"feature ics=1");
gui_send(GUI,"feature myname=\"%s\"",
- option_get_string(Option,"EngineName"));
+ disarm(option_get_string(Option,"EngineName")));
gui_send(GUI,"feature name=1");
gui_send(GUI,"feature pause=0");
gui_send(GUI,"feature ping=1");
}
+ gui_send(GUI,"feature option=\"Polyglot exclude move -string \"");
+
option_start_iter(Option);
while((opt=option_next(Option))){
if(opt->mode &XBOARD){
my_log("POLYGLOT %d move%s with resign score\n",State->resign_nb,(State->resign_nb>1)?"s":"");
if (State->resign_nb >= option_get_int(Option,"ResignMoves")) {
- my_log("POLYGLOT *** RESIGN ***\n");
- gui_send(GUI,"resign");
+ if (!option_get_bool(Option,"QueenNeverResigns") || !board_has_queen(board, board->turn)) { // [HGM] suppress resignig with Queen
+ my_log("POLYGLOT *** RESIGN ***\n");
+ gui_send(GUI,"resign");
+ }
}
} else {
engine_send(Engine,""); // newline
} else if (State->state == ANALYSE) {
-
- engine_send(Engine,"go infinite");
+ int i;
+ char move_string[256];
+
+ engine_send_queue(Engine,"go infinite");
+
+ if(list_size(move_list)) {
+ board_t board[1];
+ game_get_board(Game,board);
+ engine_send_queue(Engine," searchmoves");
+ for(i=0; i<list_size(move_list); i++) {
+ if(!move_list->value[i]) {
+ move_to_can(move_list->move[i],board,move_string,256);
+ engine_send_queue(Engine," %s",move_string);
+ }
+ }
+ }
+ engine_send(Engine,""); // newline
} else {
ASSERT(result>=-1&&result<=+1);
ASSERT(XB->result);
- ASSERT(State->computer[White]||State->computer[Black]);
+// ASSERT(State->computer[White]||State->computer[Black]);
// init
pos = 0;
- if (FALSE) {
- } else if (State->computer[White]) {
+ // [HGM] does not account for the hypothetical possibility we played both sides!
+ if (State->playedAllMoves[White]) {
pos = 0;
- } else if (State->computer[Black]) {
+ } else if (State->playedAllMoves[Black]) {
pos = 1;
result = -result;
} else {
- my_fatal("learn(): unknown side\n");
+ return; // [HGM] if we did not play all moves for some side, do not learn, but don't make a fuss!
}
if (FALSE) {