Files
lab_tic_tac_toe/nim/view.py
root 9d0c6174ec (Commit summary. Replace this with a one-line description of this commit.)
All of nim
What I changed
(Replace this with a description of what you changed in this commit. This should be 1-2 sentences.)
Completed the nim game.
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.)
Made additions to work towards completing the game. Tried my best to make the game as properly functional as I could.
Estimate for remaining time to finish assignment: [0 minutes]
2024-02-22 08:51:45 -05:00

33 lines
953 B
Python

from nim.game_stub import NimGame
class NimView:
def __init__(self, player0, player1):
self.players = [player0, player1]
self.game = NimGame()
def greet(self):
print(f"{self.players[0].name} and {self.players[1].name}, welcome to Nim.")
def show_board(self, state):
for lines_in_row in state["board"]:
print("| " * lines_in_row)
def get_action(self, state):
self.show_board(state)
player = self.get_current_player(state)
return player.choose_action(state)
def get_current_player(self, state):
if state["first_player"]:
return self.players[0]
else:
return self.players[1]
def conclude(self, state):
self.show_board(state)
if self.game.get_reward(state) > 0:
winner = self.players[0]
else:
winner = self.players[1]
print(f"Congratulations, {winner.name}!")