fen
stringlengths
28
78
n_moves
sequencelengths
1
378k
term_n_moves
sequencelengths
1
378k
term_reason
sequencelengths
1
378k
term_white_wins
sequencelengths
1
378k
3q4/k5n1/1p1p3p/2PBp1NP/p2P1P1P/8/6K1/8 b - - 3 61
[ 121 ]
[ 314 ]
[ 3 ]
[ null ]
8/8/3K4/7p/7P/p1kpN3/8/4n3 w - - 3 93
[ 184 ]
[ 362 ]
[ 3 ]
[ null ]
rnbqkb1r/pp1pp1pp/2p2n2/5p2/8/2BP4/PPP1PPPP/RN1QKBNR w KQkq - 2 4
[ 6 ]
[ 317 ]
[ 3 ]
[ null ]
3K1k2/P7/8/8/4B3/b6n/8/8 b - - 8 138
[ 275 ]
[ 416 ]
[ 3 ]
[ null ]
8/5p2/r2bkp2/8/8/8/7K/8 w - - 26 176
[ 350 ]
[ 589 ]
[ 3 ]
[ null ]
6N1/8/8/1k3r2/1B5K/1p6/8/8 b - - 14 133
[ 265 ]
[ 414 ]
[ 3 ]
[ null ]
n1N5/1R4k1/8/1B2r2P/8/8/5K2/8 b - - 17 112
[ 223 ]
[ 308 ]
[ 3 ]
[ null ]
2Bk4/rp3r2/5p2/2p2P2/1n1p1BPb/PP1P3P/8/R2KR3 w - - 3 35
[ 68 ]
[ 331 ]
[ 3 ]
[ null ]
K7/3k4/8/8/3b4/p2q4/8/8 b - - 68 139
[ 277 ]
[ 294 ]
[ 2 ]
[ null ]
2b3n1/3knr2/r4p2/p1b1P2R/6P1/PB2p1P1/2P5/RK6 w - - 1 37
[ 72 ]
[ 276 ]
[ 3 ]
[ null ]
2r2bnr/p7/3k1pq1/4p1NQ/R2pP3/2BP3p/1NP2PR1/6K1 w - - 4 34
[ 66 ]
[ 74 ]
[ 1 ]
[ false ]
kn5B/7r/2p5/p3P1pP/P4pb1/8/3R3N/2R1K3 b - - 1 61
[ 121 ]
[ 182 ]
[ 2 ]
[ null ]
N7/7b/5P2/3p2N1/k2P2p1/8/1K6/7r w - - 6 81
[ 160 ]
[ 175 ]
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B3/4P3/7K/8 b - - 6 145
[ 289 ]
[ 456 ]
[ 3 ]
[ null ]
1nb2qkr/3pb3/1p6/r2P1pp1/p1n3pp/1P2P3/PBP3BP/4RK1R w - - 2 34
[ 66 ]
[ 314 ]
[ 3 ]
[ null ]
8/7P/6k1/8/8/8/6K1/8 b - - 0 204
[ 407 ]
[ 409 ]
[ 3 ]
[ null ]
6q1/2B5/1P6/6K1/8/2n5/5k2/1q6 w - - 31 115
[ 228 ]
[ 230 ]
[ 1 ]
[ false ]
8/6n1/8/p5p1/P3Kp2/4p3/1b1r4/1k6 b - - 6 92
[ 183 ]
[ 378 ]
[ 2 ]
[ null ]

100M Random Chess Boards

This dataset contains 100 million randomly sampled chess board positions. The process to generate each board state is as follows:

  1. Game Simulation
  • 100 million games were played, with each move being randomly determined until the game ended (i.e., until checkmate, stalemate, or draw).
  1. Board Sampling
  • From each game, a single random board state was selected at some point in the game.

Columns other than fen represent statistics for the sample. Most boards are sampled only once, however for example, the most common board, the initial board, is sampled 378,310 times. This comprises a single row with each column other than fen being 378,310 long.

Columns

  • fen: The FEN (Forsyth-Edwards Notation) representing the randomly sampled board position.
  • n_moves: The number of moves made from the start of the game to reach the sampled FEN position.
  • term_n_moves: The total number of moves in the random game before it terminated.
  • term_reason: The reason the game ended. (Codes)
  • term_white_wins: Indicates whether white won the game (true/false). null indicates a tie. Note that all games are complete, but the sampled board position is from an intermediate point.

Code

from tqdm import tqdm
import collections
import chess
import random
from datasets import Dataset

import os
from multiprocessing import Process, Queue


def random_fen():
    """
    Play random game to completion
    backtrack random uniform number of moves
    """
    board = chess.Board()
    num_moves = 0
    while True:
        board.push(random.choice(list(board.legal_moves)))
        num_moves += 1
        if board.is_game_over():
            outcome = board.outcome()
            revert_moves = random.randint(0, num_moves)
            for _ in range(revert_moves):
                board.pop()
            fen_num_moves = num_moves - revert_moves
            termination_reason = outcome.termination.value
            white_is_winner = outcome.winner
            return board.fen(), fen_num_moves, num_moves, termination_reason, white_is_winner


def batched_random_fen(queue, batch_size=100):
    while True:
        fens = []
        while len(fens) < batch_size:
            fens.append(random_fen())
        queue.put(fens)


def generate_fens_parallel(N):
    all_fens = collections.defaultdict(
        lambda: {"n_moves": [], "term_n_moves": [], "term_reason": [], "term_white_wins": []}
    )
    queue = Queue()
    num_workers = os.cpu_count() // 2

    # Start worker processes in advance
    workers = []
    for _ in range(num_workers):
        worker = Process(target=batched_random_fen, args=(queue,))
        worker.daemon = True  # Ensures the process terminates with the main process
        workers.append(worker)
        worker.start()

    with tqdm(total=N, desc="FENs Captured") as pbar:
        for i in range(1_000_000_000_000):
            for fen, board_num_moves, final_state_num_moves, final_result, final_is_white_winner in queue.get():
                all_fens[fen]["n_moves"].append(board_num_moves)
                all_fens[fen]["term_n_moves"].append(final_state_num_moves)
                all_fens[fen]["term_reason"].append(final_result)
                all_fens[fen]["term_white_wins"].append(final_is_white_winner)

            if i % 100 == 0:
                pbar.n = len(all_fens)
                pbar.last_print_n = len(all_fens)
                pbar.refresh()

            if len(all_fens) >= N:
                break

    # Terminate workers
    for worker in workers:
        worker.terminate()

    # flatten
    return [{"fen": k, **v} for k, v in all_fens.items()]


if __name__ == "__main__":
    board_dicts = list(generate_fens_parallel(100_000_000))
    ds = Dataset.from_dict({key: [dic[key] for dic in board_dicts] for key in board_dicts[0]})
    ds.save_to_disk("random_uniform_chess_boards.hf")
    # ds = datasets.load_from_disk("random_uniform_chess_boards.hf")
    # ds.push_to_hub(...)
Downloads last month
33
Edit dataset card