-
Notifications
You must be signed in to change notification settings - Fork 0
/
dump_games
executable file
·58 lines (53 loc) · 1.25 KB
/
dump_games
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/usr/bin/env coffee
Book = require './book'
{
Board
BLACK
WHITE
pos_from_str
pos_to_str
pos_array_to_str
pos_array_from_str
} = require './board'
{ unique_moves } = require './util'
{ encode_normalized } = require './encode'
argv = require 'yargs'
.options
b:
alias: 'book'
desc: 'Database file'
default: 'book.db'
h:
alias: 'help'
.strict()
.version false
.argv
visited = {}
book = new Book argv.book, readonly: true
book.init()
board = new Board
moves = []
replay = (turn) ->
unique = false
for move in unique_moves(board, turn)
flips = board.move turn, move
throw new Error "invalid move #{pos_to_str(move, turn)}" unless flips.length
code = encode_normalized(board)
outcome = book.get_game_node_by_code(code)
if outcome?
unless visited[code]
visited[code] = true
unique = true
moves.push {move, turn}
if board.any_moves(-turn)
replay -turn
else if board.any_moves(turn)
replay turn
else if unique
console.log pos_array_to_str(moves), outcome
unique = false
moves.pop()
board.undo turn, move, flips
board.move BLACK, pos_from_str('F5')
moves.push { turn:BLACK, move:pos_from_str('F5') }
replay WHITE