int chc_iskfk(board_t board) { rc_t from, to; findking(board, 0, &to); findking(board, 1, &from); if(from.c == to.c && between(board, from, to, 0) == 0) return 1; return 0; }
int chc_ischeck(board_t board, int turn) { rc_t from, to; findking(board, turn, &to); for(from.r = 0;from.r < BRD_ROW; from.r++) for(from.c = 0; from.c < BRD_COL; from.c++) if(board[from.r][from.c] && CHE_O(board[from.r][from.c]) != turn) if(chc_canmove(board, from, to)) return 1; return 0; }
Device long thinkiterate_fast(struct board *_board, int DEEP, int verbose, long Alpha, long Beta, int AllowCutoff) { int i=0, r=0, PersistentBufferOnline=0; int enemy_score=0, machine_score=0; int ABcutoff = 0; long score=-INFINITE; struct movelist moves; int PLAYER = _board->whoplays; legal_moves(_board, &moves, PLAYER, 0); searchNODEcount++; //If in checkmate/stalemate situation; if (!moves.k) { if (ifsquare_attacked(_board->squares, findking(_board->squares, 'Y', PLAYER), findking(_board->squares, 'X', PLAYER), PLAYER, 0)) { score = -13000 + 50*(BRAIN.DEEP-DEEP); //if (PLAYER != Machineplays) flip(score); } else score = 0; return score; } //IFnotGPU( Vb show_board(_board->squares); ) if (DEEP>0) { reorder_movelist(&moves); //NULL MOVE: guaranteed as long as if PL is not in check, //and its not K+P endgame. //if(DEEP > BRAIN.DEEP - 2) /* if(canNullMove(DEEP, _board, moves.k, PLAYER)) { flip(_board->whoplays); DisposableBuffer = thinkiterate(_board, DEEP-1, verbose, -Beta, -Alpha, AllowCutoff); invert(DisposableBuffer->score); flip(_board->whoplays); if (DisposableBuffer->score > Alpha) Alpha = DisposableBuffer->score; DUMP(DisposableBuffer); }*/ // Movelist iteration. for(i=0;i<moves.k;i++) { move_pc(_board, &moves.movements[i]); moves.movements[i].score = -thinkiterate_fast(_board, DEEP-1, verbose, -Beta, -Alpha, AllowCutoff); if (moves.movements[i].score > score) score = moves.movements[i].score; if (moves.movements[i].score > Alpha) Alpha = moves.movements[i].score; undo_move(_board, &moves.movements[i]); if (Beta<=Alpha && AllowCutoff) break; } return score; } else { machine_score = evaluate(_board, &moves, PLAYER, PLAYER); enemy_score = evaluate(_board, &moves, 1-PLAYER, PLAYER) * ( 1+BRAIN.presumeOPPaggro); score = machine_score - enemy_score; //if (PLAYER != Machineplays) invert(score); return score; } }