generated from mwc/lab_tic_tac_toe
Submission for tic tac toe lab.
What I changed I completed checkpoints 1-3. I would have submitted all three separately, but a bug prohibited my initial submissions. I also started working on the nim section of the lab. Why I changed it I made these changes in order to make a functions tic tac toe and nim game. Estimate for remaining time to finish assignment: 15 minutes
This commit is contained in:
20
ttt/game.py
20
ttt/game.py
@@ -58,4 +58,22 @@ class TTTGame:
|
||||
|
||||
def check_winner(self, state, symbol):
|
||||
"Checks whether the player with `symbol` has won the game."
|
||||
return False
|
||||
board = state["board"]
|
||||
if board[0] == symbol and board[1] == symbol and board[2] == symbol:
|
||||
return True
|
||||
elif board[3] == symbol and board[4] == symbol and board[5] == symbol:
|
||||
return True
|
||||
elif board[6] == symbol and board[7] == symbol and board[8] == symbol:
|
||||
return True
|
||||
elif board[0] == symbol and board[3] == symbol and board[6] == symbol:
|
||||
return True
|
||||
elif board[1] == symbol and board[4] == symbol and board[7] == symbol:
|
||||
return True
|
||||
elif board[2] == symbol and board[5] == symbol and board[8] == symbol:
|
||||
return True
|
||||
elif board[0] == symbol and board[4] == symbol and board[8] == symbol:
|
||||
return True
|
||||
elif board[2] == symbol and board[4] == symbol and board[6] == symbol:
|
||||
return True
|
||||
else:
|
||||
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(), deterministic=False)
|
||||
|
||||
def choose_action(self, state):
|
||||
"Chooses a random move from the moves available."
|
||||
|
||||
Reference in New Issue
Block a user