From 463c168405761c73de8f74cb25fa5823a17a7ab2 Mon Sep 17 00:00:00 2001 From: Chris Proctor Date: Fri, 6 May 2022 16:50:20 -0400 Subject: [PATCH] Add state arguments to Game methods --- ttt_game.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/ttt_game.py b/ttt_game.py index dfbb574..cdf7463 100644 --- a/ttt_game.py +++ b/ttt_game.py @@ -35,9 +35,9 @@ class TTTGame: "Returns a list of the indices of empty spaces" return [index for index in range(9) if state["board"][index] == '-'] - def is_over(self): + def is_over(self, state): "Checks whether the game is over." - return self.board_is_full() or self.check_winner('X') or self.check_winner('O') + return self.board_is_full(state) or self.check_winner(state, 'X') or self.check_winner(state, 'O') def get_reward(self, state): """Determines the reward associated with reaching this state. @@ -73,13 +73,16 @@ class TTTGame: "Checks whether a move is valid" return move in self.get_valid_moves() - def board_is_full(self): + def board_is_full(state, self): "Checks whether all the spaces in the board are occupied." - for space in self.state["board"]: + for space in state["board"]: if space == '-': return False return True - def check_winner(self, symbol): + def check_winner(self, state, symbol): "Checks whether the player with `symbol` has won the game." return False + + +