Compare commits

...

53 Commits

Author SHA1 Message Date
Karma Riuk
c55645ad73 using global peft
Some checks failed
pre-release / Pre Release (push) Waiting to run
tagged-release / Tagged Release (push) Has been cancelled
2025-02-04 21:53:07 +01:00
Karma Riuk
1b0af3b486 annotated each depths with its time (to then
compare with the different optimizations)
2025-02-04 21:52:07 +01:00
Karma Riuk
df20060075 added global peft 2025-02-04 21:51:58 +01:00
Karma Riuk
151a50fba9 made move str better (includes promotion) 2025-02-04 21:51:14 +01:00
Karma Riuk
609d5f8c98 fixed castle right rook capture coords 2025-02-04 21:50:43 +01:00
Karma Riuk
e9c96e83da fixed en passant offset 2025-02-04 21:50:30 +01:00
Karma Riuk
76310400e8 added empty line before move counts to ease copying 2025-02-03 23:41:27 +01:00
Karma Riuk
e5bb2d1a5f printing moves normally 2025-02-03 23:41:16 +01:00
Karma Riuk
4c86d5e815 fixed castling rights on capture 2025-02-03 23:40:30 +01:00
Karma Riuk
b1812f1df6 removed the inclusion of move in piece 2025-02-03 19:10:49 +01:00
Karma Riuk
9d21141d3c fixed pawn capture + promotion action 2025-02-03 19:10:07 +01:00
Karma Riuk
974af5d19f we can now print a move (stockfish stile) 2025-02-03 19:09:21 +01:00
Karma Riuk
df07b4399d minor fix 2025-02-03 19:09:13 +01:00
Karma Riuk
fa59784230 fixed castling rights that were not removed
properly
2025-02-03 19:08:26 +01:00
Karma Riuk
be34045f92 minor fix 2025-02-03 19:08:21 +01:00
Karma Riuk
4eaed699c0 fixed en passant capture 2025-02-03 16:26:31 +01:00
Karma Riuk
310abb0611 fixed slight mistake 2025-02-03 16:12:20 +01:00
Karma Riuk
b70ca5302a put back good code 2025-02-03 15:36:11 +01:00
Karma Riuk
83af5f0b97 removed problemaic code 2025-02-03 15:35:43 +01:00
Karma Riuk
72ba6a80ae made types behave 2025-02-03 15:35:03 +01:00
Karma Riuk
1723356f62 removed useless stuff 2025-02-03 15:34:52 +01:00
Karma Riuk
75adb4b1ba removed already existing variable 2025-02-03 15:34:12 +01:00
Karma Riuk
6951b860da forgot to push the normal moves for the pawn, fixed it now 2025-02-03 14:05:32 +01:00
Karma Riuk
805d9fa95c fixed implicit type casting (warning) 2025-02-03 14:05:16 +01:00
Karma Riuk
4df7cbf01a fixed piece recognition 2025-02-03 14:04:52 +01:00
Karma Riuk
00137e022a fixed move for position initial guard 2025-02-03 14:04:27 +01:00
Karma Riuk
570b8df4a7 fixed look_direction 2025-02-03 14:04:18 +01:00
Karma Riuk
9a66a71c38 handling better the output of perft 2025-02-03 13:59:33 +01:00
Karma Riuk
41e4119468 reordered members of enum 2025-02-03 13:51:43 +01:00
Karma Riuk
e7fc1b06de fixed the is_within_bounds check 2025-02-03 13:50:48 +01:00
Karma Riuk
5f79b81ce4 added validity check when creating coords from index 2025-02-03 13:50:34 +01:00
Karma Riuk
e5819ee83b minor fix 2025-02-03 13:50:15 +01:00
Karma Riuk
58109c5120 fixed condition 2025-02-03 13:49:40 +01:00
Karma Riuk
6478176a7d fixed check condition 2025-02-03 13:47:27 +01:00
Karma Riuk
ab088da33c removed useless this-> 2025-02-03 13:47:17 +01:00
Karma Riuk
31799cb0ec added optimization and warning flags to the compiler 2025-02-03 13:44:53 +01:00
Karma Riuk
96dcbc0a6c actually counting milliseconds now 2025-02-03 13:41:45 +01:00
Karma Riuk
ce06097063 i forgot to actually implement the root legal_moves haha 2025-02-03 01:12:30 +01:00
Karma Riuk
3fc2aa73ad actually counting milliseconds now 2025-02-03 01:06:07 +01:00
Karma Riuk
de6a03ce08 fixed mistake 2025-02-03 01:05:59 +01:00
Karma Riuk
dc3031ddc1 we can finally print pieces and colours properly 2025-02-03 01:05:37 +01:00
Karma Riuk
5e4b880aad checking perft to see if my cpp implementation is
correct
2025-02-03 00:33:12 +01:00
Karma Riuk
540ffa4fb3 fixed slight mistake 2025-02-03 00:33:04 +01:00
Karma Riuk
21136a26f0 implemented the last details to make everything
work (hopefully)
2025-02-03 00:08:37 +01:00
Karma Riuk
fa57dcfc30 apparently the default value of a paramter goes in
the declaration and not the defintion, i didn't know that
2025-02-03 00:08:13 +01:00
Karma Riuk
8da349579d make_move now checks castle rights after each move 2025-02-02 23:52:24 +01:00
Karma Riuk
f0467bc516 make_move now handles castling 2025-02-02 23:34:10 +01:00
Karma Riuk
a7cf8e0c21 make_move now handles the setting of en passant
targets
2025-02-02 23:33:52 +01:00
Karma Riuk
2128159914 make_move now handles promotion 2025-02-02 23:33:29 +01:00
Karma Riuk
c564add509 removed useless variable 2025-02-02 23:33:20 +01:00
Karma Riuk
31b0656332 fixed promotion missing colour 2025-02-02 23:16:53 +01:00
Karma Riuk
24165bb5bb made comment more accurate 2025-02-02 23:14:13 +01:00
Karma Riuk
4c8fdfa3b4 implemented en passant in legal moves 2025-02-02 23:13:37 +01:00
12 changed files with 444 additions and 40 deletions

