diff --git a/chess.py b/chess.py index bd42a7f..7392d06 100644 --- a/chess.py +++ b/chess.py @@ -130,7 +130,9 @@ class Game: "black" : {"queen" : True, "king" : True} } - self.history.append(deepcopy(self)) + self.history.append((deepcopy(self.can_castle), + deepcopy(self.board), + self.turn)) def __repr__(self): # Unicode board representation @@ -173,10 +175,10 @@ class Game: def timetravel(self, i): if i >= len(self.history) or i < 0: return False - new = self.history[i] - self.board = new.board - self.turn = new.turn - self.can_castle = new.can_castle + c, board, turn = self.history[i] + self.board = board + self.turn = turn + self.can_castle = c self.index = i def prev(self): @@ -253,7 +255,9 @@ class Game: self.can_castle[color]["king"] = False self.moves.append(king_move) self.turn = invert(self.turn) - self.history.append(deepcopy(self)) + self.history.append((deepcopy(self.can_castle), + deepcopy(self.board), + self.turn)) self.index += 1 return True @@ -297,7 +301,9 @@ class Game: self.board = new.board self.can_castle = new.can_castle self.turn = invert(moved.color) - self.history.append(deepcopy(self)) + self.history.append((deepcopy(self.can_castle), + deepcopy(self.board), + self.turn)) self.index += 1 return True