def __init__(self, game=None): super().__init__(game=game) # SAMPLE - Replace with your own game inputs! self.game_inputs = { "MOVEMENT": { "MOVE UP": [KeyboardEvent(KeyboardEvents.DOWN, KeyboardKey.KEY_UP)], "MOVE LEFT": [KeyboardEvent(KeyboardEvents.DOWN, KeyboardKey.KEY_LEFT)], "MOVE DOWN": [KeyboardEvent(KeyboardEvents.DOWN, KeyboardKey.KEY_DOWN)], "MOVE RIGHT": [KeyboardEvent(KeyboardEvents.DOWN, KeyboardKey.KEY_RIGHT)] } }
def setup_method(self, method): self.random_agent = RandomAgentTest( "TEST", game_inputs=[{ "name": "FIRST", "control_type": InputControlTypes.DISCRETE, "inputs": { "A": [KeyboardEvent(KeyboardEvents.DOWN, KeyboardKey.KEY_A)], "B": [KeyboardEvent(KeyboardEvents.DOWN, KeyboardKey.KEY_A)] } }, { "name": "SECOND", "control_type": InputControlTypes.CONTINUOUS, "inputs": { "events": [KeyboardEvent(KeyboardEvents.DOWN, KeyboardKey.KEY_A)], "minimum": 0.001, "maximum": 1.0 } }, { "name": "THIRD", "control_type": InputControlTypes.DISCRETE, "inputs": { "C": [KeyboardEvent(KeyboardEvents.DOWN, KeyboardKey.KEY_C)], "D": [KeyboardEvent(KeyboardEvents.DOWN, KeyboardKey.KEY_D)], "E": [KeyboardEvent(KeyboardEvents.DOWN, KeyboardKey.KEY_E)] } }])
def __init__(self, game=None): super().__init__(game=game) self.world_map_sprites_keys = [ 'SPRITE_WORLD_MAP_AUSTRALIA', 'SPRITE_WORLD_MAP_BRAZIL', 'SPRITE_WORLD_MAP_CALIFORNIA', 'SPRITE_WORLD_MAP_CHILE', 'SPRITE_WORLD_MAP_CHINA', 'SPRITE_WORLD_MAP_GREECE', 'SPRITE_WORLD_MAP_HAWAII', 'SPRITE_WORLD_MAP_ICELAND', 'SPRITE_WORLD_MAP_INDIA', 'SPRITE_WORLD_MAP_JAPAN', 'SPRITE_WORLD_MAP_SOUTH_AFRICA', 'SPRITE_WORLD_MAP_UAE' ] self.next_region_inputs = [ KeyboardKey.KEY_S, KeyboardKey.KEY_D, KeyboardKey.KEY_D, KeyboardKey.KEY_W, KeyboardKey.KEY_W, KeyboardKey.KEY_D, KeyboardKey.KEY_D, KeyboardKey.KEY_D, KeyboardKey.KEY_W, KeyboardKey.KEY_D, KeyboardKey.KEY_D, KeyboardKey.KEY_D ] self.game_inputs = { "STEERING": { "STEER LEFT": [KeyboardEvent(KeyboardEvents.DOWN, KeyboardKey.KEY_A)], "ACCELERATE - STEER LEFT": [ KeyboardEvent(KeyboardEvents.DOWN, KeyboardKey.KEY_A), KeyboardEvent(KeyboardEvents.DOWN, KeyboardKey.KEY_W) ], "ACCELERATE": [KeyboardEvent(KeyboardEvents.DOWN, KeyboardKey.KEY_W)], "ACCELERATE - STEER RIGHT": [ KeyboardEvent(KeyboardEvents.DOWN, KeyboardKey.KEY_W), KeyboardEvent(KeyboardEvents.DOWN, KeyboardKey.KEY_D) ], "STEER RIGHT": [KeyboardEvent(KeyboardEvents.DOWN, KeyboardKey.KEY_D)], "BRAKE": [KeyboardEvent(KeyboardEvents.DOWN, KeyboardKey.KEY_S)], "NITRO": [KeyboardEvent(KeyboardEvents.DOWN, KeyboardKey.KEY_SPACE)], "IDLE": [] } }
def setup_play(self): self.game_inputs = { "MOVE UP": [ KeyboardEvent(KeyboardEvents.DOWN, KeyboardKey.KEY_W) ], "MOVE LEFT": [ KeyboardEvent(KeyboardEvents.DOWN, KeyboardKey.KEY_A) ], "MOVE DOWN": [ KeyboardEvent(KeyboardEvents.DOWN, KeyboardKey.KEY_S) ], "MOVE RIGHT": [ KeyboardEvent(KeyboardEvents.DOWN, KeyboardKey.KEY_D) ], "MOVE TOP-LEFT": [ KeyboardEvent(KeyboardEvents.DOWN, KeyboardKey.KEY_W), KeyboardEvent(KeyboardEvents.DOWN, KeyboardKey.KEY_A) ], "MOVE TOP-RIGHT": [ KeyboardEvent(KeyboardEvents.DOWN, KeyboardKey.KEY_W), KeyboardEvent(KeyboardEvents.DOWN, KeyboardKey.KEY_D) ], "MOVE DOWN-LEFT": [ KeyboardEvent(KeyboardEvents.DOWN, KeyboardKey.KEY_S), KeyboardEvent(KeyboardEvents.DOWN, KeyboardKey.KEY_A) ], "MOVE DOWN-RIGHT": [ KeyboardEvent(KeyboardEvents.DOWN, KeyboardKey.KEY_S), KeyboardEvent(KeyboardEvents.DOWN, KeyboardKey.KEY_D) ], "SHOOT UP": [ MouseEvent(MouseEvents.CLICK, MouseButton.LEFT) ], "SHOOT LEFT": [ MouseEvent(MouseEvents.CLICK, MouseButton.RIGHT) ], "DON'T MOVE": [] } self.ppo_agent = SerpentPPO( frame_shape=(125, 112, 4), game_inputs=self.game_inputs ) self.first_run = True self.game_over = False self.run_count = 0 self.run_reward = 0 self.observation_count = 0 self.episode_observation_count = 0 self.performed_inputs = collections.deque(list(), maxlen=8) self.reward_10 = collections.deque(list(), maxlen=10) self.reward_100 = collections.deque(list(), maxlen=100) self.reward_1000 = collections.deque(list(), maxlen=1000) self.rewards = list() self.average_reward_10 = 0 self.average_reward_100 = 0 self.average_reward_1000 = 0 self.top_reward = 0 self.top_reward_run = 0 self.previous_score = 0 self.score_10 = collections.deque(list(), maxlen=10) self.score_100 = collections.deque(list(), maxlen=100) self.score_1000 = collections.deque(list(), maxlen=1000) self.average_score_10 = 0 self.average_score_100 = 0 self.average_score_1000 = 0 self.best_score = 0 self.best_score_run = 0 self.just_relaunched = False self.frame_buffer = None try: self.ppo_agent.agent.restore_model( directory=os.path.join( os.getcwd(), "datasets", "pacai")) self.restore_metadata() except Exception: pass self.analytics_client.track( event_key="INITIALIZE", data=dict( episode_rewards=[])) for reward in self.rewards: self.analytics_client.track( event_key="EPISODE_REWARD", data=dict( reward=reward)) time.sleep(0.01) # Warm Agent? game_frame_buffer = FrameGrabber.get_frames( [0, 1, 2, 3], frame_type="PIPELINE") game_frame_buffer = self.extract_game_area(game_frame_buffer) self.ppo_agent.generate_action(game_frame_buffer) self.score = collections.deque(np.full((16,), 0), maxlen=16) self.lives = collections.deque(np.full((16,), 3), maxlen=16) self.continuity_bonus = 0 self.started_at = datetime.utcnow().isoformat() self.episode_started_at = None self.paused_at = None print("Enter - Auto Save") self.input_controller.tap_key(KeyboardKey.KEY_ENTER) time.sleep(2) print("Enter - Menu") self.input_controller.tap_key(KeyboardKey.KEY_ENTER) time.sleep(1) print("Enter - Start game") self.input_controller.tap_key(KeyboardKey.KEY_ENTER) time.sleep(1) # Make sure to initialize Game() after passing the Start game menu, # otherwise the pointers may not be fully loaded. self.game_data = Game() return
def setup_method(self, method): self.agent_game_inputs_simple_discrete = AgentTest( "TEST", game_inputs=[ { "control_type": InputControlTypes.DISCRETE, "inputs": { "A": [KeyboardEvent(KeyboardEvents.DOWN, KeyboardKey.KEY_A)], "B": [KeyboardEvent(KeyboardEvents.DOWN, KeyboardKey.KEY_B)] } } ] ) self.agent_game_inputs_complex_discrete = AgentTest( "TEST", game_inputs=[ { "control_type": InputControlTypes.DISCRETE, "inputs": { "A": [KeyboardEvent(KeyboardEvents.DOWN, KeyboardKey.KEY_A)], "B": [KeyboardEvent(KeyboardEvents.DOWN, KeyboardKey.KEY_B)] } }, { "control_type": InputControlTypes.DISCRETE, "inputs": { "C": [KeyboardEvent(KeyboardEvents.DOWN, KeyboardKey.KEY_C)], "D": [KeyboardEvent(KeyboardEvents.DOWN, KeyboardKey.KEY_D)], "E": [KeyboardEvent(KeyboardEvents.DOWN, KeyboardKey.KEY_E)] } } ] ) self.agent_game_inputs_complex_mixed = AgentTest( "TEST", game_inputs=[ { "name": "FIRST", "control_type": InputControlTypes.DISCRETE, "inputs": { "A": [KeyboardEvent(KeyboardEvents.DOWN, KeyboardKey.KEY_A)], "B": [KeyboardEvent(KeyboardEvents.DOWN, KeyboardKey.KEY_B)] } }, { "name": "SECOND", "control_type": InputControlTypes.CONTINUOUS, "inputs": { "events": [KeyboardEvent(KeyboardEvents.DOWN, KeyboardKey.KEY_A)], "minimum": 0.001, "maximum": 1.0 } }, { "name": "THIRD", "control_type": InputControlTypes.DISCRETE, "inputs": { "C": [KeyboardEvent(KeyboardEvents.DOWN, KeyboardKey.KEY_C)], "D": [KeyboardEvent(KeyboardEvents.DOWN, KeyboardKey.KEY_D)], "E": [KeyboardEvent(KeyboardEvents.DOWN, KeyboardKey.KEY_E)] } } ] )
def __init__(self, game=None): super().__init__(game=game) self.game_inputs = { "MOVEMENT": { "MOVE UP": [KeyboardEvent(KeyboardEvents.DOWN, KeyboardKey.KEY_W)], "MOVE LEFT": [KeyboardEvent(KeyboardEvents.DOWN, KeyboardKey.KEY_A)], "MOVE DOWN": [KeyboardEvent(KeyboardEvents.DOWN, KeyboardKey.KEY_S)], "MOVE RIGHT": [KeyboardEvent(KeyboardEvents.DOWN, KeyboardKey.KEY_D)], "MOVE TOP-LEFT": [ KeyboardEvent(KeyboardEvents.DOWN, KeyboardKey.KEY_W), KeyboardEvent(KeyboardEvents.DOWN, KeyboardKey.KEY_A) ], "MOVE TOP-RIGHT": [ KeyboardEvent(KeyboardEvents.DOWN, KeyboardKey.KEY_W), KeyboardEvent(KeyboardEvents.DOWN, KeyboardKey.KEY_D) ], "MOVE DOWN-LEFT": [ KeyboardEvent(KeyboardEvents.DOWN, KeyboardKey.KEY_S), KeyboardEvent(KeyboardEvents.DOWN, KeyboardKey.KEY_A) ], "MOVE DOWN-RIGHT": [ KeyboardEvent(KeyboardEvents.DOWN, KeyboardKey.KEY_S), KeyboardEvent(KeyboardEvents.DOWN, KeyboardKey.KEY_D) ], "DON'T MOVE": [] }, "SHOOTING": { "SHOOT UP": [KeyboardEvent(KeyboardEvents.DOWN, KeyboardKey.KEY_UP)], "SHOOT LEFT": [KeyboardEvent(KeyboardEvents.DOWN, KeyboardKey.KEY_LEFT)], "SHOOT DOWN": [KeyboardEvent(KeyboardEvents.DOWN, KeyboardKey.KEY_DOWN)], "SHOOT RIGHT": [KeyboardEvent(KeyboardEvents.DOWN, KeyboardKey.KEY_RIGHT)], "DON'T SHOOT": [] } }
def __init__(self, game=None): super().__init__(game=game) self.game_inputs = { "MOVEMENT": { "WALK LEFT": [KeyboardEvent(KeyboardEvents.DOWN, KeyboardKey.KEY_A)], "STRAFE LEFT": [ KeyboardEvent(KeyboardEvents.DOWN, KeyboardKey.KEY_A), KeyboardEvent(KeyboardEvents.DOWN, KeyboardKey.KEY_W), KeyboardEvent(KeyboardEvents.DOWN, KeyboardKey.KEY_LEFT_SHIFT) ], "SPRINT": [ KeyboardEvent(KeyboardEvents.DOWN, KeyboardKey.KEY_W), KeyboardEvent(KeyboardEvents.DOWN, KeyboardKey.KEY_LEFT_SHIFT) ], "WALK": [KeyboardEvent(KeyboardEvents.DOWN, KeyboardKey.KEY_W)], "STRAFE RIGHT": [ KeyboardEvent(KeyboardEvents.DOWN, KeyboardKey.KEY_W), KeyboardEvent(KeyboardEvents.DOWN, KeyboardKey.KEY_D), KeyboardEvent(KeyboardEvents.DOWN, KeyboardKey.KEY_LEFT_SHIFT) ], "WALK RIGHT": [KeyboardEvent(KeyboardEvents.DOWN, KeyboardKey.KEY_D)], "BACK": [KeyboardEvent(KeyboardEvents.DOWN, KeyboardKey.KEY_S)], "JUMP": [KeyboardEvent(KeyboardEvents.DOWN, KeyboardKey.KEY_SPACE)], "CROUCH": [KeyboardEvent(KeyboardEvents.DOWN, KeyboardKey.KEY_C)], "PHRONE": [ KeyboardEvent(KeyboardEvents.DOWN, KeyboardKey.KEY_LEFT_CTRL) ], "STOPPED": [] }, "COMBAT": { "RELOAD": [KeyboardEvent(KeyboardEvents.DOWN, KeyboardKey.KEY_R)], "ABILTY": [KeyboardEvent(KeyboardEvents.DOWN, KeyboardKey.KEY_B)], "GRENADE": [KeyboardEvent(KeyboardEvents.DOWN, KeyboardKey.KEY_G)], "MELEE": [KeyboardEvent(KeyboardEvents.DOWN, KeyboardKey.KEY_E)], "USE": [KeyboardEvent(KeyboardEvents.DOWN, KeyboardKey.KEY_F)], "NON LETHAL": [KeyboardEvent(KeyboardEvents.DOWN, KeyboardKey.KEY_Q)], "SECONDARY": [KeyboardEvent(KeyboardEvents.DOWN, KeyboardKey.KEY_1)], "Neutral": [] }, "CURSOR": { "MOVE MOUSE X": [], "MOVE MOUSE Y": [], "MOVE MOUSE XY": [], "MOVE MOUSE X2": [], "MOVE MOUSE Y2": [], "MOVE MOUSE XY2": [], "MOVE MOUSE XY3": [], "MOVE MOUSE XY4": [], "IDLE_MOUSE": [] } }
def __init__(self, game=None): super().__init__(game=game) # SAMPLE - Replace with your own game inputs! self.game_inputs = { "MOVEMENT": { "MOVE UP": [ KeyboardEvent(KeyboardEvents.DOWN, KeyboardKey.KEY_W) ], "MOVE LEFT": [ KeyboardEvent(KeyboardEvents.DOWN, KeyboardKey.KEY_A) ], "MOVE DOWN": [ KeyboardEvent(KeyboardEvents.DOWN, KeyboardKey.KEY_S) ], "MOVE RIGHT": [ KeyboardEvent(KeyboardEvents.DOWN, KeyboardKey.KEY_D) ], "MOVE TOP-LEFT": [ KeyboardEvent(KeyboardEvents.DOWN, KeyboardKey.KEY_W), KeyboardEvent(KeyboardEvents.DOWN, KeyboardKey.KEY_A) ], "MOVE TOP-RIGHT": [ KeyboardEvent(KeyboardEvents.DOWN, KeyboardKey.KEY_W), KeyboardEvent(KeyboardEvents.DOWN, KeyboardKey.KEY_D) ], "MOVE DOWN-LEFT": [ KeyboardEvent(KeyboardEvents.DOWN, KeyboardKey.KEY_S), KeyboardEvent(KeyboardEvents.DOWN, KeyboardKey.KEY_A) ], "MOVE DOWN-RIGHT": [ KeyboardEvent(KeyboardEvents.DOWN, KeyboardKey.KEY_S), KeyboardEvent(KeyboardEvents.DOWN, KeyboardKey.KEY_D) ], "DON'T MOVE": [] }, "SHOOTING": { "SHOOT UP": [ MouseEvent(MouseEvents.CLICK, MouseButton.LEFT) ], "SHOOT LEFT": [ MouseEvent(MouseEvents.CLICK, MouseButton.RIGHT) ] "DON'T SHOOT": [] } }
from serpent.input_controller import KeyboardKey, KeyboardEvent, KeyboardEvents from serpent.input_controller import MouseButton, MouseEvent, MouseEvents from serpent.enums import InputControlTypes game_inputs = { "MOVEMENT": { "WALK LEFT": [KeyboardEvent(KeyboardEvents.DOWN, KeyboardKey.KEY_A)], "STRAFEALEFT": [ KeyboardEvent(KeyboardEvents.DOWN, KeyboardKey.KEY_A), KeyboardEvent(KeyboardEvents.DOWN, KeyboardKey.KEY_W), KeyboardEvent(KeyboardEvents.DOWN, KeyboardKey.KEY_LEFT_SHIFT) ], "SPRINT": [ KeyboardEvent(KeyboardEvents.DOWN, KeyboardKey.KEY_W), KeyboardEvent(KeyboardEvents.DOWN, KeyboardKey.KEY_LEFT_SHIFT) ], "WALK": [KeyboardEvent(KeyboardEvents.DOWN, KeyboardKey.KEY_W)], "STRAFE RIGHT": [ KeyboardEvent(KeyboardEvents.DOWN, KeyboardKey.KEY_W), KeyboardEvent(KeyboardEvents.DOWN, KeyboardKey.KEY_D), KeyboardEvent(KeyboardEvents.DOWN, KeyboardKey.KEY_LEFT_SHIFT) ], "WALK RIGHT": [KeyboardEvent(KeyboardEvents.DOWN, KeyboardKey.KEY_D)], "BACK": [KeyboardEvent(KeyboardEvents.DOWN, KeyboardKey.KEY_S)], "JUMP": [KeyboardEvent(KeyboardEvents.DOWN, KeyboardKey.KEY_SPACE)], "CROUCH": [KeyboardEvent(KeyboardEvents.DOWN, KeyboardKey.KEY_C)], "PHRONE": [KeyboardEvent(KeyboardEvents.DOWN, KeyboardKey.KEY_LEFT_CTRL)], "STOPPED": [] }, "COMBAT": { "RELOAD": [KeyboardEvent(KeyboardEvents.DOWN, KeyboardKey.KEY_R)],