generated from mwc/lab_tic_tac_toe
(Commit summary. Replace this with a one-line description of this commit.)
checkpoint 2 win condition. What I changed (Replace this with a description of what you changed in this commit. This should be 1-2 sentences.) added tictactoe win conditions Why I changed it (Describe why you made these changes. Were you working toward a goal? Did you reorganize your code? This should be 1-2 sentences.) working in order to add win conditions. Estimate for remaining time to finish assignment: [2 days]
This commit is contained in:
14
ttt/game.py
14
ttt/game.py
@@ -22,6 +22,7 @@ class TTTGame:
|
||||
|
||||
def get_actions(self, state):
|
||||
"Returns a list of the indices of empty spaces"
|
||||
#False bc blank #false bc no makers #false because no markers
|
||||
return [index for index in range(9) if state["board"][index] == '-']
|
||||
|
||||
def is_over(self, state):
|
||||
@@ -58,4 +59,17 @@ class TTTGame:
|
||||
|
||||
def check_winner(self, state, symbol):
|
||||
"Checks whether the player with `symbol` has won the game."
|
||||
currentState = state["board"]
|
||||
#possible tictactoes: 012 345 678 036 147 258 048 246
|
||||
for i in range(0, 7, 3):
|
||||
if currentState[i] == symbol and currentState[i + 1] == symbol and currentState[i+2] == symbol:
|
||||
return True
|
||||
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:
|
||||
return True
|
||||
if currentState[2] == symbol and currentState[4] == symbol and currentState[6] ==symbol:
|
||||
return True
|
||||
|
||||
return False
|
||||
|
||||
Reference in New Issue
Block a user