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:
parent
b5ab43b8b8
commit
c1b40db3e1
14
notes.md
14
notes.md
|
@ -30,15 +30,23 @@ available actions generated
|
|||
For each of the following board states, if you are playing as X
|
||||
and it's your turn, which action would you take? Why?
|
||||
|
||||
| O | O | | O | X | X | O |
|
||||
| O | O | | O x | X | X | O |
|
||||
---+---+--- ---+---+--- ---+---+--- ---+---+---
|
||||
X | X | | X | X | O | O | |
|
||||
X | X | x | X | x X | O | O | x |
|
||||
---+---+--- ---+---+--- ---+---+--- ---+---+---
|
||||
| | | | O | | | |
|
||||
| | | | O | | | |
|
||||
|
||||
For #1, choosing 6 wins the game. For #2, choosing 6 blocks O from winning.
|
||||
For #3, choosing 0 gives a win on the next turn regardless of where O blocks.
|
||||
For #4, choosing 4 means O has to block, then if X chooses 6 on the next turn,
|
||||
there is a guaranteed win in 2 or 3 regardless of where O blocks.
|
||||
|
||||
### Initial game state
|
||||
|
||||
You can get the inital game state using game.get_initial_state().
|
||||
What is the current and future reward for this state? What does this mean?
|
||||
|
||||
The current and future reward for this state is 0 which tells me there are as many
|
||||
games where x wins as loses and most games end in a draw? Does this mean it's a
|
||||
fair game?
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@ from ttt.view import TTTView
|
|||
from ttt.player import TTTHumanPlayer, TTTComputerPlayer
|
||||
|
||||
player0 = TTTHumanPlayer("Player 1")
|
||||
player1 = TTTHumanPlayer("Player 2")
|
||||
player1 = TTTComputerPlayer("Robot")
|
||||
game = TTTGame()
|
||||
view = TTTView(player0, player1)
|
||||
|
||||
|
|
|
@ -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."
|
||||
|
|
Loading…
Reference in New Issue