I just used the coordiantes of the grid to check all possible winning combinations.

This commit is contained in:
cdonahue
2025-11-17 09:32:53 -05:00
parent b58d15aa4a
commit 08b52bb799
3 changed files with 15 additions and 2 deletions

View File

@@ -2,7 +2,7 @@
## Checkpoint 1 Notes
play_ttt.py is the class responsible for each of the beahviors
game.py is the class responsible for each of the beahviors
Which class is responsible for each of the following behaviors?
For each, explain how the behavior is accomplished.
@@ -18,6 +18,8 @@ For each, explain how the behavior is accomplished.
## Checkpoint 2 Notes
I have no clue where im supposed to start but trial and error.
### TTT Strategy
For each of the following board states, if you are playing as X

View File

@@ -3,7 +3,8 @@ from ttt.view import TTTView
from ttt.player import TTTHumanPlayer, TTTComputerPlayer
player0 = TTTHumanPlayer("Player 1")
player1 = TTTHumanPlayer("Player 2")
# Play against the computer: make player1 a computer-controlled player.
player1 = TTTComputerPlayer("Computer")
game = TTTGame()
view = TTTView(player0, player1)

View File

@@ -58,4 +58,14 @@ class TTTGame:
def check_winner(self, state, symbol):
"Checks whether the player with `symbol` has won the game."
board = state["board"]
# All winning triplets (rows, columns, diagonals)
winning_combinations = [
(0, 1, 2), (3, 4, 5), (6, 7, 8), # rows
(0, 3, 6), (1, 4, 7), (2, 5, 8), # columns
(0, 4, 8), (2, 4, 6), # diagonals
]
for i, j, k in winning_combinations:
if board[i] == board[j] == board[k] == symbol:
return True
return False