Skip to content

Instantly share code, notes, and snippets.

@AnishN
Created April 24, 2020 16:54
Show Gist options
  • Select an option

  • Save AnishN/be63925844f2f61d15187e0260c3a525 to your computer and use it in GitHub Desktop.

Select an option

Save AnishN/be63925844f2f61d15187e0260c3a525 to your computer and use it in GitHub Desktop.
Bughouse Single Board Puzzle Basic Validation
import chess
from chess.variant import CrazyhouseBoard, CrazyhousePocket
def bug_single_board_move(fen, san_move):
board = CrazyhouseBoard()
board.set_fen(fen)
try:
move = board.parse_san(san_move)
is_capture = board.is_capture(move)
capture_piece_type = None
if is_capture:
capture_piece = board.piece_at(move.to_square)
if capture_piece == None:
if board.is_en_passant(move):
capture_piece_type = chess.PAWN
else:
capture_piece_type = capture_piece.piece_type
if board.promoted & (1 << move.to_square):
capture_piece_type = chess.PAWN
board.push(move)
board.pockets[not(board.turn)].remove(capture_piece_type)#undo crazyhouse pocket rules
else:
board.push(move)
out_fen = board.fen()
return out_fen
except ValueError:
return None
test_fen = "r4r2/p1pb1kPp/b1p2Ppp/3pP2P/1P3P2/3N1Q1p/PPPp1PPP/R4K1R/Q w KQ - 0 1"
out_fen = bug_single_board_move(test_fen, "Q@e7")
print(out_fen)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment