void printPosition(Position *pos){ char chars[64]; int p, n, r, c; for (n = 0; n < 64; n++){ chars[n] = ' '; } for (p = 0; p < 12; p++) { int sq; bitboard b = pos->bits[p]; while ((sq = popBit(&b)) != NO_SQUARE) { chars[sq] = getSymbol(p); } } /* en passant square if (pos->enpas != NO_SQUARE) { chars[pos->enpas] = 'x'; } */ //printf("%.8s\n%.8s\n%.8s\n%.8s\n%.8s\n%.8s\n%.8s\n%.8s\n", &chars[56], &chars[48], &chars[40], &chars[32], &chars[24], &chars[16], &chars[8], &chars[0]); for (r = 7; r >= 0; r--) { for (c = 0; c < 8; c++) { int at = 1, fg = 31, bg; if (r%2 == c%2) { bg = 45; } else { bg = 47; } //fg = 77 - bg; printf("%c[%d;%d;%dm",27,at,fg,bg); printf("%c ", chars[8*r + c]); } printf("%c[0m", 27); printf("\n"); } //printf("%llx\n", pos->hash); }
int checkBoard(const board& b){ int temp_numPieces[13] = {0,0,0,0,0,0,0,0,0,0,0,0,0}; int temp_numMinorPieces[2] = {0,0}; int temp_numMajorPieces[2] = {0,0}; int temp_numBigPieces[2] = {0,0}; int temp_materialValue[2] = {0,0}; U64 temp_pawns[3] = {0ULL, 0ULL, 0ULL}; temp_pawns[WHITE] = b.pawns[WHITE]; temp_pawns[BLACK] = b.pawns[BLACK]; temp_pawns[BOTH] = b.pawns[BOTH]; int sq120, color, pcount, tempPiece; for (int i = wP; i <= bK; ++i){ for (int j = 0; j < b.numPieces[i]; ++j){ sq120 = b.pieceList[i][j]; if (b.pieces[sq120] != i) throw pieceListException(); } } for (int i = 0; i < 64; ++i){ sq120 = SQ64[i]; tempPiece = b.pieces[sq120]; temp_numPieces[tempPiece]++; color = pieceColor[tempPiece]; if (isBig[tempPiece]) temp_numBigPieces[color]++; if (isMinor[tempPiece]) { temp_numMinorPieces[color]++; } if (isMajor[tempPiece]) temp_numMajorPieces[color]++; temp_materialValue[color] += pieceValue[tempPiece]; } for (int i = wP; i<= bK; ++i){ if (temp_numPieces[i] != b.numPieces[i]){ throw pieceListException(); } } pcount = countBits(temp_pawns[WHITE]); if (pcount != b.numPieces[wP]) throw pieceListException(); pcount = countBits(temp_pawns[BLACK]); if (pcount != b.numPieces[bP]) throw pieceListException(); pcount = countBits(temp_pawns[BOTH]); if (pcount != (b.numPieces[wP] + b.numPieces[bP])) { std::cout << "Piece count: " << pcount << " White: " << b.numPieces[wP] << " Black: " << b.numPieces[bP] << " Total: " << (b.numPieces[wP] + b.numPieces[bP]) << std::endl; throw pieceListException(); } while (temp_pawns[WHITE]){ int sq = popBit(&temp_pawns[WHITE]); if (b.pieces[SQ64[sq]] != wP) throw pieceListException(); } while (temp_pawns[BLACK]){ int sq = popBit(&temp_pawns[BLACK]); if (b.pieces[SQ64[sq]] != bP) throw pieceListException(); } while (temp_pawns[BOTH]){ int sq = popBit(&temp_pawns[BOTH]); if (b.pieces[SQ64[sq]] != bP && b.pieces[SQ64[sq]] != wP){ throw pieceListException(); } } if (temp_materialValue[WHITE] != b.materialValue[WHITE] || temp_materialValue[BLACK] != b.materialValue[BLACK]){ std::cout << "TmpWhite: " << std::dec <<temp_materialValue[WHITE] << " White: " << std::dec <<b.materialValue[WHITE] << std::endl; std::cout << "Tmpblack: " << std::dec << temp_materialValue[BLACK] << " black: " <<std::dec << b.materialValue[BLACK] << std::endl; throw pieceListException(); } if (temp_numMajorPieces[WHITE] != b.numMajorPieces[WHITE] || temp_numMajorPieces[BLACK] != b.numMajorPieces[BLACK]){ throw pieceListException(); } if (temp_numMinorPieces[WHITE] != b.numMinorPieces[WHITE] || temp_numMinorPieces[BLACK] != b.numMinorPieces[BLACK]){ std::cout << "TmpWhite: " << std::dec << temp_numMinorPieces[WHITE] << " White: " << std::dec <<b.numMinorPieces[WHITE] << std::endl; std::cout << "Tmpblack: " << std::dec << temp_numMinorPieces[BLACK] << " black: " <<std::dec << b.numMinorPieces[BLACK] << std::endl; throw pieceListException(); } if (temp_numBigPieces[WHITE] != b.numBigPieces[WHITE] && temp_numBigPieces[BLACK] != b.numBigPieces[BLACK]){ throw pieceListException(); } if (generatePosKey(b) != b.posKey){ throw pieceListException(); } return 1; }
int validatePosition(Position *pos) { int p, n, squares[64], score = 0; bitboard occupied = 0, white = 0, black = 0; for (n = 0; n < 64; n++) { squares[n] = EMPTY; } for (p = WP; p <= BK; p++){ bitboard pbits; pbits = pos->bits[p]; if (occupied & pbits) { printf("Multiple pieces at a single square.\n"); return 0; } occupied |= pbits; if (p < BP) { white |= pbits; } else { black |= pbits; } score += VAL[p] * countBits(pbits); while (pbits) { squares[popBit(&pbits)] = p; } } //generate the rest of our bitboards: if (white != pos->bits[WHITE] || black != pos->bits[BLACK] || occupied != pos->bits[OCCUPIED] || ~occupied != pos->bits[EMPTY]) { printf("Incorrect derived bitboards.\n"); printf("white:\n"); printBitboard(pos->bits[WHITE]); printf("\nblack:\n"); printBitboard(pos->bits[BLACK]); printf("\noccupied:\n"); printBitboard(pos->bits[OCCUPIED]); printf("\nempty:\n"); printBitboard(pos->bits[EMPTY]); return 0; } if (score != pos->score) { printf("Incorrect score, expected: %d, actual: %d\n", score, pos->score); return 0; } for (n = 0; n < 64; n++) { if (squares[n] != pos->squares[n]) { printf("Incorrect piece buffer."); return 0; } } if (pos->ephash != EPHASH(pos)) { printf("Incorrect en passant hash code, expected: %llx, actual: %llx.\n", EPHASH(pos), pos->ephash); return 0; } if (pos->hash != hashPosition(pos)) { printf("Incorrect hash code, expected: %llx, actual: %llx.\n", hashPosition(pos), pos->hash); return 0; } return 1; }