Skip to content

Instantly share code, notes, and snippets.

@luccabb
Created December 8, 2021 03:11
Show Gist options
  • Save luccabb/9cf4d91754dbe4e9ec11dbddff55cd4b to your computer and use it in GitHub Desktop.
Save luccabb/9cf4d91754dbe4e9ec11dbddff55cd4b to your computer and use it in GitHub Desktop.
Simple move ordering
def organize_moves(board: chess.Board):
"""
This function receives a board and it returns a list of all the
possible moves for the current player, sorted by importance.
Right now we are only sending the moves that are capturing pieces
at the starting positions in our array (so we can prune more and earlier).
Arguments:
- board: chess board state
Returns:
- legal_moves: list of all the possible moves for the current player.
"""
org_moves = deque()
for move in board.legal_moves:
if board.is_capture(move):
org_moves.appendleft(move)
else:
org_moves.append(move)
return list(org_moves)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment