diff --git a/notes.md b/notes.md index e278c19..72b3a73 100644 --- a/notes.md +++ b/notes.md @@ -16,7 +16,11 @@ The player class contains the choose_action method which allows the player to choose whicn place to play. ## Checkpoint 2 Notes - +I was able to get the game to correctly determine who the winner was. I understand that there's +an array that I'm accessing, and that indexes 0 through 9 correspond to the different spaces on the +board starting on the top left and going across the row, then down to the left of the next row, etc. +What I do not understand is what state is and why we need to use state["board"][index] to access +something on the boare ### TTT Strategy For each of the following board states, if you are playing as X diff --git a/ttt/game.py b/ttt/game.py index 2f0e302..1db20cd 100644 --- a/ttt/game.py +++ b/ttt/game.py @@ -58,4 +58,23 @@ class TTTGame: def check_winner(self, state, symbol): "Checks whether the player with `symbol` has won the game." - return False + if state["board"][0]==symbol and state["board"][1]==symbol and state["board"][2]==symbol: + return True + elif state["board"][3]==symbol and state["board"][4]==symbol and state["board"][5]==symbol: + return True + elif state["board"][6]==symbol and state["board"][7]==symbol and state["board"][8]==symbol: + return True + elif state["board"][0]==symbol and state["board"][3]==symbol and state["board"][6]==symbol: + return True + elif state["board"][1]==symbol and state["board"][4]==symbol and state["board"][7]==symbol: + return True + elif state["board"][2]==symbol and state["board"][5]==symbol and state["board"][8]==symbol: + return True + elif state["board"][0]==symbol and state["board"][4]==symbol and state["board"][8]==symbol: + return True + elif state["board"][2]==symbol and state["board"][4]==symbol and state["board"][6]==symbol: + return True + else: + return False + +