2026-03-06

stockfishの対戦を眺めるだけのプログラム

import chess
import chess.engine
import chess.svg
import cairosvg
import os

# 保存用フォルダ作成
os.makedirs("frames", exist_ok=True)

board = chess.Board()
engine = chess.engine.SimpleEngine.popen_uci("/usr/games/stockfish")

count = 0
print("対局中...")
while not board.is_game_over():
    result = engine.play(board, chess.engine.Limit(time=1.00))
    board.push(result.move)
    
    # 連番でPNG保存 (001.png, 002.png...)
    svg_data = chess.svg.board(board, size=400).encode("utf-8")
    cairosvg.svg2png(bytestring=svg_data, write_to=f"frames/{count:03d}.png")
    count += 1
    print(f"\r{count}手目を保存中...", end="")

engine.quit()
print("\n全画像を保存しました。")
#convert -delay 50 -loop 0 frames/*.png fast_match.gif

記事への反応(ブックマークコメント)

ログイン ユーザー登録
ようこそ ゲスト さん