Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add GameNode and Game.

  • Loading branch information...
commit 70dffd816058c9efbd9460043fd73cead0ea8356 1 parent d8addb2
@niklasf authored
Showing with 64 additions and 0 deletions.
  1. +15 −0 chess/game.py
  2. +49 −0 chess/game_node.py
View
15 chess/game.py
@@ -0,0 +1,15 @@
+import chess
+
+class Game(chess.GameNode):
+ def __init__(self, position=chess.Position(), comment=""):
+ chess.GameNode.__init__(self, None, None, (), comment)
+ self._position = position
+
+ def get_nags(self):
+ raise Exception("Game object can not have NAGs.")
+
+ def add_nag(self, nag):
+ raise Exception("Game object can not have NAGs.")
+
+ def remove_nag(self, nag):
+ raise Exception("Game object can not have NAGs.")
View
49 chess/game_node.py
@@ -0,0 +1,49 @@
+class GameNode(object):
+ def __init__(self, previous_node, move, nags=[], comment=""):
+ self._previous_node = previous_node
+ self._move = move
+
+ if previous_node and previous_node.get_position():
+ self._position = previous_node.get_position().copy()
+ self._position.make_move(self._move)
+
+ self._nags = nags
+ self._comment = comment
+ self._variations = []
+
+ def get_move(self):
+ return self._move
+
+ def get_position(self):
+ return self._position
+
+ def get_nags(self):
+ return tuple(self._nags)
+
+ def add_nag(self, nag):
+ if not nag in self._nags:
+ self._nags.append(nag)
+
+ def remove_nag(self, nag):
+ self._nags.remove(nag)
+
+ def get_comment(self):
+ return self._comment
+
+ def set_comment(self, comment):
+ self._comment = comment
+
+ def get_variations(self):
+ return tuple(self._variations)
+
+ def add_variation(self, node):
+ if not node in self._variations:
+ self._variations.append(node)
+
+ def add_main_variation(self, node):
+ if node in self._variations:
+ self._variations.remove(node)
+ self._variations.insert(0, node)
+
+ def remove_variation(self, node):
+ self._variations.remove(node)
Please sign in to comment.
Something went wrong with that request. Please try again.