generated from mwc/lab_tic_tac_toe
I changed the check_winner method in game.py
(Checkpoint 2) What I changed I changed the method so that it would accurately determine if the player with the symbol passed through the parameter won. It does this by checking each possible way to win tic tac toe. Why I changed it I made the change so that the game could accurately determine which player won the game. Estimate for remaining time to finish assignment: [1 to 2 hours]
This commit is contained in:
parent
67a041b903
commit
0dbc59d637
6
notes.md
6
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
|
||||
|
|
19
ttt/game.py
19
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."
|
||||
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
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue