Skip to content

Commit

Permalink
bug fixes only, subset of improve connection games
Browse files Browse the repository at this point in the history
  • Loading branch information
RainRat committed Jul 16, 2024
1 parent 81dd96c commit b67fe16
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 7 deletions.
11 changes: 10 additions & 1 deletion src/evaluate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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())

{
Expand All @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion src/position.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/position.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
7 changes: 4 additions & 3 deletions src/variant.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/variant.h
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ struct Variant {
bool endgameEval = false;
bool shogiStylePromotions = false;
std::vector<Direction> 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;
Expand Down

0 comments on commit b67fe16

Please sign in to comment.