# 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, \
                                                             make_exponential_temperature, \
                                                             PerformanceCounter, \
                                                             RLProblem
from simpleai.environments import RLEnvironment
    from Tkinter import *
    from tkinter import *
import threading

    def event(self, state1, action, state2, agent):
        print('action: %s state: %s' % (action, str(state2)))
        x, y, have_gold = state2
        if have_gold and self.gold:
            self.w.delete(self.gold)
            self.w.itemconfig(self.agent, outline="yellow", width=6.0)
        self.w.coords(self.agent, self._coord(x, y))


class WumpusEnvironment(RLEnvironment):

    def __init__(self, agent):
        super(RLEnvironment, self).__init__([agent], (1, 1, False))
        self.action_dict = {'up': (0, 1), 'down': (0, -1), 'left': (-1, 0), 'rigth': (1, 0)}
        self.wumpus = (1, 3)
        self.holes = [(3, 1), (3, 3), (4, 4)]
        self.gold = (3, 4)
        self.threats = [self.wumpus] + self.holes

        self.rewards = {(1, 1, True): 10}
        for c, r in self.threats:
            self.rewards[(c, r, True)] = -10
            self.rewards[(c, r, False)] = -10

    def do_action(self, state, action, agent):
        c1, r1, have_gold = state
        c2, r2 = self.action_dict[action]
        rn = r1 + r2
        cn = c1 + c2

# 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/wumpus.py
from simpleai.machine_learning.reinforcement_learning import TDQLearner, \
                                                             make_exponential_temperature, \
                                                             PerformanceCounter, \
                                                             RLProblem
from simpleai.environments import RLEnvironment
    from Tkinter import *
    from tkinter import *
import threading


    def event(self, state1, action, state2, agent):
        print('action: %s state: %s' % (action, str(state2)))
        x, y, have_gold = state2
        if have_gold and self.gold:
            self.w.delete(self.gold)
            self.w.itemconfig(self.agent, outline="yellow", width=6.0)
        self.w.coords(self.agent, self._coord(x, y))


class WumpusEnvironment(RLEnvironment):

    def __init__(self, agent):
        super(RLEnvironment, self).__init__([agent], (1, 1, False))
        self.action_dict = {'up': (0, 1), 'down': (0, -1), 'left': (-1, 0), 'rigth': (1, 0)}
        self.wumpus = (1, 3)
        self.holes = [(3, 1), (3, 3), (4, 4)]
        self.gold = (3, 4)
        self.threats = [self.wumpus] + self.holes

        self.rewards = {(1, 1, True): 10}
        for c, r in self.threats:
            self.rewards[(c, r, True)] = -10
            self.rewards[(c, r, False)] = -10

    def do_action(self, state, action, agent):
        c1, r1, have_gold = state
        c2, r2 = self.action_dict[action]
        rn = r1 + r2
        cn = c1 + c2

        if not have_gold and (cn, rn) == self.gold: