# Path: rlvision/grid.py
# class Grid(object):
# class GridSampler(object):
# class GridDataSampler(object):
#     def __init__(self, grid_map, value_map, im_size=None,
#                  start_pos=None, is_po=True, mask_radius=3,
#                  grid_type="one-is-free", dstar=False):
#     def get_state(self):
#     def is_pos_valid(self, pos):
#     def rand_start_pos(self):
#     def set_start_pos(self, start_pos):
#     def set_goal_pos(self):
#     def set_curr_pos(self, curr_pos):
#     def update_curr_map(self, map_update, dstar_map_update=None):
#     def get_curr_dstar_visible_map(self, pos):
#     def get_curr_visible_map(self, pos):
#     def get_state_map(self):
#     def update_state(self, pos_update):
#     def action2pos(self, action):
#     def update_state_from_action(self, action, verbose=0):
#     def get_time(self):
#     def get_state_reward(self, max_num_steps=None):
#     def __init__(self, im_data, state_data, label_data, sample_idx, im_size):
#     def find_goal(self, value_grid):
#     def get_grid(self, grid_idx):
#     def compare_grid(self, grid_1, grid_2):
#     def next(self):
#     def __init__(self, grid_data, value_data, im_size, states_xy,
#                  label_data):
#     def compare_pos(self, pos1, pos2):
#     def get_next_state(self, pos, action):
#     def get_goal_pos(self, value_grid):
#     def next(self):
# def sample_data(db, imsize, num_samples=0):
# def sample_data_grid8(num_samples=0):
# def sample_data_grid16(split=None, num_samples=0):
# def sample_data_grid28(split=None, num_samples=0):
# def sample_data_grid40(split=None, num_samples=0):
# def create_train_grid8(db_name, save_dir, num_samples=0):
# def create_train_grid16(db_name, save_dir, num_samples=0):
# def create_train_grid28(db_name, save_dir, num_samples=0):
# def create_train_grid40(db_name, save_dir, num_samples=0):
# def load_train_grid8(return_imsize=True):
# def load_train_grid16(return_imsize=True):
# def load_train_grid28(return_imsize=True):
# def load_train_grid40(return_imsize=True):


import os
import numpy as np
import matplotlib.pyplot as plt
import rlvision
from keras.models import Sequential
from keras.layers import Dense, Flatten, InputLayer
from keras.layers import Conv2D, AveragePooling2D
from keras.layers import Activation
from keras.regularizers import l2
from rlvision import grid
else:
    model.add(InputLayer(input_shape=(2, imsize[0], imsize[1])))
    model.add(Flatten())
    model.add(Dense(500))
    model.add(Activation("relu"))
    model.add(Dense(300))
    model.add(Activation("relu"))
    model.add(Dense(300))
    model.add(Activation("relu"))
    model.add(Dense(num_output, activation="softmax"))

# print model
model.summary()

model.compile(loss="categorical_crossentropy", optimizer="adam")
if resume is True:
    model.load_weights(model_path)
print ("[MESSAGE] Model built.")

# training schedule
reward_sum = 0
running_reward = None
episode_number = 0
xs, dlogps, drs, probs = [], [], [], []
train_X, train_Y = [], []
num_victory = 0
# go through entire game space
while True:
    for game_idx in xrange(num_train):
        for start_pos in [start_tot[game_idx][0]]:

# Path: rlvision/grid.py
# class Grid(object):
# class GridSampler(object):
# class GridDataSampler(object):
#     def __init__(self, grid_map, value_map, im_size=None,
#                  start_pos=None, is_po=True, mask_radius=3,
#                  grid_type="one-is-free", dstar=False):
#     def get_state(self):
#     def is_pos_valid(self, pos):
#     def rand_start_pos(self):
#     def set_start_pos(self, start_pos):
#     def set_goal_pos(self):
#     def set_curr_pos(self, curr_pos):
#     def update_curr_map(self, map_update, dstar_map_update=None):
#     def get_curr_dstar_visible_map(self, pos):
#     def get_curr_visible_map(self, pos):
#     def get_state_map(self):
#     def update_state(self, pos_update):
#     def action2pos(self, action):
#     def update_state_from_action(self, action, verbose=0):
#     def get_time(self):
#     def get_state_reward(self, max_num_steps=None):
#     def __init__(self, im_data, state_data, label_data, sample_idx, im_size):
#     def find_goal(self, value_grid):
#     def get_grid(self, grid_idx):
#     def compare_grid(self, grid_1, grid_2):
#     def next(self):
#     def __init__(self, grid_data, value_data, im_size, states_xy,
#                  label_data):
#     def compare_pos(self, pos1, pos2):
#     def get_next_state(self, pos, action):
#     def get_goal_pos(self, value_grid):
#     def next(self):
# def sample_data(db, imsize, num_samples=0):
# def sample_data_grid8(num_samples=0):
# def sample_data_grid16(split=None, num_samples=0):
# def sample_data_grid28(split=None, num_samples=0):
# def sample_data_grid40(split=None, num_samples=0):
# def create_train_grid8(db_name, save_dir, num_samples=0):
# def create_train_grid16(db_name, save_dir, num_samples=0):
# def create_train_grid28(db_name, save_dir, num_samples=0):
# def create_train_grid40(db_name, save_dir, num_samples=0):
# def load_train_grid8(return_imsize=True):
# def load_train_grid16(return_imsize=True):
# def load_train_grid28(return_imsize=True):
# def load_train_grid40(return_imsize=True):


# Path: rlvision/exps/pg_16_exp.py
import os
import numpy as np
import matplotlib.pyplot as plt
import rlvision
from keras.models import Sequential
from keras.layers import Dense, Flatten, InputLayer
from keras.layers import Conv2D, AveragePooling2D
from keras.layers import Activation
from keras.regularizers import l2
from rlvision import grid

else:
    model.add(InputLayer(input_shape=(2, imsize[0], imsize[1])))
    model.add(Flatten())
    model.add(Dense(500))
    model.add(Activation("relu"))
    model.add(Dense(300))
    model.add(Activation("relu"))
    model.add(Dense(300))
    model.add(Activation("relu"))
    model.add(Dense(num_output, activation="softmax"))

# print model
model.summary()

model.compile(loss="categorical_crossentropy", optimizer="adam")
if resume is True:
    model.load_weights(model_path)
print ("[MESSAGE] Model built.")

# training schedule
reward_sum = 0
running_reward = None
episode_number = 0
xs, dlogps, drs, probs = [], [], [], []
train_X, train_Y = [], []
num_victory = 0
# go through entire game space
while True:
    for game_idx in xrange(num_train):
        for start_pos in [start_tot[game_idx][0]]:

            game = grid.Grid(data[game_idx], value[game_idx], imsize,