Add state arguments to Game methods

This commit is contained in:
Chris Proctor 2022-05-06 16:50:20 -04:00
parent 6ad2672bd3
commit 463c168405
1 changed files with 8 additions and 5 deletions

View File

@ -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