Included gomill framework for SGF and GTP support, and sketched out SGF game-loading code.

This commit is contained in:
2012-04-21 04:27:05 -04:00
parent 700a6a2f32
commit 692dc294d6
119 changed files with 27458 additions and 3 deletions

View File

@ -1,3 +1,6 @@
import gomill.sgf
class Goban:
"""Represents the go board. Handles stone placement, captures, etc"""
@ -11,12 +14,18 @@ class Goban:
SCORING=6
def __init__(self, board_size=19):
def __init__(self, board_size=19, file_name=None):
# Build the board intersections
self.board_size = board_size
num_points = board_size * board_size
self.board = [Goban.EMPTY] * num_points
self.file_name = file_name
self.sgf_game = None
if self.file_name is not None:
self.load_sgf(file_name)
self.def_draw_codes = self._make_default_draw_codes()
self.to_move = Goban.BLACK
@ -30,6 +39,23 @@ class Goban:
self.winner = Goban.EMPTY
def load_sgf(self):
try:
with open(self.file_name, 'r') as fn:
self.sgf_game = sgf.Sgf_game.from_string(fn.read())
except IOError:
# fixme - this should be convertable into a dialog box... perhaps it should throw an exception of its own
print 'There was a problem loading the SGF file.'
for node in self.sgf_game.get_main_sequence():
color, pos = node.get_move()
if color == 'b':
color = Goban.BLACK
elif color == 'w':
color = Goban.WHITE
self.play_move(color, pos)
def set_hover(self, pos):
rpos = self._real_pos(pos)
if rpos == self.hover: