Skip to main content
deleted 77 characters in body
Source Link
import chess

# Create an empty chess benter preformatted text hereoard
board = chess.Board()

# Initialize an empty list to store all possible moves
action_space = []

# Iterate over all squares and all piece types
for square in chess.SQUARES:
    for piece_type in chess.PIECE_TYPES:
        for color in chess.COLORS:
            # Set player to color
            board.turn = color
            # Place piece on given square
            board.set_piece_at(square, chess.Piece(piece_type, color))
            
            # If the piece is a pawn, place other pawns around it to include attacks
            if piece_type == chess.PAWN:
                other_color = chess.WHITE if color == chess.BLACK else chess.BLACK
                for square_offset in [-7, -9, 7, 9]:
                    if square + square_offset in chess.SQUARES:
                        board.set_piece_at(square + square_offset, chess.Piece(piece_type, other_color))

            # Iterate over all squares again to find all possible moves
            for move in board.legal_moves:
                # If the move is not already in the action space, add it
                if move not in action_space:
                    action_space.append(move)

            # Clear the board
            board.clear()
action_space = sorted(action_space, key=lambda x: x.uci())

for i in range(len(action_space) - 1):
    if action_space[i] == action_space[i+1]:
        print("Duplicate found: ", action_space[i].uci())
        exit()
print("No duplicates found")
print("Number of moves: ", len(action_space))
import chess

# Create an empty chess benter preformatted text hereoard
board = chess.Board()

# Initialize an empty list to store all possible moves
action_space = []

# Iterate over all squares and all piece types
for square in chess.SQUARES:
    for piece_type in chess.PIECE_TYPES:
        for color in chess.COLORS:
            # Set player to color
            board.turn = color
            # Place piece on given square
            board.set_piece_at(square, chess.Piece(piece_type, color))
            
            # If the piece is a pawn, place other pawns around it to include attacks
            if piece_type == chess.PAWN:
                other_color = chess.WHITE if color == chess.BLACK else chess.BLACK
                for square_offset in [-7, -9, 7, 9]:
                    if square + square_offset in chess.SQUARES:
                        board.set_piece_at(square + square_offset, chess.Piece(piece_type, other_color))

            # Iterate over all squares again to find all possible moves
            for move in board.legal_moves:
                # If the move is not already in the action space, add it
                if move not in action_space:
                    action_space.append(move)

            # Clear the board
            board.clear()
action_space = sorted(action_space, key=lambda x: x.uci())

for i in range(len(action_space) - 1):
    if action_space[i] == action_space[i+1]:
        print("Duplicate found: ", action_space[i].uci())
        exit()
print("No duplicates found")
print("Number of moves: ", len(action_space))
import chess

# Create an empty chess benter preformatted text hereoard
board = chess.Board()

# Initialize an empty list to store all possible moves
action_space = []

# Iterate over all squares and all piece types
for square in chess.SQUARES:
    for piece_type in chess.PIECE_TYPES:
        for color in chess.COLORS:
            # Set player to color
            board.turn = color
            # Place piece on given square
            board.set_piece_at(square, chess.Piece(piece_type, color))
            
            # If the piece is a pawn, place other pawns around it to include attacks
            if piece_type == chess.PAWN:
                other_color = chess.WHITE if color == chess.BLACK else chess.BLACK
                for square_offset in [-7, -9, 7, 9]:
                    if square + square_offset in chess.SQUARES:
                        board.set_piece_at(square + square_offset, chess.Piece(piece_type, other_color))

            for move in board.legal_moves:
                # If the move is not already in the action space, add it
                if move not in action_space:
                    action_space.append(move)

            # Clear the board
            board.clear()
action_space = sorted(action_space, key=lambda x: x.uci())

for i in range(len(action_space) - 1):
    if action_space[i] == action_space[i+1]:
        print("Duplicate found: ", action_space[i].uci())
        exit()
print("No duplicates found")
print("Number of moves: ", len(action_space))
edited body
Source Link

havingHaving written the code below, I find 1968 unique moves. This thread is old but maybe this helps someone.

having written the code below, I find 1968 unique moves. This thread is old but maybe this helps someone.

Having written the code below, I find 1968 unique moves. This thread is old but maybe this helps someone.

Source Link

having written the code below, I find 1968 unique moves. This thread is old but maybe this helps someone.

import chess

# Create an empty chess benter preformatted text hereoard
board = chess.Board()

# Initialize an empty list to store all possible moves
action_space = []

# Iterate over all squares and all piece types
for square in chess.SQUARES:
    for piece_type in chess.PIECE_TYPES:
        for color in chess.COLORS:
            # Set player to color
            board.turn = color
            # Place piece on given square
            board.set_piece_at(square, chess.Piece(piece_type, color))
            
            # If the piece is a pawn, place other pawns around it to include attacks
            if piece_type == chess.PAWN:
                other_color = chess.WHITE if color == chess.BLACK else chess.BLACK
                for square_offset in [-7, -9, 7, 9]:
                    if square + square_offset in chess.SQUARES:
                        board.set_piece_at(square + square_offset, chess.Piece(piece_type, other_color))

            # Iterate over all squares again to find all possible moves
            for move in board.legal_moves:
                # If the move is not already in the action space, add it
                if move not in action_space:
                    action_space.append(move)

            # Clear the board
            board.clear()
action_space = sorted(action_space, key=lambda x: x.uci())

for i in range(len(action_space) - 1):
    if action_space[i] == action_space[i+1]:
        print("Duplicate found: ", action_space[i].uci())
        exit()
print("No duplicates found")
print("Number of moves: ", len(action_space))