Skip to content

Commit

Permalink
Merge remote-tracking branch 'fairy/master' into tools
Browse files Browse the repository at this point in the history
  • Loading branch information
ianfab committed Aug 20, 2023
2 parents 85b0964 + 1d101f8 commit 947a355
Show file tree
Hide file tree
Showing 14 changed files with 220 additions and 23 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/wheels.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-20.04, windows-2019, macos-10.15]
os: [ubuntu-20.04, windows-2019, macos-11]

steps:
- uses: actions/checkout@v3
Expand Down
2 changes: 1 addition & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ before_build:
'add_compile_definitions(NNUE_EMBEDDING_OFF)',
'add_executable(stockfish ${source_files})'
# Write CMakeLists.txt withouth BOM
# Write CMakeLists.txt without BOM
$MyPath = (Get-Item -Path "." -Verbose).FullName + '\CMakeLists.txt'
$Utf8NoBomEncoding = New-Object System.Text.UTF8Encoding $False
[System.IO.File]::WriteAllLines($MyPath, $t, $Utf8NoBomEncoding)
Expand Down
17 changes: 16 additions & 1 deletion src/evaluate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1294,7 +1294,22 @@ namespace {
// Connect-n
if (pos.connect_n() > 0)
{
for (Direction d : {NORTH, NORTH_EAST, EAST, SOUTH_EAST})
std::vector<Direction> connect_directions;

if (pos.connect_horizontal())
{
connect_directions.push_back(EAST);
}
if (pos.connect_vertical())
{
connect_directions.push_back(NORTH);
}
if (pos.connect_diagonal())
{
connect_directions.push_back(NORTH_EAST);
connect_directions.push_back(SOUTH_EAST);
}
for (Direction d : connect_directions)
{
// Find sufficiently large gaps
Bitboard b = pos.board_bb() & ~pos.pieces(Them);
Expand Down
3 changes: 3 additions & 0 deletions src/parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,9 @@ Variant* VariantParser<DoCheck>::parse(Variant* v) {
parse_attribute("flagMove", v->flagMove);
parse_attribute("checkCounting", v->checkCounting);
parse_attribute("connectN", v->connectN);
parse_attribute("connectHorizontal", v->connectHorizontal);
parse_attribute("connectVertical", v->connectVertical);
parse_attribute("connectDiagonal", v->connectDiagonal);
parse_attribute("materialCounting", v->materialCounting);
parse_attribute("countingRule", v->countingRule);

Expand Down
2 changes: 1 addition & 1 deletion src/partner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ void PartnerHandler::parse_ptell(std::istringstream& is, const Position& pos) {
ptell<HUMAN>("If you specify a valid move, e.g., 'move e2e4', I will play it.");
}
else if (token == "fast")
ptell<HUMAN>("After receiving 'go', I will play fast.");
ptell<HUMAN>("After receiving 'fast', I will play fast.");
else if (token == "slow")
ptell<HUMAN>("After receiving 'slow', I will play at normal speed.");
else if (token == "dead")
Expand Down
30 changes: 23 additions & 7 deletions src/position.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -353,10 +353,10 @@ Position& Position::set(const Variant* v, const string& fenStr, bool isChess960,

token = char(toupper(token));

if (token == 'K')
if (castling_enabled() && token == 'K')
for (rsq = make_square(var->castlingRookKingsideFile, castling_rank(c)); !(castling_rook_pieces(c) & type_of(piece_on(rsq))) || color_of(piece_on(rsq)) != c; --rsq) {}

else if (token == 'Q')
else if (castling_enabled() && token == 'Q')
for (rsq = make_square(var->castlingRookQueensideFile, castling_rank(c)); !(castling_rook_pieces(c) & type_of(piece_on(rsq))) || color_of(piece_on(rsq)) != c; ++rsq) {}

else if (token >= 'A' && token <= 'A' + max_file())
Expand Down Expand Up @@ -433,6 +433,7 @@ Position& Position::set(const Variant* v, const string& fenStr, bool isChess960,
// c) there is no piece on epSquare or behind epSquare
if ( (var->enPassantRegion & epSquare)
&& ( !var->fastAttacks
|| (var->enPassantTypes[sideToMove] & ~piece_set(PAWN))
|| ( pawn_attacks_bb(~sideToMove, epSquare) & pieces(sideToMove, PAWN)
&& ( (pieces(~sideToMove, PAWN) & (epSquare + pawn_push(~sideToMove)))
|| (pieces(~sideToMove, PAWN) & (epSquare + 2 * pawn_push(~sideToMove))))
Expand Down Expand Up @@ -703,7 +704,7 @@ string Position::fen(bool sfen, bool showPromoted, int countStarted, std::string
ss << piece_to_char()[piece_on(make_square(f, r))];

// Set promoted pieces
if (((captures_to_hand() && !drop_loop()) || showPromoted) && is_promoted(make_square(f, r)))
if (((captures_to_hand() && !drop_loop()) || two_boards() || showPromoted) && is_promoted(make_square(f, r)))
ss << "~";
}
}
Expand Down Expand Up @@ -1665,7 +1666,7 @@ void Position::do_move(Move m, StateInfo& newSt, bool givesCheck) {
// Find end of rows to be flipped
if (flip_enclosed_pieces() == REVERSI)
{
Bitboard b = attacks_bb(us, QUEEN, to, board_bb() & ~pieces(~us)) & ~PseudoAttacks[us][KING][to] & pieces(us);
Bitboard b = attacks_bb(us, QUEEN, to, ~pieces(~us)) & ~PseudoAttacks[us][KING][to] & pieces(us);
while(b)
st->flippedPieces |= between_bb(pop_lsb(b), to) ^ to;
}
Expand Down Expand Up @@ -1795,15 +1796,15 @@ void Position::do_move(Move m, StateInfo& newSt, bool givesCheck) {
|| std::abs(int(to) - int(from)) == 3 * NORTH))
{
if ( (var->enPassantRegion & (to - pawn_push(us)))
&& (pawn_attacks_bb(us, to - pawn_push(us)) & pieces(them, PAWN))
&& ((pawn_attacks_bb(us, to - pawn_push(us)) & pieces(them, PAWN)) || var->enPassantTypes[them] & ~piece_set(PAWN))
&& !(wall_gating() && gating_square(m) == to - pawn_push(us)))
{
st->epSquares |= to - pawn_push(us);
k ^= Zobrist::enpassant[file_of(to)];
}
if ( std::abs(int(to) - int(from)) == 3 * NORTH
&& (var->enPassantRegion & (to - 2 * pawn_push(us)))
&& (pawn_attacks_bb(us, to - 2 * pawn_push(us)) & pieces(them, PAWN))
&& ((pawn_attacks_bb(us, to - 2 * pawn_push(us)) & pieces(them, PAWN)) || var->enPassantTypes[them] & ~piece_set(PAWN))
&& !(wall_gating() && gating_square(m) == to - 2 * pawn_push(us)))
{
st->epSquares |= to - 2 * pawn_push(us);
Expand Down Expand Up @@ -2722,7 +2723,22 @@ bool Position::is_immediate_game_end(Value& result, int ply) const {
if (connect_n() > 0)
{
Bitboard b;
for (Direction d : {NORTH, NORTH_EAST, EAST, SOUTH_EAST})
std::vector<Direction> connect_directions;

if (connect_horizontal())
{
connect_directions.push_back(EAST);
}
if (connect_vertical())
{
connect_directions.push_back(NORTH);
}
if (connect_diagonal())
{
connect_directions.push_back(NORTH_EAST);
connect_directions.push_back(SOUTH_EAST);
}
for (Direction d : connect_directions)
{
b = pieces(~sideToMove);
for (int i = 1; i < connect_n() && b; i++)
Expand Down
18 changes: 18 additions & 0 deletions src/position.h
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,10 @@ class Position {
bool flag_reached(Color c) const;
bool check_counting() const;
int connect_n() const;
bool connect_horizontal() const;
bool connect_vertical() const;
bool connect_diagonal() const;

CheckCount checks_remaining(Color c) const;
MaterialCounting material_counting() const;
CountingRule counting_rule() const;
Expand Down Expand Up @@ -973,6 +977,20 @@ inline int Position::connect_n() const {
return var->connectN;
}

inline bool Position::connect_horizontal() const {
assert(var != nullptr);
return var->connectHorizontal;
}
inline bool Position::connect_vertical() const {
assert(var != nullptr);
return var->connectVertical;
}
inline bool Position::connect_diagonal() const {
assert(var != nullptr);
return var->connectDiagonal;
}


inline CheckCount Position::checks_remaining(Color c) const {
return st->checksRemaining[c];
}
Expand Down
6 changes: 3 additions & 3 deletions src/syzygy/tbprobe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -770,7 +770,7 @@ Ret do_probe_table(const Position& pos, T* entry, WDLScore wdl, ProbeState* resu
goto encode_remaining; // With pawns we have finished special treatments
}

// In positions withouth pawns, we further flip the squares to ensure leading
// In positions without pawns, we further flip the squares to ensure leading
// piece is below RANK_5.
if (rank_of(squares[0]) > RANK_4)
for (int i = 0; i < size; ++i)
Expand Down Expand Up @@ -821,7 +821,7 @@ Ret do_probe_table(const Position& pos, T* entry, WDLScore wdl, ProbeState* resu
int adjust2 = (squares[2] > squares[0]) + (squares[2] > squares[1]);

// First piece is below a1-h8 diagonal. MapA1D1D4[] maps the b1-d1-d3
// triangle to 0...5. There are 63 squares for second piece and and 62
// triangle to 0...5. There are 63 squares for second piece and 62
// (mapped to 0...61) for the third.
if (off_A1H8(squares[0]))
idx = ( MapA1D1D4[squares[0]] * 63
Expand Down Expand Up @@ -1326,7 +1326,7 @@ void Tablebases::init(const std::string& paths) {
for (auto p : bothOnDiagonal)
MapKK[p.first][p.second] = code++;

// Binomial[] stores the Binomial Coefficents using Pascal rule. There
// Binomial[] stores the Binomial Coefficients using Pascal rule. There
// are Binomial[k][n] ways to choose k elements from a set of n elements.
Binomial[0][0] = 1;

Expand Down
2 changes: 1 addition & 1 deletion src/syzygy/tbprobe.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ enum WDLScore {
// Possible states after a probing operation
enum ProbeState {
FAIL = 0, // Probe failed (missing file table)
OK = 1, // Probe succesful
OK = 1, // Probe successful
CHANGE_STM = -1, // DTZ should check the other side
ZEROING_BEST_MOVE = 2 // Best move zeroes DTZ (capture or pawn move)
};
Expand Down
3 changes: 3 additions & 0 deletions src/variant.h
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,9 @@ struct Variant {
bool flagMove = false;
bool checkCounting = false;
int connectN = 0;
bool connectHorizontal = true;
bool connectVertical = true;
bool connectDiagonal = true;
MaterialCounting materialCounting = NO_MATERIAL_COUNTING;
CountingRule countingRule = NO_COUNTING;

Expand Down
Loading

0 comments on commit 947a355

Please sign in to comment.