Skip to content

Commit

Permalink
Generate less pseudo-legal moves if we're under check
Browse files Browse the repository at this point in the history
  • Loading branch information
alex65536 committed Aug 6, 2023
1 parent 7b850c3 commit 53f1cdb
Show file tree
Hide file tree
Showing 13 changed files with 427 additions and 137 deletions.
8 changes: 7 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This file is part of SoFCheck
#
# Copyright (c) 2020-2022 Alexander Kernozhitsky and SoFCheck contributors
# Copyright (c) 2020-2023 Alexander Kernozhitsky and SoFCheck contributors
#
# SoFCheck is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -79,6 +79,7 @@ add_library(sof_core STATIC
src/core/test/selftest.cpp
"${PROJECT_BINARY_DIR}/src/core/private/near_attacks.h"
"${PROJECT_BINARY_DIR}/src/core/private/magic_consts.h"
"${PROJECT_BINARY_DIR}/src/core/private/between_consts.h"
)
target_link_libraries(sof_core PUBLIC sof_util)

Expand Down Expand Up @@ -214,6 +215,11 @@ generate_file(
src/core/private/magic_consts.h
)

generate_file(
gen/core/between_consts.cpp
src/core/private/between_consts.h
)

generate_file_json(
gen/eval/feature_count.cpp
src/eval/feature_count.h
Expand Down
4 changes: 2 additions & 2 deletions bench/core/bench_is_move_legal.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// This file is part of SoFCheck
//
// Copyright (c) 2020-2021 Alexander Kernozhitsky and SoFCheck contributors
// Copyright (c) 2020-2021, 2023 Alexander Kernozhitsky and SoFCheck contributors
//
// SoFCheck is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -34,7 +34,7 @@ inline void runCheckValid(benchmark::State &state, const char *fen) {

Board board = Board::fromFen(fen).unwrap();
Move moves[BUFSZ_MOVES];
size_t cnt = genAllMoves(board, moves);
size_t cnt = MoveGen(board).genAllMoves(moves);

for ([[maybe_unused]] auto _ : state) {
for (size_t i = 0; i < cnt; ++i) {
Expand Down
75 changes: 75 additions & 0 deletions gen/core/between_consts.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
// This file is part of SoFCheck
//
// Copyright (c) 2023 Alexander Kernozhitsky and SoFCheck contributors
//
// SoFCheck is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// SoFCheck is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with SoFCheck. If not, see <https://www.gnu.org/licenses/>.

#include <cstddef>
#include <cstdint>
#include <vector>

#include "common.h"
#include "core/bitboard.h"
#include "core/types.h"

using namespace SoFCore;

template <typename Mask>
std::vector<bitboard_t> genBishopBetween(const Mask &mask) {
std::vector<bitboard_t> result(64);
for (coord_t c = 0; c < 64; ++c) {
const auto bb = BB_DIAG1[coordDiag1(c)] | BB_DIAG2[coordDiag2(c)];
result[c] = bb & mask(c);
}
return result;
}

template <typename Mask>
std::vector<bitboard_t> genRookBetween(const Mask &mask) {
std::vector<bitboard_t> result(64);
for (coord_t c = 0; c < 64; ++c) {
const auto bb = BB_ROW[coordX(c)] | BB_COL[coordY(c)];
result[c] = bb & mask(c);
}
return result;
}

inline bitboard_t ltMask(const coord_t c) {
return coordToBitboard(c) - static_cast<bitboard_t>(1);
}

inline bitboard_t gtMask(const coord_t c) { return ~(ltMask(c) | coordToBitboard(c)); }

GeneratorInfo getGeneratorInfo() {
return GeneratorInfo{"Generate tables to find cells located between pieces on one line"};
}

int doGenerate(SourcePrinter &p) {
p.headerGuard("SOF_CORE_PRIVATE_BETWEEN_CONSTS_INCLUDED");
p.skip();
p.include("core/types.h");
p.skip();
auto ns = p.inNamespace("SoFCore::Private");
p.skip();
p.bitboardArray("BISHOP_LT", genBishopBetween(ltMask));
p.skip();
p.bitboardArray("BISHOP_GT", genBishopBetween(gtMask));
p.skip();
p.bitboardArray("ROOK_LT", genRookBetween(ltMask));
p.skip();
p.bitboardArray("ROOK_GT", genRookBetween(gtMask));
p.skip();

return 0;
}
3 changes: 2 additions & 1 deletion selftest/sofcheck/intf.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ inline void moveStr(const Board &, const Move &mv, char *str) { SoFCore::moveToS

inline MoveList generateMoves(const Board &board) {
MoveList moves;
moves.count = static_cast<int>(SoFCore::genAllMoves(board, moves.moves));
SoFCore::MoveGen gen(board);
moves.count = static_cast<int>(gen.genAllMoves(moves.moves));
return moves;
}

Expand Down
Loading

0 comments on commit 53f1cdb

Please sign in to comment.