# Path: src/SuperMarioBros/simulation.py
# class MarioSimulation:
#     def __init__(self, layout, config=None):
#         """
#         Instantiate physics engine objects
#         :param layout: Two-dimensional numpy array layout
#         :param config: Global configuration
#         """
#             
#         self.layout = layout
#         self.config = config
# 
#         init_pos = np.array([2, 3, 0]) if config is None or "init_pos" not in config else config["init_pos"]
#         mario_bb = np.array([0.5, 1]) if config is None or "mario_bb" not in config else config["mario_bb"]
# 
#         self.mario = CollidableRigid(init_pos, mario_bb, config)
#         self.brick_bb = layout_tobb(layout, config)
# 
#         # Start with gravity
#         self.mario.reaction(give_gravity)
# 
#     def advance_frame(self, action):
#         """
#         Update physics engine object states for next frame
#         :param action: agent action for current frame
#         :return: None
#         """
#         if(self.mario.state[0][0] <= 0.5):
#             return
#         # Advance a time step
#         self.mario.update()
# 
#         # Locate blocks for collision detections
#         bb_to_check = collision_proposal(self.mario, self.brick_bb, self.config)
#         
# 
#         gravity = compensate_gravity(self.mario, bb_to_check, self.config)
# 
#         if not bb_to_check or gravity:
#             self.mario.reaction(give_gravity)
#         
#         # Resolve collisions
#         collisions = list(filter(lambda pair: pair[1]['hit'] is not None,
#                                  map(lambda bb: (bb.get_center(), bb.collide(self.mario)), bb_to_check)))
# 
#         if collisions:
#             closest_collision = min(collisions, key=lambda pair: pair[1]['hit']['time'])
# 
#             self.mario.reaction(collision_resolved, closest_collision[1]["hit"]["delta"])
#             # self.mario.reaction(collision_resolved, closest_collision[1]["position"])
# 
#             # Process momentum change
#             self.mario.reaction(hit_edge_reaction(closest_collision[1]))
# 
#         # Grab an action from input and simulate the force
#         self.mario.reaction(action_mapping[action])
# 
#         if collisions:
#             return closest_collision
# 
#     def get_renderable(self):
#         return self.mario
#     
#     def next_none_time(self, ori):
#         if(self.mario.state[0][0] <= 0.5):
#             return ori
#         ll = []
#         for bb in self.brick_bb:
#             if bb[0] == int(self.mario.state[0][0]):
#                 if bb[1] < int(self.mario.state[1][0]):
#                     ll.append(bb)
#         ll = sorted(ll,key=lambda x:x[1],reverse=True)
#         block_below = ll[0]
#         print self.mario.state, block_below
#         if self.mario.state[1][0] - block_below[1] > 1.05:
#                 print "self", self.mario.state, block_below
#                 print "END"
#                 return 0
#         return ori


import time
import json
import numpy as np
import pqdict
from abc import ABCMeta, abstractmethod
from Supervised.Astar import Astar
from src.SuperMarioBros.simulation import MarioSimulation


__author__ = "Chang Gao"
__copyright__ = "Copyright (c) 2017 Malmactor"
__license__ = "MIT"



# Path: src/SuperMarioBros/simulation.py
# class MarioSimulation:
#     def __init__(self, layout, config=None):
#         """
#         Instantiate physics engine objects
#         :param layout: Two-dimensional numpy array layout
#         :param config: Global configuration
#         """
#             
#         self.layout = layout
#         self.config = config
# 
#         init_pos = np.array([2, 3, 0]) if config is None or "init_pos" not in config else config["init_pos"]
#         mario_bb = np.array([0.5, 1]) if config is None or "mario_bb" not in config else config["mario_bb"]
# 
#         self.mario = CollidableRigid(init_pos, mario_bb, config)
#         self.brick_bb = layout_tobb(layout, config)
# 
#         # Start with gravity
#         self.mario.reaction(give_gravity)
# 
#     def advance_frame(self, action):
#         """
#         Update physics engine object states for next frame
#         :param action: agent action for current frame
#         :return: None
#         """
#         if(self.mario.state[0][0] <= 0.5):
#             return
#         # Advance a time step
#         self.mario.update()
# 
#         # Locate blocks for collision detections
#         bb_to_check = collision_proposal(self.mario, self.brick_bb, self.config)
#         
# 
#         gravity = compensate_gravity(self.mario, bb_to_check, self.config)
# 
#         if not bb_to_check or gravity:
#             self.mario.reaction(give_gravity)
#         
#         # Resolve collisions
#         collisions = list(filter(lambda pair: pair[1]['hit'] is not None,
#                                  map(lambda bb: (bb.get_center(), bb.collide(self.mario)), bb_to_check)))
# 
#         if collisions:
#             closest_collision = min(collisions, key=lambda pair: pair[1]['hit']['time'])
# 
#             self.mario.reaction(collision_resolved, closest_collision[1]["hit"]["delta"])
#             # self.mario.reaction(collision_resolved, closest_collision[1]["position"])
# 
#             # Process momentum change
#             self.mario.reaction(hit_edge_reaction(closest_collision[1]))
# 
#         # Grab an action from input and simulate the force
#         self.mario.reaction(action_mapping[action])
# 
#         if collisions:
#             return closest_collision
# 
#     def get_renderable(self):
#         return self.mario
#     
#     def next_none_time(self, ori):
#         if(self.mario.state[0][0] <= 0.5):
#             return ori
#         ll = []
#         for bb in self.brick_bb:
#             if bb[0] == int(self.mario.state[0][0]):
#                 if bb[1] < int(self.mario.state[1][0]):
#                     ll.append(bb)
#         ll = sorted(ll,key=lambda x:x[1],reverse=True)
#         block_below = ll[0]
#         print self.mario.state, block_below
#         if self.mario.state[1][0] - block_below[1] > 1.05:
#                 print "self", self.mario.state, block_below
#                 print "END"
#                 return 0
#         return ori


# Path: src/_backup_ref_files_/movement-search.py
import time
import json
import numpy as np
import pqdict
from abc import ABCMeta, abstractmethod
from Supervised.Astar import Astar
from src.SuperMarioBros.simulation import MarioSimulation



__author__ = "Chang Gao"
__copyright__ = "Copyright (c) 2017 Malmactor"
__license__ = "MIT"



class Actor: