In [ ]:
%matplotlib inline

import numpy as np
from grid_game import GridGame
from display import show_game, show_probability_boards
from agents import PlannerAgent, play_game

np.set_printoptions(precision=2)

game = GridGame((2, 3), 2)
agent = PlannerAgent(game, seed=3)

seeds = xrange(100)

last_lost_game = None
last_loss_subgoals = None
for seed in seeds:
    game_start = game.new_game(seed=seed)
    positions, moves = play_game(game_start, agent, max_moves=5)
    if positions[-1].is_win:
        moves.append("Win!")
        print "W",
    else:
        moves.append("Lose!")
        last_lost_game = (positions, moves)
        last_loss_subgoals = agent.subgoals
        print "L",        
    #show_game(positions, moves)

if last_lost_game:
    show_game(*last_lost_game)
    subgoals = np.array([item for (position, goal) in last_loss_subgoals for item in (position, goal)])
    show_probability_boards(subgoals)
    print subgoals