# Path: simpleai/environments.py
# class RLEnvironment(Environment):
# 
#     def __init__(self, agents, initial_state):
#         super(RLEnvironment, self).__init__(agents, initial_state)
# 
#     def step(self, viewer=None):
#         super(RLEnvironment, self).step(viewer)
#         for agent in self.agents:
#             agent.set_reward(self.reward(self.state, agent), self.is_completed(self.state))
# 
#     def reward(self, state, agent):
#         raise NotImplementedError()


from simpleai.machine_learning.reinforcement_learning import TDQLearner, RLProblem, \
                                                             make_exponential_temperature, \
                                                             PerformanceCounter
from simpleai.environments import RLEnvironment
import random
        rows = state.split()
        columns = [''.join(x) for x in zip(*rows)]
        diagonals = [rows[0][0] + rows[1][1] + rows[2][2], rows[0][2] + rows[1][1] + rows[2][0]]
        to_check = rows + columns + diagonals
        for x in to_check:
            if all([c == x[0] for c in x]) and x[0] != '_':
                if x[0] == agent.play_with:
                    return 1
                else:
                    return -1
        return 0


if __name__ == '__main__':
    a = TicTacToePlayer('X')
    b = RandomPlayer('O')
    c = HumanPlayer('O')
    game = TicTacToeGame([a, b])
    print('Training with a random player, please wait...')
    game.agents = [a, b]
    for i in range(3000):
        game.run()

    a.dump('qlearner_agent')

    d = TicTacToePlayer.load('qlearner_agent')
    d.play_with = 'O'

    game.agents = [a, d]
    per = PerformanceCounter(game.agents, ['QLearnerA', 'QLearnerD'])

# Path: simpleai/environments.py
# class RLEnvironment(Environment):
# 
#     def __init__(self, agents, initial_state):
#         super(RLEnvironment, self).__init__(agents, initial_state)
# 
#     def step(self, viewer=None):
#         super(RLEnvironment, self).step(viewer)
#         for agent in self.agents:
#             agent.set_reward(self.reward(self.state, agent), self.is_completed(self.state))
# 
#     def reward(self, state, agent):
#         raise NotImplementedError()


# Path: samples/machine_learning/tic_tac_toe.py
from simpleai.machine_learning.reinforcement_learning import TDQLearner, RLProblem, \
                                                             make_exponential_temperature, \
                                                             PerformanceCounter
from simpleai.environments import RLEnvironment
import random

        rows = state.split()
        columns = [''.join(x) for x in zip(*rows)]
        diagonals = [rows[0][0] + rows[1][1] + rows[2][2], rows[0][2] + rows[1][1] + rows[2][0]]
        to_check = rows + columns + diagonals
        for x in to_check:
            if all([c == x[0] for c in x]) and x[0] != '_':
                if x[0] == agent.play_with:
                    return 1
                else:
                    return -1
        return 0


if __name__ == '__main__':
    a = TicTacToePlayer('X')
    b = RandomPlayer('O')
    c = HumanPlayer('O')
    game = TicTacToeGame([a, b])
    print('Training with a random player, please wait...')
    game.agents = [a, b]
    for i in range(3000):
        game.run()

    a.dump('qlearner_agent')

    d = TicTacToePlayer.load('qlearner_agent')
    d.play_with = 'O'

    game.agents = [a, d]
    per = PerformanceCounter(game.agents, ['QLearnerA', 'QLearnerD'])

    for i in range(3000):