generated from mwc/lab_tic_tac_toe
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:
@@ -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
|
||||
|
||||
@@ -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."
|
||||
|
||||
Reference in New Issue
Block a user