From ca1c55868603c1d24ab131e1f8256c30ec19461f Mon Sep 17 00:00:00 2001 From: root Date: Wed, 14 Feb 2024 21:46:08 -0500 Subject: [PATCH] completed checkpoint 2 What I changed I added the logic to check if someone won the game. Why I changed it The goal was to make it so the code could tell if a there was a winner at each point in the game. I figured the easiest way I could implement this accessing the list then using if statements. Estimate for remaining time to finish assignment: 1 hour --- ttt/game.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/ttt/game.py b/ttt/game.py index 2f0e302..49c4e9b 100644 --- a/ttt/game.py +++ b/ttt/game.py @@ -58,4 +58,21 @@ class TTTGame: def check_winner(self, state, symbol): "Checks whether the player with `symbol` has won the game." + b=state['board'] + if b[0]==symbol and b[3]==symbol and b[6]==symbol: + return True + if b[1]==symbol and b[4]==symbol and b[7]==symbol: + return True + if b[2]==symbol and b[5]==symbol and b[8]==symbol: + return True + if b[0]==symbol and b[1]==symbol and b[2]==symbol: + return True + if b[3]==symbol and b[4]==symbol and b[5]==symbol: + return True + if b[6]==symbol and b[7]==symbol and b[8]==symbol: + return True + if b[0]==symbol and b[4]==symbol and b[8]==symbol: + return True + if b[2]==symbol and b[4]==symbol and b[6]==symbol: + return True return False