generated from mwc/lab_tic_tac_toe
Made the computer player smart. Only cats games.
What I changed Updated the LookaheadStrategy for the computer player Why I changed it In this case, we weren't asked to develop the strategy (thankfully!) but instead just tasked with pointing the computer player class to using that strategy instead of making a random choice. Estimate for remaining time to finish assignment: [Time for Nim?]
This commit is contained in:
@@ -67,9 +67,9 @@ class TTTGame:
|
||||
for i in range(3):
|
||||
if currentState[i] == symbol and currentState[i+3] == symbol and currentState[i+6] == symbol:
|
||||
return True
|
||||
if currentState[0] == symbol and currentState[4] == symbol and currentState[8] == symbol:
|
||||
if currentState[4] == symbol and currentState[0] == symbol and currentState[8] == symbol:
|
||||
return True
|
||||
if currentState[2] == symbol and currentState[4] == symbol and currentState[6] == symbol:
|
||||
if currentState[4] == symbol and currentState[2] == symbol and currentState[6] == symbol:
|
||||
return True
|
||||
|
||||
return False
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
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 +24,7 @@ class TTTComputerPlayer:
|
||||
def __init__(self, name):
|
||||
"Sets up the player."
|
||||
self.name = name
|
||||
self.strategy = RandomStrategy(TTTGame())
|
||||
self.strategy = LookaheadStrategy(TTTGame(), deterministic=False)
|
||||
|
||||
def choose_action(self, state):
|
||||
"Chooses a random move from the moves available."
|
||||
|
||||
Reference in New Issue
Block a user