def perform_move(self, state, d, maximizing_player): # ->succ_state i = state.pos[0] + d[0] j = state.pos[1] + d[1] new_pos = (i, j) self.board[state.pos] = -1 new_player_to_move = utils.nextTurn(state.playerToMove) new_fruit_life = max(0, state.fruit_life - 1) fruit_taken = 0 if new_fruit_life > 0: fruit_taken = self.board[new_pos] self.board[new_pos] = state.playerToMove penalty_taken = 0 if not utils.playerCanMove(self.board, new_pos) and utils.playerCanMove( self.board, state.rival_pos): penalty_taken = self.penalty_score self.score[state.playerToMove - 1] = self.score[ state.playerToMove - 1] + fruit_taken - penalty_taken # the fruit was on my pos + penalty if there any return Player.PlayerState(self.board, new_player_to_move, new_fruit_life, fruit_taken, penalty_taken)
def goal(self, state): return not utils.playerCanMove(self.board, state.pos)