commit e861582a1bd04c63bd30253a0fbfc8c97f15162e
parent efb266c91585d3dcfe9ade481bc13199b9508418
Author: Dimitrije Dobrota <mail@dimitrijedobrota.com>
Date: Fri, 11 Aug 2023 15:02:48 +0200
Fix the bug!
Diffstat:
5 files changed, 28 insertions(+), 24 deletions(-)
diff --git a/src/board/zobrist.cpp b/src/board/zobrist.cpp
@@ -5,7 +5,7 @@
U64 castle_keys[16];
U64 enpassant_keys[64];
-U64 piece_keys[16][64];
+U64 piece_keys[12][64];
U64 side_key;
U64 zobrist_key_side(void) { return side_key; }
@@ -56,7 +56,7 @@ U64 zobrist_hash(const Board &board) {
}
const piece::Piece &piece_black = piece::get(type, Color::BLACK);
- int piece_black_index = piece_white.index;
+ int piece_black_index = piece_black.index;
U64 bitboard_black = board.get_bitboard_piece(piece_black);
bitboard_for_each_bit(square, bitboard_black) {
diff --git a/src/include/moves.hpp b/src/include/moves.hpp
@@ -4,6 +4,7 @@
#include "board.hpp"
#include "piece.hpp"
+#include <iostream>
#include <vector>
struct Move {
@@ -17,6 +18,8 @@ struct Move {
bool castle : 1;
bool capture : 1;
bool promote : 1;
+
+ friend std::ostream &operator<<(std::ostream &os, const Move &Move);
};
struct MoveE {
@@ -31,7 +34,6 @@ std::vector<MoveE> move_list_generate(const Board &board);
int move_make(Move move, Board &board, int flag);
void move_list_sort(std::vector<MoveE> &list);
int move_cmp(Move a, Move b);
-void move_print(Move move);
#define move_source(move) (move.source)
#define move_target(move) (move.target)
diff --git a/src/moves/moves.cpp b/src/moves/moves.cpp
@@ -2,7 +2,7 @@
#include "utils_cpp.hpp"
#include <algorithm>
-#include <cstdio>
+#include <iomanip>
int move_cmp(Move a, Move b) { return *(uint32_t *)&a == *(uint32_t *)&b; }
@@ -23,18 +23,6 @@ Move move_encode(uint8_t src, uint8_t tgt, const piece::Piece *piece,
};
}
-void move_print(Move move) {
- printf("%5s %5s %2c %2c %2c %4d %4d %4d %4d %4d\n",
- square_to_coordinates(static_cast<Square>(move_source(move))),
- square_to_coordinates(static_cast<Square>(move_target(move))),
- move_piece(move).code,
- move_capture(move) ? move_piece_capture(move).code : '.',
- move_promote(move) ? move_piece_promote(move).code : '.',
- move_double(move) ? 1 : 0, move_enpassant(move) ? 1 : 0,
- move_castle(move) ? 1 : 0, move_capture(move) ? 1 : 0,
- move_promote(move) ? 1 : 0);
-}
-
void move_list_sort(std::vector<MoveE> &list) {
std::sort(list.begin(), list.end(),
[](const MoveE &a, const MoveE &b) { return a.score < b.score; });
@@ -44,7 +32,20 @@ void move_list_print(const std::vector<MoveE> &list) {
printf("Score From To Pi Cap Prmt Dbl Enp Cst C P\n");
for (const MoveE &move : list) {
printf("%5d: ", move.score);
- move_print(move.move);
+ // move_print(move.move);
}
printf("Total: %lu\n", list.size());
}
+
+std::ostream &operator<<(std::ostream &os, const Move &move) {
+ os << square_to_coordinates(static_cast<Square>(move_source(move))) << " ";
+ os << square_to_coordinates(static_cast<Square>(move_target(move))) << " ";
+ os << move_piece(move).code << " ";
+ os << (move_capture(move) ? move_piece_capture(move).code : '.') << " ";
+ os << (move_promote(move) ? move_piece_promote(move).code : '.') << " ";
+ os << move_double(move) << " ";
+ os << move_enpassant(move) << " ";
+ os << move_castle(move);
+
+ return os;
+}
diff --git a/src/moves/moves_make.cpp b/src/moves/moves_make.cpp
@@ -68,16 +68,18 @@ int move_make(Move move, Board &board, int flag) {
board.set_enpassant(move_double(move) ? ntarget : Square::no_sq);
if (move_castle(move)) {
- static const piece::Piece &rook =
- piece::get(piece::Type::ROOK, board.get_side());
+ static constexpr const piece::Piece &rook_white =
+ piece::get(piece::Type::ROOK, Color::WHITE);
+ static constexpr const piece::Piece &rook_black =
+ piece::get(piece::Type::ROOK, Color::BLACK);
if (target == Square::g1)
- _piece_move(board, rook, Square::h1, Square::f1);
+ _piece_move(board, rook_white, Square::h1, Square::f1);
if (target == Square::c1)
- _piece_move(board, rook, Square::a1, Square::d1);
+ _piece_move(board, rook_white, Square::a1, Square::d1);
if (target == Square::g8)
- _piece_move(board, rook, Square::h8, Square::f8);
+ _piece_move(board, rook_black, Square::h8, Square::f8);
if (target == Square::c8)
- _piece_move(board, rook, Square::a8, Square::d8);
+ _piece_move(board, rook_black, Square::a8, Square::d8);
}
board.xor_hash(zobrist_key_castle(board.get_castle()));
diff --git a/src/perft/perft.cpp b/src/perft/perft.cpp
@@ -139,7 +139,6 @@ PerftResult perft_test(const char *fen, int depth, int thread_num) {
}
int main(int argc, char *argv[]) {
-
int c, depth = 1, thread_num = 1;
std::string s(tricky_position);
const char *fen = s.data();