in evals/elsuite/cant_do_that_anymore/scripts/diagonal_dataset_creation.py [0:0]
def get_bishop_diagonal_moves(controller: BoardController, player_id: str) -> Sequence[str]:
"""
Gets all possible diagonal moves that a bishop could make on a board, even if the bishop isn't
allowed to move diagonally under the board's rules
"""
# Find all bishops on board
bishop_coords = []
board_state = controller.board.board_state
for row_idx in range(8):
for col_idx in range(8):
piece_color, piece_id = parse_piece(board_state, row_idx, col_idx)
if piece_color == player_id and piece_id == 2:
bishop_coords.append([row_idx, col_idx])
# Find all possible diagonal movements of each bishop
bishop_diagonal_moves = []
for row_idx, col_idx in bishop_coords:
for transformation in DIAGONAL_MOVES:
new_coord = [row_idx + transformation[0], col_idx + transformation[1]]
move = Move([row_idx, col_idx], new_coord, promotion=None, castling=False)
# If piece doesn't move
if transformation[0] == 0 and transformation[1] == 0:
continue
# If transformation moves piece outside board
if not coord_within_board(new_coord[0], new_coord[1]):
continue
# If transformation moves onto piece of same color
piece_color, _ = parse_piece(controller.board.board_state, new_coord[0], new_coord[1])
if piece_color == player_id:
continue
# If move crosses friendly pieces
if move_crosses_pieces(controller.board.board_state, move):
continue
move = controller.notation_parser._move_to_str(move, controller.board.board_state)
bishop_diagonal_moves.append(move)
return bishop_diagonal_moves