-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBOTvinnik.py
32 lines (27 loc) · 944 Bytes
/
BOTvinnik.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#! /usr/bin/env python
import chess, chess.pgn, random
def randomGame():
game_num = random.randint(0,800)
pgn = open('botvinnik.pgn')
for i in range(game_num):
game = chess.pgn.read_game(pgn)
pgn.close()
return game
def getMoves(game):
moves = list(game.main_line())
return moves
def randomBoard(moves,game):
board = chess.Board()
if game.headers['Black'] == 'Botvinnik, Mikhail':
move_num = random.randrange(10,len(moves)-2,2)
else:
move_num = random.randrange(10,len(moves)-2,2)+1
for i in range(move_num):
board.push(moves[i])
return board
def question(game):
if game.headers['Black'] == 'Botvinnik, Mikhail':
text = "Here Botvinnik had black against %s in the %s. What did Mikhail play?" % (game.headers['White'].split(",")[0],game.headers['Event'])
else:
text = "Here Botvinnik had white against %s in the %s. What did Mikhail play?" % (game.headers['Black'].split(",")[0],game.headers['Event'])
return text