void PerftTest(int depth, S_BOARD *pos) { S_MOVELIST list[1]; int move; int MoveNum = 0; int start = GetTimeMs(); long cumnodes, oldnodes; ASSERT(CheckBoard(pos)); PrintBoard(pos); printf("\nStarting Test To Depth:%d\n", depth); leafNodes = 0; GenerateAllMoves(pos, list); for(MoveNum = 0; MoveNum < list->count; ++MoveNum) { move = list->moves[MoveNum].move; if(!MakeMove(pos, move)) continue; cumnodes = leafNodes; Perft(depth - 1, pos); TakeMove(pos); oldnodes = leafNodes - cumnodes; printf("move %d : %s : %ld\n", MoveNum + 1, PrMove(move), oldnodes); } printf("\nTest Complete : %ld nodes visited in %dms\n", leafNodes, GetTimeMs() - start); }
int MoveExists(S_BOARD *pos, const int move) { int MoveNum = 0; S_MOVELIST list[1]; GenerateAllMoves(pos, list); for(MoveNum = 0; MoveNum < list->count; ++MoveNum) { if(!MakeMove(pos, list->moves[MoveNum].move)) { continue; } TakeMove(pos); if(list->moves[MoveNum].move == move) { return TRUE; } } return FALSE; }
int ParseMove(char *ptrChar, CHESS_BOARD *pos) { ASSERT(CheckBoard(pos)); if (ptrChar[1] > '8' || ptrChar[1] < '1') return NOMOVE; if (ptrChar[3] > '8' || ptrChar[3] < '1') return NOMOVE; if (ptrChar[0] > 'h' || ptrChar[0] < 'a') return NOMOVE; if (ptrChar[2] > 'h' || ptrChar[2] < 'a') return NOMOVE; int from = FR2SQ(ptrChar[0] - 'a', ptrChar[1] - '1'); int to = FR2SQ(ptrChar[2] - 'a', ptrChar[3] - '1'); ASSERT(SqOnBoard(from) && SqOnBoard(to)); MOVELIST list[1]; GenerateAllMoves(pos, list); int MoveNum = 0; int Move = 0; int PromPce = EMPTY; for (MoveNum = 0; MoveNum < list->count; ++MoveNum) { Move = list->moves[MoveNum].move; if (FROMSQ(Move) == from && TOSQ(Move) == to) { PromPce = PROMOTED(Move); if (PromPce != EMPTY) { if (IsRQ(PromPce) && !IsBQ(PromPce) && ptrChar[4] == 'r') { return Move; } else if (!IsRQ(PromPce) && IsBQ(PromPce) && ptrChar[4] == 'b') { return Move; } else if (IsRQ(PromPce) && IsBQ(PromPce) && ptrChar[4] == 'q') { return Move; } else if (IsKn(PromPce) && ptrChar[4] == 'n') { return Move; } continue; } return Move; } } return NOMOVE; }
U64 Perft(int depth, S_BOARD *pos) { ASSERT(checkBoard(pos)); S_MOVELIST list[1]; GenerateAllMoves(pos, list); if(depth == 0) { return 1; } U64 nodes = ZERO64; int i; for (i = 0; i < list->count; i++) { if (MakeMove(pos, list->moves[i].move)) { nodes += Perft(depth - 1, pos); TakeMove(pos); } } return nodes; }
void Perft(int depth, S_BOARD *pos) { S_MOVELIST list[1]; int MoveNum = 0; ASSERT(CheckBoard(pos)); if(depth == 0) { leafNodes++; return; } GenerateAllMoves(pos, list); for(MoveNum = 0; MoveNum < list->count; ++MoveNum) { if(!MakeMove(pos, list->moves[MoveNum].move)) { continue; } Perft(depth - 1, pos); TakeMove(pos); } return; }