import outsmart as osmt

osmt.STATE.lab[6, 8] = 2
osmt.STATE.lab[0, 0] = -1


def step_4():
    """Sucessful training"""
    osmt.script(s_text="Good Job !")


def step_3():
    """Rocks spawning"""
    def success(state):
        bob_on_patch = state.lab[6, 8] == -2
        rock_nearby = state.lab[7, 8] == 4
        rock_nearby = rock_nearby or state.lab[5, 8] == 4
        rock_nearby = rock_nearby or state.lab[6, 9] == 4
        rock_nearby = rock_nearby or state.lab[6, 7] == 4
        return bob_on_patch and rock_nearby
    osmt.script(s_text="""Uh-oh, something went wrong :
In this lab setting, there is no reward
that could let Bob know how it's doing.
Let's change that.""",
                o_text="""Spawn some rocks somewhere right next to Bob by right-clicking
multiple times on the appropriate tile.""",
                objective_function=success,
                next_step=step_4)


def step_2():
    """Frist training"""
    osmt.create_train_button()
    osmt.script(s_text="""Good Job !
You can train Bob with a state-of-the-art
Reinforcement Learning algorithm.
This will allow you to train him like you would a dog or a rat.""",
                o_text="Train bob by clicking on the train button.",
                objective_function=lambda s: s.log_text[0][1] == 'Error !',
                next_step=step_3)

osmt.script(s_text="""This is your lab.
The blue robot is a test robot.
His name is Bob.
You can control its position.""",
            o_text="Click on the green patch to move the robot there.",
            objective_function=lambda s: s.lab[6, 8] == -2,
            next_step=step_2)

osmt.pyglet.app.run()

@@ -71,16 +71,103 @@
  = -1%0A%0A%0A
+def step_5():%0A    %22%22%22Resetting the robot%22%22%22%0A    osmt.script(s_text=%22%22%22Good Job !%22%22%22)%0A%0A%0A
 def step
@@ -225,16 +225,18 @@
 s_text=%22
+%22%22
 Good Job
@@ -237,17 +237,573 @@
 od Job !
-%22
+%0ANow, training Bob will succeed.%0ABob is wired to collect rocks and crystals. You can't change that.%0AYou can, however, change the environment and use rocks and%0Acrystals as a motivator to make Bob do what you want.%0AWhen dealing with animals food is used as a reward.%0AThis is the same here, only with robots.%22%22%22,%0A                o_text=%22Try again to train Bob by clicking on the%22%0A                %22%22%22%22Train%22 button.%22%22%22,%0A                objective_function=lambda s: s.log_text%5B0%5D%5B1%5D == %22Training%22%0A                %22 successful !%22,%0A                next_step=step_5
 )%0A%0A%0Adef 

Create step 4 of tutorial