void cmd_inspect(char *s) { int i; output("\tPawns : "); output("W : "); for (i=1;i<9;i++) output("%d",board->pawns[0][i]); output(" B : "); for (i=1;i<9;i++) output("%d",board->pawns[1][i]); output("\n"); output("\tFlags : %s\n", formatflags()); if (ply) { undo u = undostack[ply-1]; int v = board->flags; board->flags = u.flags; output("\tprevious move : %c took %c = %s : %s\n", rep(u.moved), rep(u.captured), movestring(u.m), formatflags()); board->flags = v; } if (fullincheckp(tomove())) { output("\tYou are currently in check : %d\n", fullincheckp(tomove())); } }
void cmd_game(char *s) { int i; for(i=0;i<ply;i++) { char *s = movestring(gamestack[i]); if (i%2==0) printf("\tW %2d %s\t", (i+1)/2+1, s); else printf("\tB %2d %s\n", i/2+1, s); } if (ply%2==1) printf("\n"); }
void cmd_attacks(char *s) { move_and_score *restore_sp = move_sp; genattacks(); if (move_sp>restore_sp) { while (move_sp>restore_sp) { move m = popmove(); printf("%8.8lx - %8lu - %s\n", (unsigned long)m, (unsigned long)m,movestring(m)); } } else printf("\tno available attacks\n"); }
void save_leaf(move *pv, int n, int value, int hashed) { #ifndef LEARNING return; #else int s_ply = ply; int searched_value = -1; int stored_board_value = -1; if (tomove() != WHITE) value = -value; stored.search_results[stored.index] = value; /* first check our stored position */ if (stored.boards[stored.index]->piececount[0]>0) { chessboard *temp_board = board; board = stored.boards[stored.index]; countmaterial(); stored_board_value = eval_for_white(); board = temp_board; countmaterial(); if (((stored_board_value > (value - EVAL_INTERVAL)) && (stored_board_value < (value + EVAL_INTERVAL))) || (value > WIN - 50) || (value < LOSE + 50)) { stored.usable[stored.index] = 1; stored.actual[stored.index] = stored_board_value; printf("STORING: qsearch board = %d\n", stored_board_value); } } /* then check to see if our value is the same as our last search */ if (!stored.usable[stored.index]) { if ((stored.search_results[stored.index] == stored.search_results[stored.index-1])) { memcpy(stored.boards[stored.index], stored.boards[stored.index-1], sizeof(chessboard)); stored.usable[stored.index] = 1; stored.actual[stored.index] = stored.actual[stored.index]-1; printf("STORING: previous board = %d\n", stored.search_results[stored.index-1]); } } /* lastly check to see if our pv leads to a correct board eval */ if (!stored.usable[stored.index]) { int i; printf("pv: "); for (i=0;i<n;i++) { if (pv[i] == dummymove) break; domove(pv[i]); printf("%s ", movestring(pv[i])); } printf("\n"); searched_value = eval_for_white(); if ((searched_value > value - EVAL_INTERVAL)&& (searched_value < value + EVAL_INTERVAL)) { memcpy(stored.boards[stored.index], board, sizeof(chessboard)); stored.usable[stored.index] = 1; stored.actual[stored.index] = searched_value; printf("STORING: pv board = %d\n", searched_value); } else { printf("!usable: stored_position %d, " "searched %d, previous %d, stored %d\n", stored_board_value, searched_value, stored.search_results[stored.index-1], value); } while (ply>s_ply) undomove(); } #endif }
void cmd_suggest(char *s){printf("Hint: %s\n", movestring(bce()));}
/* returns -1 for stalemate or winner's color */ int playchess() { int use_pondering = 0; printboard_and_time(); for (;;) { long starttime, endtime; move m; int g; g = gameoverp(tomove()); if (g) { switch (g) { case END_CHECKMATE: if (tomove() == BLACK) { return end(WHITE, "white mates"); } else { return end(BLACK, "black mates"); } case END_STALEMATE: return end(-1, "stalemate"); case NON_MATERIAL: return end(-1, "insufficient material"); case REP_DRAW: if (!robo_mode) { printf("drawable position\n"); } if (computer[WHITE]||computer[BLACK]) { if (robo_mode) tellics("draw\n"); return end(-1, "draw by repetition of moves"); } break; } } starttime = get_ms(); if (computer[tomove()]) { m = bce(); if ((m!=dummymove)&&(validmove(m)==1)) { printf("move %s\n", movestring(m)); } else { if (robo_mode) { tellics("mailmoves\n"); tellics( "message madhacker valid? = %d, move = %s, wouldbeincheckp() = %d, wouldbeinfullcheckp() = %d, pv = %s\n", validmove(m), movestring(m), wouldbeincheckp(m), wouldbeincheckfullp(m), thoughts); tellics("abort\n"); } else { printf("BCE returned invalid move: %s\n", movestring(m)); printf("valid? = %d\n", validmove(m)); fprintf(stdout, "random seed = %ld\n", seed); fprintf(stdout, "hash = %lld\n", board->hash); fprintf(stdout, "draw? = %d g = %d\n", draw_by_rep(), g); computer[1] = computer[0] = 0; } } use_pondering = 1; } else { if ((ponder_mode && computer[opp(tomove())])&& use_pondering) { ponder(); use_pondering = 0; } m = usermove(); use_pondering = 0; } endtime = get_ms(); chessclock[tomove()] -= (endtime-starttime); chessclock[tomove()] += clockinc; if (m) { domove(m); update_state(m); printboard_and_time(); } } }