From b67fe16fba7db701f6737e4db5f12e2bd08edc49 Mon Sep 17 00:00:00 2001 From: rainrat Date: Tue, 16 Jul 2024 14:47:40 -0700 Subject: [PATCH] bug fixes only, subset of improve connection games --- src/evaluate.cpp | 11 ++++++++++- src/position.cpp | 2 +- src/position.h | 2 +- src/variant.cpp | 7 ++++--- src/variant.h | 2 +- 5 files changed, 17 insertions(+), 7 deletions(-) diff --git a/src/evaluate.cpp b/src/evaluate.cpp index 396d5ff62..5e4987457 100644 --- a/src/evaluate.cpp +++ b/src/evaluate.cpp @@ -1283,6 +1283,15 @@ namespace { // Connect-n if (pos.connect_n() > 0) { + //Calculate eligible pieces for connection once. + //Still consider all opponent pieces as blocking. + Bitboard connectPiecesUs = 0; + for (PieceSet ps = pos.connect_piece_types(); ps;){ + PieceType pt = pop_lsb(ps); + connectPiecesUs |= pos.pieces(pt); + }; + connectPiecesUs &= pos.pieces(Us); + for (const Direction& d : pos.getConnectDirections()) { @@ -1296,7 +1305,7 @@ namespace { Square s = pop_lsb(b); int c = 0; for (int j = 0; j < pos.connect_n(); j++) - if (pos.pieces(Us) & (s - j * d)) + if (connectPiecesUs & (s - j * d)) c++; score += make_score(200, 200) * c / (pos.connect_n() - c) / (pos.connect_n() - c); } diff --git a/src/position.cpp b/src/position.cpp index b9f34be44..df9aa6157 100644 --- a/src/position.cpp +++ b/src/position.cpp @@ -2887,7 +2887,7 @@ bool Position::is_immediate_game_end(Value& result, int ply) const { } // Check for bikjang rule (Janggi), double passing, or board running full - if ( (st->pliesFromNull > 0 && ((st->bikjang && st->previous->bikjang) || (st->pass && st->previous->pass))) + if ( (st->pliesFromNull > 0 && ((st->bikjang && st->previous->bikjang) || ((st->pass && st->previous->pass)&&!var->wallOrMove))) || (var->adjudicateFullBoard && !(~pieces() & board_bb()))) { result = var->materialCounting ? convert_mate_value(material_counting_result(), ply) : VALUE_DRAW; diff --git a/src/position.h b/src/position.h index d02372567..712c21eea 100644 --- a/src/position.h +++ b/src/position.h @@ -1040,7 +1040,7 @@ inline int Position::connect_n() const { inline PieceSet Position::connect_piece_types() const { assert(var != nullptr); - return var->connectPieceTypes; + return var->connectPieceTypesTrimmed; } inline bool Position::connect_horizontal() const { diff --git a/src/variant.cpp b/src/variant.cpp index bf61a0493..db69f55ad 100644 --- a/src/variant.cpp +++ b/src/variant.cpp @@ -2066,15 +2066,16 @@ Variant* Variant::conclude() { connect_directions.push_back(SOUTH_EAST); } - // If not a connect variant, set connectPieceTypes to no pieces. + // If not a connect variant, set connectPieceTypesTrimmed to no pieces. + // connectPieceTypesTrimmed is separated so that connectPieceTypes is left unchanged for inheritance. if ( !(connectRegion1[WHITE] || connectRegion1[BLACK] || connectN || connectNxN || collinearN) ) { - connectPieceTypes = NO_PIECE_SET; + connectPieceTypesTrimmed = NO_PIECE_SET; } //Otherwise optimize to pieces actually in the game. else { - connectPieceTypes = connectPieceTypes & pieceTypes; + connectPieceTypesTrimmed = connectPieceTypes & pieceTypes; }; return this; diff --git a/src/variant.h b/src/variant.h index aa2738356..03faa51fb 100644 --- a/src/variant.h +++ b/src/variant.h @@ -178,7 +178,7 @@ struct Variant { bool endgameEval = false; bool shogiStylePromotions = false; std::vector connect_directions; - + PieceSet connectPieceTypesTrimmed = ~NO_PIECE_SET; void add_piece(PieceType pt, char c, std::string betza = "", char c2 = ' ') { // Avoid ambiguous definition by removing existing piece with same letter size_t idx;