generated from mwc/lab_tic_tac_toe
This submit dealt with the problems of not
determining a winner and always ending with a tie regardless of the outcome. What I changed I looked to find all of the possible win scenarios, which took some time to determine. I then utilized several loops to ensure a winner is declared when three in a row is earned. Why I changed it While perhaps not done in the most proficient way, this helped to map out each of the win scenarios while still understanding it at the surface level. Estimate for remaining time to finish assignment: [2-4 hours depending on peer assistance]
This commit is contained in:
parent
46e45b2b6f
commit
b84640e4b3
2
notes.md
2
notes.md
|
@ -14,7 +14,7 @@ The board is shown using TTTView with the methods for print_board() and get_acti
|
||||||
### Choosing which action to play on a turn
|
### Choosing which action to play on a turn
|
||||||
A player can choose which action to play on a turn from within the TTTHumanPlayer with the method for choose_action().
|
A player can choose which action to play on a turn from within the TTTHumanPlayer with the method for choose_action().
|
||||||
|
|
||||||
## Checkpoint 2 Notes
|
## Checkpoint 3 Notes
|
||||||
|
|
||||||
### TTT Strategy
|
### TTT Strategy
|
||||||
|
|
||||||
|
|
11
ttt/game.py
11
ttt/game.py
|
@ -58,4 +58,15 @@ class TTTGame:
|
||||||
|
|
||||||
def check_winner(self, state, symbol):
|
def check_winner(self, state, symbol):
|
||||||
"Checks whether the player with `symbol` has won the game."
|
"Checks whether the player with `symbol` has won the game."
|
||||||
|
currentState = state["board"]
|
||||||
|
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
|
return False
|
||||||
|
|
Loading…
Reference in New Issue