generated from mwc/lab_tic_tac_toe
I just used the coordiantes of the grid to check all possible winning combinations.
This commit is contained in:
4
notes.md
4
notes.md
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
## Checkpoint 1 Notes
|
## Checkpoint 1 Notes
|
||||||
|
|
||||||
play_ttt.py is the class responsible for each of the beahviors
|
game.py is the class responsible for each of the beahviors
|
||||||
|
|
||||||
Which class is responsible for each of the following behaviors?
|
Which class is responsible for each of the following behaviors?
|
||||||
For each, explain how the behavior is accomplished.
|
For each, explain how the behavior is accomplished.
|
||||||
@@ -18,6 +18,8 @@ For each, explain how the behavior is accomplished.
|
|||||||
|
|
||||||
## Checkpoint 2 Notes
|
## Checkpoint 2 Notes
|
||||||
|
|
||||||
|
I have no clue where im supposed to start but trial and error.
|
||||||
|
|
||||||
### TTT Strategy
|
### TTT Strategy
|
||||||
|
|
||||||
For each of the following board states, if you are playing as X
|
For each of the following board states, if you are playing as X
|
||||||
|
|||||||
@@ -3,7 +3,8 @@ from ttt.view import TTTView
|
|||||||
from ttt.player import TTTHumanPlayer, TTTComputerPlayer
|
from ttt.player import TTTHumanPlayer, TTTComputerPlayer
|
||||||
|
|
||||||
player0 = TTTHumanPlayer("Player 1")
|
player0 = TTTHumanPlayer("Player 1")
|
||||||
player1 = TTTHumanPlayer("Player 2")
|
# Play against the computer: make player1 a computer-controlled player.
|
||||||
|
player1 = TTTComputerPlayer("Computer")
|
||||||
game = TTTGame()
|
game = TTTGame()
|
||||||
view = TTTView(player0, player1)
|
view = TTTView(player0, player1)
|
||||||
|
|
||||||
|
|||||||
10
ttt/game.py
10
ttt/game.py
@@ -58,4 +58,14 @@ class TTTGame:
|
|||||||
|
|
||||||
def check_winner(self, state, symbol):
|
def check_winner(self, state, symbol):
|
||||||
"Checks whether the player with `symbol` has won the game."
|
"Checks whether the player with `symbol` has won the game."
|
||||||
|
board = state["board"]
|
||||||
|
# All winning triplets (rows, columns, diagonals)
|
||||||
|
winning_combinations = [
|
||||||
|
(0, 1, 2), (3, 4, 5), (6, 7, 8), # rows
|
||||||
|
(0, 3, 6), (1, 4, 7), (2, 5, 8), # columns
|
||||||
|
(0, 4, 8), (2, 4, 6), # diagonals
|
||||||
|
]
|
||||||
|
for i, j, k in winning_combinations:
|
||||||
|
if board[i] == board[j] == board[k] == symbol:
|
||||||
|
return True
|
||||||
return False
|
return False
|
||||||
|
|||||||
Reference in New Issue
Block a user