Created
January 12, 2021 13:33
-
-
Save void4/77e1f0aa21ad40622c5634ba03261383 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Python | |
# pip install python-chess | |
import chess | |
moves = [] | |
# Queen, covers all lines and diagonals | |
for x in range(8): | |
for y in range(8): | |
board = chess.Board("8/8/8/8/8/8/8/8") | |
board.set_piece_at(chess.square(x,y), chess.Piece(chess.QUEEN, chess.WHITE)) | |
moves += [move.uci() for move in board.generate_legal_moves()] | |
# Knight jumps | |
for x in range(8): | |
for y in range(8): | |
board = chess.Board("8/8/8/8/8/8/8/8") | |
board.set_piece_at(chess.square(x,y), chess.Piece(chess.KNIGHT, chess.WHITE)) | |
moves += [move.uci() for move in board.generate_legal_moves()] | |
# Straight pawn promotions, 2 players, 8 ranks each, 4 choices (queen, rook, bishop, knight) | |
# Diagonal pawn promotions, when capturing a piece | |
# 2 players, 14 diagonals (12 in the center and 1 each in the first and last ranks) | |
for x in range(8): | |
board = chess.Board("8/8/8/8/8/8/8/8") | |
board.set_piece_at(chess.square(x,6), chess.Piece(chess.PAWN, chess.WHITE)) | |
if x > 0: | |
board.set_piece_at(chess.square(x-1,7), chess.Piece(chess.PAWN, chess.BLACK)) | |
if x < 7: | |
board.set_piece_at(chess.square(x+1,7), chess.Piece(chess.PAWN, chess.BLACK)) | |
moves += [move.uci() for move in board.generate_legal_moves()] | |
board = chess.Board("8/8/8/8/8/8/8/8") | |
board.turn = chess.BLACK | |
board.set_piece_at(chess.square(x,1), chess.Piece(chess.PAWN, chess.BLACK)) | |
if x > 0: | |
board.set_piece_at(chess.square(x-1,0), chess.Piece(chess.PAWN, chess.WHITE)) | |
if x < 7: | |
board.set_piece_at(chess.square(x+1,0), chess.Piece(chess.PAWN, chess.WHITE)) | |
moves += [move.uci() for move in board.generate_legal_moves()] | |
board.turn = chess.WHITE | |
print(sorted(moves)) | |
print(len(moves)) | |
assert len(moves) == len(set(moves)) | |
with open("allmoves2.txt", "w+") as f: | |
f.write("\n".join(moves)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment