My biggest frustration occurred when I ran the minimax unit test. Clearly, errors were returned, which wiped out my dignity as a programming student. Ha, ha, ha...
In A2, the minimax we wrote only worked for Subtract the Square, but not with Tippy.
I suspected that something was wrong with TippyGameState. Indeed, it was!
I realized the mistake after debugging from GameView (the overall program for running the game):
while not self.state.over:
if self.state.next_player == 'p1':
m = self.state.get_move()
while not m in self.state.possible_next_moves:
# The move was illegal.
print('Illegal move: {}\nPlease try again.\n'.format(m))
print(self.state.instructions)
print(self.state)
m = self.state.get_move()
print('You choose: {}'.format(m))
else:
# The computer makes a move.
m = self.strategy.suggest_move(self.state)
print(m)
print('The computer chooses: {}'.format(m))
self.state = self.state.apply_move(m)
print('New game state: ', str(self.state))
print()
When the game is played, the first round would work. Self.possible_next_moves would return a list of all the possible moves available initially in the game.
However, the problem occurs in apply_move, that it does not properly modify self.possible_next_moves.
I tried to modify possible_next_moves every time apply_move is called. However, for some reason, possible_next_moves remain constant.
Basically, the mistake made was keeping a list of possible moves as a variable within the object. Hence I'm mutating it as game states change. This is a very bad idea because the default when create in the object is the original game state( with all possible moves in the initial state).
UPDATE: I think another mistake I made was not reading the code provided by the instructors first in Subtract the Square. In the exemplary file, possible_next_moves is actually a method! Ooops... In the future, I must take more precaution!
-----------------------------------------------EXOCOETIDAEE---I--AM--A--LINE----------------------------







