Skip to content

Commit

Permalink
add 'wall or move' rule (for Atlantis) (fairy-stockfish#728)
Browse files Browse the repository at this point in the history
  • Loading branch information
RainRat authored Mar 1, 2024
1 parent fb8cf35 commit bbe0d95
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 6 deletions.
9 changes: 8 additions & 1 deletion src/movegen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ namespace {
ExtMove* make_move_and_gating(const Position& pos, ExtMove* moveList, Color us, Square from, Square to, PieceType pt = NO_PIECE_TYPE) {

// Wall placing moves
if (pos.walling())
//if it's "wall or move", and they chose non-null move, skip even generating wall move
if (pos.walling() && !(pos.variant()->wallOrMove && (from!=to)))
{
Bitboard b = pos.board_bb() & ~((pos.pieces() ^ from) | to);
if (T == CASTLING)
Expand Down Expand Up @@ -443,6 +444,12 @@ namespace {
// Workaround for passing: Execute a non-move with any piece
if (pos.pass(Us) && !pos.count<KING>(Us) && pos.pieces(Us))
*moveList++ = make<SPECIAL>(lsb(pos.pieces(Us)), lsb(pos.pieces(Us)));

//if "wall or move", generate walling action with null move
if (pos.variant()->wallOrMove)
{
moveList = make_move_and_gating<SPECIAL>(pos, moveList, Us, lsb(pos.pieces(Us)), lsb(pos.pieces(Us)));
}
}

// King moves
Expand Down
1 change: 1 addition & 0 deletions src/parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,7 @@ Variant* VariantParser<DoCheck>::parse(Variant* v) {
parse_attribute("wallingRegionBlack", v->wallingRegion[BLACK]);
parse_attribute("wallingRegion", v->wallingRegion[WHITE]);
parse_attribute("wallingRegion", v->wallingRegion[BLACK]);
parse_attribute("wallOrMove", v->wallOrMove);
parse_attribute("seirawanGating", v->seirawanGating);
parse_attribute("cambodianMoves", v->cambodianMoves);
parse_attribute("diagonalLines", v->diagonalLines);
Expand Down
6 changes: 4 additions & 2 deletions src/position.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1303,7 +1303,8 @@ bool Position::pseudo_legal(const Move m) const {
return checkers() ? MoveList< EVASIONS>(*this).contains(m)
: MoveList<NON_EVASIONS>(*this).contains(m);

if (walling())
//if walling, and walling is not optional, or they didn't move, do the checks.
if (walling() && (!var->wallOrMove || (from==to)))
{
Bitboard wallsquares = st->wallSquares;

Expand Down Expand Up @@ -2045,7 +2046,8 @@ void Position::do_move(Move m, StateInfo& newSt, bool givesCheck) {
}

// Add gated wall square
if (walling())
// if wallOrMove, only actually place the wall if they gave up their move
if (walling() && (!var->wallOrMove || (from==to)))
{
// Reset wall squares for duck walling
if (walling_rule() == DUCK)
Expand Down
1 change: 1 addition & 0 deletions src/variant.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ struct Variant {
bool gating = false;
WallingRule wallingRule = NO_WALLING;
Bitboard wallingRegion[COLOR_NB] = {AllSquares, AllSquares};
bool wallOrMove = false;
bool seirawanGating = false;
bool cambodianMoves = false;
Bitboard diagonalLines = 0;
Expand Down
5 changes: 2 additions & 3 deletions src/variants.ini
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@
# wallingRule: rule on where wall can be placed [WallingRule] (default: none)
# wallingRegionWhite: mask where wall squares (including duck) can be placed by white [Bitboard] (default: all squares)
# wallingRegionBlack: mask where wall squares (including duck) can be placed by black [Bitboard] (default: all squares)
# wallOrMove: can wall or move, but not both [bool] (default: false)
# seirawanGating: allow gating of pieces in hand like in S-Chess, requires "gating = true" [bool] (default: false)
# cambodianMoves: enable special moves of cambodian chess, requires "gating = true" [bool] (default: false)
# diagonalLines: enable special moves along diagonal for specific squares (Janggi) [Bitboard]
Expand Down Expand Up @@ -1811,9 +1812,7 @@ connectDiagonal = false
#https://www.chessvariants.com/boardrules.dir/atlantis.html
[atlantis:chess]
wallingRule = edge
#not ready yet. Other wall variants are "move and wall", this is "move or wall".
#need to figure out way to do this ie. write code for:
#wallOrMove = true
wallOrMove = true

#https://www.chessvariants.com/rules/ajax-orthodox-chess
[ajax-orthodox:chess]
Expand Down

0 comments on commit bbe0d95

Please sign in to comment.