generated from mwc/lab_tic_tac_toe
Kathryn Odell-Hamilton
All the Checkpoints answered within the notes.md file.
This commit is contained in:
parent
71df2cf2b8
commit
0929ab7173
77
notes.md
77
notes.md
|
@ -1,4 +1,5 @@
|
|||
# Tic Tac Toe notes
|
||||
Kathryn Odell-Hamilton
|
||||
|
||||
## Checkpoint 1 Notes
|
||||
|
||||
|
@ -6,13 +7,62 @@ Which class is responsible for each of the following behaviors?
|
|||
For each, explain how the behavior is accomplished.
|
||||
|
||||
### Checking to see whether the game is over
|
||||
The Class is
|
||||
class TTTGame:
|
||||
"Models a tic-tac-toe game."
|
||||
|
||||
def is_over(self, state):
|
||||
"Checks whether the game is over."
|
||||
|
||||
### Determining which actions are available at a particular state
|
||||
The Class is
|
||||
class TTTGame:
|
||||
"Models a tic-tac-toe game."
|
||||
|
||||
def get_actions(self, state):
|
||||
"Returns a list of the indices of empty spaces"
|
||||
return [index for index in range(9) if state["board"][index] == '-']
|
||||
|
||||
Can it also be considered this in addition?
|
||||
|
||||
def get_next_state(self, state, action):
|
||||
"""Given a state and an action, returns the resulting state.
|
||||
In the resulting state, the current player's symbol has been placed
|
||||
in an empty board space, and it is the opposite player's turn."""
|
||||
new_board = state["board"].copy()
|
||||
new_board[action] = 'X' if state["player_x"] else 'O'
|
||||
return {
|
||||
"board": new_board,
|
||||
"player_x": not state["player_x"],
|
||||
}
|
||||
|
||||
### Showing the board
|
||||
The Class is
|
||||
class TTTView:
|
||||
|
||||
def get_initial_state(self):
|
||||
"Returns the game's initial state."
|
||||
"Represents an empty tic-tac-toe board where player X starts the game.”
|
||||
return {
|
||||
"board": ['-', '-', '-', '-', '-', '-', '-', '-', '-'],
|
||||
"player_x": True,
|
||||
}
|
||||
|
||||
### Choosing which action to play on a turn
|
||||
The Class is
|
||||
class TTTView:
|
||||
|
||||
def get_next_state(self, state, action):
|
||||
"""Given a state and an action, returns the resulting state.
|
||||
In the resulting state, the current player's symbol has been placed
|
||||
in an empty board space, and it is the opposite player's turn.
|
||||
"""
|
||||
new_board = state["board"].copy()
|
||||
new_board[action] = 'X' if state["player_x"] else 'O'
|
||||
return {
|
||||
"board": new_board,
|
||||
"player_x": not state["player_x"],
|
||||
}
|
||||
|
||||
## Checkpoint 2 Notes
|
||||
|
||||
|
@ -27,9 +77,36 @@ and it's your turn, which action would you take? Why?
|
|||
---+---+--- ---+---+--- ---+---+--- ---+---+---
|
||||
| | | | O | | | |
|
||||
|
||||
First Game:
|
||||
I would choose “X” is middle row, last right column.
|
||||
It’s the most obvious choice to get “3 X’s” in a row.
|
||||
|
||||
Second Game:
|
||||
I would choose “X” in 3rd column, 2nd row.
|
||||
I’m going to block “O” from getting a vertical 3 in a row in 3rd column.
|
||||
|
||||
Third Game:
|
||||
I would choose “X” in 1st column, 1st row.
|
||||
“O” will lose the game, unable to block “X” from winning. Whether “O” chooses either 3rd column/1st row or 1st column/3rd row. “X” will choose the other empty spot to win.
|
||||
|
||||
Fourth Game:
|
||||
I would choose “X” in very middle of game board, 2nd column/2nd row.
|
||||
No matter how “0” tries to block 3 in a row, “X” will win. “X” will have the advantage of 3 in a row vertical, diagonal, or horizontal.
|
||||
|
||||
### 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?
|
||||
|
||||
Begins in file:
|
||||
play_tt.py “state = game.get_initial_state()”
|
||||
|
||||
This is returning the games initial state
|
||||
|
||||
Next in file:
|
||||
game.py. “def get_initial_state(self):”
|
||||
|
||||
Is returning the game's initial state with the Tic Tac Toe board ready for the 1st player to play the initial round.
|
||||
Within “next state” there is a Boolean of True to see if it’s “X’s” turn and if not it’s “0’s” turn to play. The future reward for the state is that the game proceeds and updates until the all spots have been used by both player with an outcome of a winner or not.
|
||||
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
@ -13,3 +13,7 @@ while not game.is_over(state):
|
|||
action = view.get_action(state)
|
||||
state = game.get_next_state(state, action)
|
||||
view.conclude(state)
|
||||
|
||||
|
||||
"""Playing Computer, Robot didn't have the correct outcome. Player 1, "X" won, but
|
||||
game continued to play with no winner. It didn't work."""
|
|
@ -1,15 +1,14 @@
|
|||
# This file is automatically @generated by Poetry 1.4.0 and should not be changed by hand.
|
||||
# This file is automatically @generated by Poetry 1.5.1 and should not be changed by hand.
|
||||
|
||||
[[package]]
|
||||
name = "click"
|
||||
version = "8.1.3"
|
||||
version = "8.1.7"
|
||||
description = "Composable command line interface toolkit"
|
||||
category = "main"
|
||||
optional = false
|
||||
python-versions = ">=3.7"
|
||||
files = [
|
||||
{file = "click-8.1.3-py3-none-any.whl", hash = "sha256:bb4d8133cb15a609f44e8213d9b391b0809795062913b383c62be0ee95b1db48"},
|
||||
{file = "click-8.1.3.tar.gz", hash = "sha256:7682dc8afb30297001674575ea00d1814d808d6a36af415a82bd481d37ba7b8e"},
|
||||
{file = "click-8.1.7-py3-none-any.whl", hash = "sha256:ae74fb96c20a0277a1d615f1e4d73c8414f5a98db8b799a7931d1582f3390c28"},
|
||||
{file = "click-8.1.7.tar.gz", hash = "sha256:ca9853ad459e787e2192211578cc907e7594e294c7ccc834310722b41b9ca6de"},
|
||||
]
|
||||
|
||||
[package.dependencies]
|
||||
|
@ -19,7 +18,6 @@ colorama = {version = "*", markers = "platform_system == \"Windows\""}
|
|||
name = "colorama"
|
||||
version = "0.4.6"
|
||||
description = "Cross-platform colored terminal text."
|
||||
category = "main"
|
||||
optional = false
|
||||
python-versions = "!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,!=3.4.*,!=3.5.*,!=3.6.*,>=2.7"
|
||||
files = [
|
||||
|
|
Binary file not shown.
Binary file not shown.
23
ttt/game.py
23
ttt/game.py
|
@ -58,4 +58,27 @@ class TTTGame:
|
|||
|
||||
def check_winner(self, state, symbol):
|
||||
"Checks whether the player with `symbol` has won the game."
|
||||
"""Seems to be an issue because the code looks incomplete.
|
||||
In the View, it shows the Player's choice/symbol placed on the Tic Tac Toe
|
||||
board as a winner, but doesn't announce the Player as the winner, the Game
|
||||
keeps playing as though there is no winner. The Game doesn't recognize that the
|
||||
Player has "3 symbols in a row," this should stop the game to determine the winner.
|
||||
The Game doesn't state in the "View" that the current Player is the winner.
|
||||
"""
|
||||
|
||||
board = state["board"]
|
||||
for row in range(3):
|
||||
if all(board[row * 3 + col] == symbol for col in range(3)):
|
||||
return True
|
||||
for col in range(3):
|
||||
if all(board[row + col * 3] == symbol for row in range(3)):
|
||||
return True
|
||||
if board[0] == board[4] == board[8] == symbol or board[2] == board[4] == board[6] == symbol:
|
||||
return True
|
||||
return False
|
||||
|
||||
"""I played the game.
|
||||
Message
|
||||
Well, that's a wrap.
|
||||
Congratulations to Player 1.
|
||||
"""
|
||||
|
|
|
@ -9,6 +9,8 @@ class TTTView:
|
|||
x_color = "red"
|
||||
o_color = "blue"
|
||||
option_color = "bright_black"
|
||||
"""Added winner. Not sure if correct."""
|
||||
winner = "You have won the game!"
|
||||
|
||||
def __init__(self, playerX, playerO):
|
||||
self.game = TTTGame()
|
||||
|
|
Loading…
Reference in New Issue