I found a mistake in the check_winner() function.

It was working only with three or less X or O signs.
I have changed it to work for all combinations
This commit is contained in:
Seoyeon Lee
2024-12-15 16:51:49 -05:00
parent 740872f7b6
commit adf951b53f
4 changed files with 12 additions and 5 deletions

View File

@@ -61,6 +61,8 @@ class TTTGame:
winning_combinations=[[0,1,2],[3,4,5],[6,7,8],[0,3,6],[1,4,7],[2,5,8],[0,4,8],[2,4,6]]
board=state["board"]
combination=[index for index in range(9) if board[index]==symbol]
if combination in winning_combinations:
return True
for combo in winning_combinations:
tot = sum([board[index] == symbol for index in combo])
if tot == 3:
return True
return False

View File

@@ -1,5 +1,6 @@
from click import Choice, prompt
from strategy.random_strategy import RandomStrategy
from strategy.lookahead_strategy import LookaheadStrategy
from ttt.game import TTTGame
import random
@@ -24,7 +25,7 @@ class TTTComputerPlayer:
def __init__(self, name):
"Sets up the player."
self.name = name
self.strategy = RandomStrategy(TTTGame())
self.strategy = LookaheadStrategy(TTTGame())
def choose_action(self, state):
"Chooses a random move from the moves available."