diff --git a/play_ttt.py b/play_ttt.py index 2ecaba1..24a123f 100644 --- a/play_ttt.py +++ b/play_ttt.py @@ -10,13 +10,16 @@ player1 = TTTHumanPlayer("Player 2") game = TTTGame() view = TTTView(player0, player1) +#creates initial state state = game.get_initial_state() view.greet() """ while loop that checks if game is over if its not... """ +#gets passed blank board while not game.is_over(state): + #take action and update board action = view.get_action(state) state = game.get_next_state(state, action) view.conclude(state) diff --git a/ttt/game.py b/ttt/game.py index 2f0e302..13dc3f1 100644 --- a/ttt/game.py +++ b/ttt/game.py @@ -22,6 +22,7 @@ class TTTGame: def get_actions(self, state): "Returns a list of the indices of empty spaces" + #False bc blank #false bc no makers #false because no markers return [index for index in range(9) if state["board"][index] == '-'] def is_over(self, state): @@ -58,4 +59,17 @@ class TTTGame: def check_winner(self, state, symbol): "Checks whether the player with `symbol` has won the game." + currentState = state["board"] + #possible tictactoes: 012 345 678 036 147 258 048 246 + for i in range(0, 7, 3): + if currentState[i] == symbol and currentState[i + 1] == symbol and currentState[i+2] == symbol: + return True + for i in range(3): + if currentState[i] == symbol and currentState[i+3] == symbol and currentState[i+6] == symbol: + return True + if currentState[0] == symbol and currentState[4] == symbol and currentState[8] == symbol: + return True + if currentState[2] == symbol and currentState[4] == symbol and currentState[6] ==symbol: + return True + return False