From 08b52bb7992740b997d80f6bb2d92bd699dae2fb Mon Sep 17 00:00:00 2001 From: cdonahue Date: Mon, 17 Nov 2025 09:32:53 -0500 Subject: [PATCH] I just used the coordiantes of the grid to check all possible winning combinations. --- notes.md | 4 +++- play_ttt.py | 3 ++- ttt/game.py | 10 ++++++++++ 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/notes.md b/notes.md index ea383f3..486f62f 100644 --- a/notes.md +++ b/notes.md @@ -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 diff --git a/play_ttt.py b/play_ttt.py index ef5530a..d5c79b6 100644 --- a/play_ttt.py +++ b/play_ttt.py @@ -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) diff --git a/ttt/game.py b/ttt/game.py index 2f0e302..b3be04d 100644 --- a/ttt/game.py +++ b/ttt/game.py @@ -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