View File

@ -1,3 +1,5 @@
CXXFLAGS += -O3 -Wall
# Add .d to Make's recognized suffixes.
SUFFIXES += .d

View File

@ -169,8 +169,6 @@ std::string Board::to_fen() const {
}
Board Board::make_move(Move move) const {
int8_t dest_piece = this->squares[move.target_square];
Board ret;
std::copy(
std::begin(this->squares),
@ -185,13 +183,89 @@ Board Board::make_move(Move move) const {
// -- Handle en passant target being eaten
if (move.en_passant)
ret.squares[move.target_square - 8] = Piece::None;
ret.squares[move.target_square + (white_to_play ? -8 : 8)] =
Piece::None;
// -- Handle promotion
if (move.promoting_to != Piece::None)
ret.squares[move.target_square] = move.promoting_to;
// -- Set en passant target if need
if ((squares[move.source_square] & 0b111) == Piece::Pawn
&& std::abs(move.target_square - move.source_square) == 16) {
if (white_to_play)
ret.en_passant_target = move.target_square - 8;
else
ret.en_passant_target = move.target_square + 8;
} else {
ret.en_passant_target = -1;
}
// -- Handle castling (just move the rook over)
Coords c = Coords::from_index(move.source_square);
if (move.castle_side & KingSide) {
Coords rook_source{7, c.y};
int8_t old_rook = ret.squares[rook_source.to_index()];
ret.squares[rook_source.to_index()] = Piece::None;
Coords rook_dest{5, c.y};
ret.squares[rook_dest.to_index()] = old_rook;
} else if (move.castle_side & QueenSide) {
Coords rook_source{0, c.y};
int8_t old_rook = ret.squares[rook_source.to_index()];
ret.squares[rook_source.to_index()] = Piece::None;
Coords rook_dest{3, c.y};
ret.squares[rook_dest.to_index()] = old_rook;
}
// -- Check for castling rights
ret.w_castle_rights = w_castle_rights;
ret.b_castle_rights = b_castle_rights;
if (white_to_play) {
if ((squares[move.source_square] & 0b111) == King)
ret.w_castle_rights = NeitherSide;
if ((squares[move.source_square] & 0b111) == Rook) {
if (c.x == 0 && (ret.w_castle_rights & QueenSide))
ret.w_castle_rights &= ~(QueenSide);
if (c.x == 7 && (ret.w_castle_rights & KingSide))
ret.w_castle_rights &= ~(KingSide);
}
Coords target = Coords::from_index(move.target_square);
if (move.is_capturing && target.y == 7
&& (squares[move.target_square] & 0b111) == Rook) {
if (target.x == 0 && (ret.b_castle_rights & QueenSide))
ret.b_castle_rights &= ~(QueenSide);
if (target.x == 7 && (ret.b_castle_rights & KingSide))
ret.b_castle_rights &= ~(KingSide);
}
} else {
if ((squares[move.source_square] & 0b111) == King)
ret.b_castle_rights = NeitherSide;
if ((squares[move.source_square] & 0b111) == Rook) {
if (c.x == 0 && (ret.b_castle_rights & QueenSide))
ret.b_castle_rights &= ~(QueenSide);
if (c.x == 7 && (ret.b_castle_rights & KingSide))
ret.b_castle_rights &= ~(KingSide);
}
Coords target = Coords::from_index(move.target_square);
if (move.is_capturing && target.y == 0
&& (squares[move.target_square] & 0b111) == Rook) {
if (target.x == 0 && (ret.w_castle_rights & QueenSide))
ret.w_castle_rights &= ~(QueenSide);
if (target.x == 7 && (ret.w_castle_rights & KingSide))
ret.w_castle_rights &= ~(KingSide);
}
}
return ret;
}
int8_t Board::get_king_of(int8_t colour) const {
for (int i = 0; i < 64; i++)
if (this->squares[i] == (colour | Piece::King))
if (squares[i] == (colour | Piece::King))
return i;
throw std::domain_error(
"Apparently there no kings of the such color in this board"
@ -208,13 +282,57 @@ std::vector<int8_t> to_target_square(std::vector<Move> moves) {
bool Board::is_check_for(int8_t colour) const {
int8_t king_idx = this->get_king_of(colour);
for (int i = 0; i < 64; i++) {
if (this->squares[i] == Piece::None)
if (this->squares[i] == Piece::None || colour_at(i) == colour)
continue;
std::vector<Move> moves =
legal_moves(this->squares[i], *this, Coords::from_index(i), true);
std::vector<int8_t> targets = to_target_square(moves);
if (std::find(targets.begin(), targets.end(), i) != targets.end())
std::vector<int8_t> targets;
if ((squares[i] & 0b00111) == King) {
// special case for the king, because it creates infinite recursion
// (since he looks if he's walking into a check)
Coords king_pos = Coords::from_index(i);
for (int dx = -1; dx <= 1; dx++) {
for (int dy = -1; dy <= 1; dy++) {
Coords c{king_pos.x + dx, king_pos.y + dy};
if (c.is_within_bounds())
targets.push_back(c.to_index());
}
}
} else {
std::vector<Move> moves = legal_moves(
this->squares[i],
*this,
Coords::from_index(i),
true
);
targets = to_target_square(moves);
}
if (std::find(targets.begin(), targets.end(), king_idx)
!= targets.end())
return true;
}
return false;
}
bool Board::no_legal_moves_for(int8_t colour) const {
for (int i = 0; i < 64; i++) {
if (colour_at(i) == colour) {
std::vector<Move> moves =
legal_moves(squares[i], *this, Coords::from_index(i));
if (moves.size() > 0)
return false;
}
}
return true;
}
std::vector<Move> Board::all_legal_moves() const {
std::vector<Move> ret;
for (int i = 0; i < 64; i++) {
if ((colour_at(i) == White && white_to_play)
|| (colour_at(i) == Black && !white_to_play)) {
std::vector<Move> moves =
legal_moves(squares[i], *this, Coords::from_index(i));
ret.insert(ret.end(), moves.begin(), moves.end());
}
}
return ret;
}

View File

@ -8,7 +8,8 @@
struct Board {
private:
int8_t get_king_of(int8_t colour) const;
int8_t get_king_of(int8_t) const;
bool no_legal_moves_for(int8_t) const;
public:
int8_t squares[64] = {Piece::None};
@ -25,6 +26,21 @@ struct Board {
std::string to_fen() const;
bool is_check_for(int8_t) const;
std::vector<Move> all_legal_moves() const;
bool is_checkmate_for(int8_t colour) const {
return is_check_for(colour) && no_legal_moves_for(colour);
}
bool is_stalemate_for(int8_t colour) const {
return !is_check_for(colour) && no_legal_moves_for(colour);
}
bool is_terminal() const {
return is_checkmate_for(White) || is_checkmate_for(Black)
|| is_stalemate_for(White) || is_stalemate_for(Black);
}
int8_t colour_at(int8_t idx) const {
return squares[idx] & 0b11000;
}

View File

@ -18,6 +18,8 @@ struct Coords {
}
static Coords from_index(int idx) {
if (idx < 0 || idx > 63)
throw std::invalid_argument("The index is outside the board...");
return {idx % 8, idx / 8};
}
@ -27,17 +29,17 @@ struct Coords {
"An algebraic coordinate should only have two characters"
);
int x = _FILES.find(pos[0]);
size_t x = _FILES.find(pos[0]);
if (x == std::string::npos)
throw std::invalid_argument("The first character of the given "
"algebraic coordinate is invalid");
int y = _RANKS.find(pos[1]);
size_t y = _RANKS.find(pos[1]);
if (y == std::string::npos)
throw std::invalid_argument("The second character of the given "
"algebraic coordinate is invalid");
return Coords{x, y};
return Coords{(int) x, (int) y};
}
std::string to_algebraic() const {
@ -52,7 +54,7 @@ struct Coords {
}
bool is_within_bounds() const {
return this->to_index() < 64;
return 0 <= x && x < 8 && 0 <= y && y < 8;
}
};

View File

@ -1,11 +1,12 @@
#include "board.hpp"
#include "stickfosh.hpp"
#include <iostream>
int main(int argc, char* argv[]) {
std::string pos =
"rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1";
Board b = Board::setup_fen_position(pos);
sizeof(b);
"r2q1rk1/pP1p2pp/Q4n2/bbp1p3/Np6/1B3NBn/pPPP1PPP/R3K2R b KQ - 0 5";
// Board b = Board::setup_fen_position(pos);
perft();
return 0;
}

View File

@ -1,8 +1,11 @@
#pragma once
#include "castle_side.hpp"
#include "coords.hpp"
#include "pieces/piece.hpp"
#include <cstdint>
#include <sstream>
struct Move {
int8_t source_square;
@ -11,5 +14,35 @@ struct Move {
bool is_capturing = false;
CastleSide castle_side = CastleSide::NeitherSide;
bool en_passant = false;
int8_t promoting_to = 0;
int8_t promoting_to = Piece::None;
std::string to_string() const {
std::stringstream ss;
ss << Coords::from_index(source_square)
<< Coords::from_index(target_square);
if (promoting_to != Piece::None) {
switch (promoting_to & 0b00111) {
case Queen:
ss << 'q';
break;
case Bishop:
ss << 'b';
break;
case Knigt:
ss << 'n';
break;
case Rook:
ss << 'r';
break;
default:
break;
}
}
return ss.str();
}
};
inline std::ostream& operator<<(std::ostream& os, const Move& m) {
os << m.to_string();
return os;
}

View File

@ -46,7 +46,7 @@ std::vector<Move> king_moves(const Board& b, const Coords xy) {
}
if (b.is_check_for(b.colour_at(xy)))
return ret;
return keep_only_blocking(ret, b);
// -- Castles
int8_t castling_rights = b.colour_at(xy) == Colour::White

View File

@ -14,7 +14,18 @@ std::vector<Move> pawn_moves(const Board& b, const Coords xy) {
int8_t capturable_piece = b.squares[left.to_index()];
if (capturable_piece != 0) {
if (my_colour != b.colour_at(left))
ret.push_back(Move{xy.to_index(), left.to_index()});
if ((my_colour == White && left.y == 7)
|| (my_colour == Black && left.y == 0))
for (auto piece : {Rook, Knigt, Bishop, Queen})
ret.push_back(Move{
xy.to_index(),
left.to_index(),
.is_capturing = true,
.promoting_to = (int8_t) (my_colour | piece)
});
else
ret.push_back(Move{xy.to_index(), left.to_index()});
}
}
@ -25,11 +36,36 @@ std::vector<Move> pawn_moves(const Board& b, const Coords xy) {
int8_t capturable_piece = b.squares[right.to_index()];
if (capturable_piece != 0) {
if (my_colour != b.colour_at(right))
ret.push_back(Move{xy.to_index(), right.to_index()});
if ((my_colour == White && right.y == 7)
|| (my_colour == Black && right.y == 0))
for (auto piece : {Rook, Knigt, Bishop, Queen})
ret.push_back(Move{
xy.to_index(),
right.to_index(),
.is_capturing = true,
.promoting_to = (int8_t) (my_colour | piece)
});
else
ret.push_back(Move{xy.to_index(), right.to_index()});
}
}
// -- Promotion
// -- Capture en passant
if (b.en_passant_target != -1) {
Coords c = Coords::from_index(b.en_passant_target);
int dy = my_colour == Colour::White ? 1 : -1;
if (c.y == xy.y + dy && (c.x == xy.x - 1 || c.x == xy.x + 1)) {
ret.push_back(Move{
xy.to_index(),
c.to_index(),
.is_capturing = true,
.en_passant = true
});
}
}
// -- Normal move + promotion
bool is_on_starting_rank =
my_colour == Colour::White ? xy.y == 1 : xy.y == 6;
int max_dy = is_on_starting_rank ? 3 : 2;
@ -39,12 +75,17 @@ std::vector<Move> pawn_moves(const Board& b, const Coords xy) {
if (b.squares[new_xy.to_index()] != Piece::None)
break;
if (new_xy.y == 7 || new_xy.y == 0)
for (auto piece : {Queen, Knigt, Bishop, Rook})
for (auto piece : {Rook, Knigt, Bishop, Queen})
ret.push_back(Move{
xy.to_index(),
new_xy.to_index(),
.promoting_to = piece
.promoting_to = (int8_t) (my_colour | piece)
});
else
ret.push_back(Move{
xy.to_index(),
new_xy.to_index(),
});
}
return ret;

View File

@ -18,14 +18,28 @@ keep_only_blocking(const std::vector<Move> candidates, const Board& board) {
return ret;
}
std::vector<Move> legal_moves(
int8_t p, const Board& b, const Coords xy, bool looking_for_check = false
) {
std::vector<Move>
legal_moves(int8_t p, const Board& b, const Coords xy, bool looking_for_check) {
std::vector<Move> ret;
switch (p) {
int8_t simple_piece = p & 0b00111;
switch (simple_piece) {
case Piece::Pawn:
ret = pawn_moves(b, xy);
break;
case Piece::Bishop:
ret = bishop_moves(b, xy);
break;
case Piece::Rook:
ret = rook_moves(b, xy);
break;
case Piece::Knigt:
ret = knight_moves(b, xy);
break;
case Piece::Queen:
ret = queen_moves(b, xy);
break;
case Piece::King:
ret = king_moves(b, xy);
break;
default:
break;
@ -34,12 +48,12 @@ std::vector<Move> legal_moves(
if (!looking_for_check)
return keep_only_blocking(ret, b);
return {};
return ret;
}
std::optional<Move>
move_for_position(const Board& board, const Coords source, const Coords dest) {
if (dest.is_within_bounds())
if (!dest.is_within_bounds())
return {};
int8_t piece = board.squares[dest.to_index()];
@ -56,7 +70,7 @@ move_for_position(const Board& board, const Coords source, const Coords dest) {
std::vector<Move>
look_direction(const Board& board, const Coords xy, int mult_dx, int mult_dy) {
std::vector<Move> ret;
for (int d = 0; d < 8; d++) {
for (int d = 1; d < 8; d++) {
int dx = mult_dx * d;
int dy = mult_dy * d;
@ -66,6 +80,8 @@ look_direction(const Board& board, const Coords xy, int mult_dx, int mult_dy) {
ret.push_back(move.value());
if (move.value().is_capturing)
break;
} else {
break;
}
}
return ret;

View File

@ -1,19 +1,18 @@
#pragma once
#include "../move.hpp"
#include <cstdint>
#include <optional>
#include <ostream>
#include <vector>
enum Piece : int8_t {
None = 0,
King = 1,
Pawn = 2,
Knigt = 3,
Bishop = 4,
Rook = 5,
Queen = 6,
Rook = 1,
Knigt = 2,
Bishop = 3,
Queen = 4,
King = 5,
Pawn = 6,
};
enum Colour : int8_t {
@ -21,10 +20,16 @@ enum Colour : int8_t {
Black = 16,
};
inline std::ostream& operator<<(std::ostream& os, const int8_t& i) {
os << std::to_string(i);
return os;
}
class Board;
struct Coords;
struct Move;
std::vector<Move> legal_moves(int8_t, const Board&, const Coords, bool);
std::vector<Move> legal_moves(int8_t, const Board&, const Coords, bool = false);
std::vector<Move> keep_only_blocking(const std::vector<Move>, const Board&);
std::optional<Move> move_for_position(const Board&, const Coords, const Coords);
std::vector<Move> look_direction(const Board&, const Coords, int, int);

View File

@ -0,0 +1,164 @@
#include "stickfosh.hpp"
#include "board.hpp"
#include "move.hpp"
#include <chrono>
#include <map>
#include <ostream>
#include <sstream>
#include <string>
#include <vector>
static std::string tick = "\033[92m✔\033[0m"; // Green Tick;
static std::string cross = "\033[91m❌\033[0m"; // Red Cross
static std::map<std::string, std::map<int, int>> pos2expected{
// -- Position 1
{
"rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1",
{
{1, 20}, // 0
{2, 400}, // 1
{3, 8902}, // 38
{4, 197281}, // 971
// {5, 4865609}, // 23032
},
},
// -- Position 2
{
"r3k2r/p1ppqpb1/bn2pnp1/3PN3/1p2P3/2N2Q1p/PPPBBPPP/R3K2R w KQkq - 0 2",
{
{1, 48}, // 0
{2, 2039}, // 16
{3, 97862}, // 602
// {4, 4085603}, // 26612
},
},
// -- Position 3
{
"8/2p5/3p4/KP5r/1R3p1k/8/4P1P1/8 w - - 0 3",
{
{1, 14}, // 0
{2, 191}, // 1
{3, 2812}, // 11
{4, 43238}, // 157
{5, 674624}, // 2199
// {6, 11030083},
},
},
// -- Position 4a
{
"r3k2r/Pppp1ppp/1b3nbN/nP6/BBP1P3/q4N2/Pp1P2PP/R2Q1RK1 w kq - 0 4",
{
{1, 6}, // 0
{2, 264}, // 1
{3, 9467}, // 69
{4, 422333}, // 3085
// {5, 15833292}, // 124452
},
},
// -- Position 4b
{
"r2q1rk1/pP1p2pp/Q4n2/bbp1p3/Np6/1B3NBn/pPPP1PPP/R3K2R b KQ - 0 5",
{
{1, 6}, // 0
{2, 264}, // 2
{3, 9467}, // 104
{4, 422333}, // 3742
// {5, 15833292}, // 136784
},
},
// -- Position 5
{
"rnbq1k1r/pp1Pbppp/2p5/8/2B5/8/PPP1NnPP/RNBQK2R w KQ - 1 6",
{
{1, 44}, // 0
{2, 1486}, // 12
{3, 62379}, // 357
// {4, 2103487}, // 13804
// {5, 89941194}, // 1230428
},
},
// -- Position 6
{
"r4rk1/1pp1qppp/p1np1n2/2b1p1B1/2B1P1b1/P1NP1N2/1PP1QPPP/R4RK1 w - - 0 "
"7",
{
{1, 46}, // 0
{2, 2079}, // 16
{3, 89890}, // 602
// {4, 3894594}, // 26612
// {5, 164075551}, // 1230428
},
},
};
static std::stringstream res;
int move_generation_test(Board& b, int depth, int max_depth) {
if (depth == max_depth) {
res.str("");
res.clear();
}
if (b.is_terminal())
return 0;
if (depth == 0)
return 1;
std::vector<Move> moves = b.all_legal_moves();
if (depth == 1)
return moves.size();
int num_pos = 0;
for (const Move& move : moves) {
Board tmp_board = b.make_move(move);
// std::cout << ">" << move << std::endl;
int n = move_generation_test(tmp_board, depth - 1, max_depth);
// std::cout << "<" << move << std::endl;
if (depth == max_depth)
res << move << ": " << n << std::endl;
num_pos += n;
}
return num_pos;
}
void perft() {
for (auto& [key, value] : pos2expected)
perft(key);
}
void perft(std::string pos) {
std::cout << pos << std::endl;
std::map<int, int> expected = pos2expected[pos];
Board b = Board::setup_fen_position(pos);
for (const auto& [depth, expected_n_moves] : expected) {
std::cout << "Depth: " << depth << " " << std::flush;
auto start = std::chrono::steady_clock::now();
int moves = move_generation_test(b, depth, depth);
auto end = std::chrono::steady_clock::now();
auto elapsed =
std::chrono::duration_cast<std::chrono::milliseconds>(end - start)
.count();
std::cout << "Results: " << moves << " ";
if (moves == expected_n_moves)
std::cout << tick << " ";
else
std::cout << cross << " (expected " << expected_n_moves << ") ";
std::cout << "positions Time: " << elapsed << " milliseconds"
<< std::endl;
if (moves != expected_n_moves) {
std::cout << std::endl << res.str();
exit(1);
}
}
}

6
cpp/src/stickfosh.hpp Normal file
View File

@ -0,0 +1,6 @@
#pragma once
#include <string>
void perft(std::string pos);
void perft();