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:
Justin Toombs 2024-02-12 21:50:12 -05:00
parent 46e45b2b6f
commit b84640e4b3
2 changed files with 12 additions and 1 deletions

View File

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

View File

@ -58,4 +58,15 @@ class TTTGame:
def check_winner(self, state, symbol):
"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