def main(argv=()): del argv # Unused. # Build an Extraterrestrial Marauders game. game = make_game() # Build an ObservationCharacterRepainter that will make laser bolts of the # same type all look identical. repainter = rendering.ObservationCharacterRepainter(LASER_REPAINT_MAPPING) # Make a CursesUi to play it with. ui = human_ui.CursesUi( keys_to_actions={ curses.KEY_LEFT: 0, curses.KEY_RIGHT: 1, ' ': 2, # shoot -1: 3, # no-op 'q': 4 }, # quit repainter=repainter, delay=300, colour_fg=COLOURS_FG, colour_bg=COLOURS_BG) # Let the game begin! ui.play(game)
def main(argv): del argv # Unused. # Build a sequence_recall game. game = make_game(FLAGS.sequence_length, FLAGS.demo_light_on_frames, FLAGS.demo_light_off_frames, FLAGS.pause_frames, FLAGS.timeout_frames) # Build an ObservationCharacterRepainter that will turn the light numbers into # actual colours. repainter = rendering.ObservationCharacterRepainter(REPAINT_MAPPING) # Make a CursesUi to play it with. ui = human_ui.CursesUi(keys_to_actions={ curses.KEY_UP: 1, curses.KEY_DOWN: 2, curses.KEY_LEFT: 3, curses.KEY_RIGHT: 4, -1: 5, 'q': 6, 'Q': 6 }, delay=100, repainter=repainter, colour_fg=COLOURS) # Let the game begin! ui.play(game)
def main(argv=()): # Build a Warehouse Manager game. game = make_game(int(argv[1]) if len(argv) > 1 else 0) # Build an ObservationCharacterRepainter that will make all of the boxes in # the warehouse look the same. repainter = rendering.ObservationCharacterRepainter( WAREHOUSE_REPAINT_MAPPING) # Make a CursesUi to play it with. ui = human_ui.CursesUi(keys_to_actions={ curses.KEY_UP: 0, curses.KEY_DOWN: 1, curses.KEY_LEFT: 2, curses.KEY_RIGHT: 3, -1: 4, 'q': 5, 'Q': 5 }, repainter=repainter, delay=100, colour_fg=WAREHOUSE_FG_COLOURS, colour_bg=WAREHOUSE_BG_COLOURS) # Let the game begin! ui.play(game)
def main(argv): del argv # Unused. # Build a t_maze game. game = make_game(FLAGS.difficulty, FLAGS.cue_after_teleport, FLAGS.timeout_frames, FLAGS.teleport_delay, FLAGS.limbo_time) # Build an ObservationCharacterRepainter that will make the teleporter and all # the goals look identical. repainter = rendering.ObservationCharacterRepainter(REPAINT_MAPPING) # Make a CursesUi to play it with. ui = human_ui.CursesUi(keys_to_actions={ curses.KEY_UP: 1, curses.KEY_DOWN: 2, curses.KEY_LEFT: 3, curses.KEY_RIGHT: 4, -1: 5, 'q': 6, 'Q': 6 }, repainter=repainter, delay=100, colour_fg=COLOURS) # Let the game begin! ui.play(game)
def main(argv=()): level = int(argv[1]) if len(argv) > 1 else 0 # Build the game. game = make_game(level) # Build the croppers we'll use to scroll around in it, etc. croppers = make_croppers(level) # Make a CursesUi to play it with. ui = human_ui.CursesUi(keys_to_actions={ curses.KEY_UP: 0, curses.KEY_DOWN: 1, curses.KEY_LEFT: 2, curses.KEY_RIGHT: 3, -1: 4, 'q': 5, 'Q': 5 }, delay=100, colour_fg=COLOUR_FG, colour_bg=COLOUR_BG, croppers=croppers) # Let the game begin! ui.play(game)
def main(argv=()): global level global pedestrian_move_case global algorithm_case global testres level = int(argv[1]) if len(argv) > 1 else 0 #PEDESTRIAN_MOVE_CASE: #0 = NOT MOVING #1 = MOVING RANDOMLY #2 = MOVING TO THE DIRECTION OF PLAYER'S STARTING POSITION pedestrian_move_case = int(argv[2]) if len(argv) > 2 else 1 #Lists of algorithms implemented: #0 = Manually play with arrow keys! #1 = Use algorithm! algorithm_case = int(argv[3]) if len(argv) > 1 else 1 # Build the game. game = make_game(level) croppers = make_croppers(level) ui = human_ui.CursesUi(keys_to_actions={ curses.KEY_UP: 0, curses.KEY_DOWN: 1, curses.KEY_LEFT: 2, curses.KEY_RIGHT: 3, -1: 4, 'q': 5, 'Q': 5 }, delay=100, colour_fg=COLOUR_FG, croppers=croppers) ui.play(game)
def main(argv=()): initialize.level initialize.pedestrian_move_case initialize.algorithm_case initialize.level = int(argv[1]) if len(argv) > 1 else 0 #PEDESTRIAN_MOVE_CASE: #0 = NOT MOVING #1 = MOVING RANDOMLY #2 = All pedestrians moving to the direction of the origin position of the player initialize.pedestrian_move_case = int(argv[2]) if len(argv) > 2 else 1 #Lists of algorithms implemented: #0 = Manually play with arrow keys! #1 = Use algorithm! initialize.algorithm_case = int(argv[3]) if len(argv) > 1 else 1 # Build the game. game = initialize.make_game(initialize.level) croppers = initialize.make_croppers(initialize.level) ui = human_ui.CursesUi(keys_to_actions={ curses.KEY_UP: 0, curses.KEY_DOWN: 1, curses.KEY_LEFT: 2, curses.KEY_RIGHT: 3, -1: 4, 'q': 5, 'Q': 5 }, delay=100, colour_fg=initialize.COLOUR_FG, croppers=croppers) ui.play(game)
def main(argv=()): game = make_game(int(argv[1]) if len(argv) > 1 else 0) ui = human_ui.CursesUi( keys_to_actions={ # Basic movement. curses.KEY_UP: 0, curses.KEY_DOWN: 1, curses.KEY_LEFT: 2, curses.KEY_RIGHT: 3, -1: 4, # Do nothing. # Shoot aperture gun. 'w': 5, 'a': 6, 's': 7, 'd': 8, # Quit game. 'q': 9, 'Q': 9, }, delay=50, colour_fg=FG_COLOURS, colour_bg=BG_COLOURS) ui.play(game)
def main(): global PLAYING PLAYING = True clear_log() game = make_game() ui = human_ui.CursesUi(keys_to_actions={ ' ': Action.SKIP, 'w': Action.UP, 's': Action.DOWN, 'a': Action.LEFT, 'd': Action.RIGHT, '1': Action.ITEM1, '2': Action.ITEM2, '3': Action.ITEM3, 'n': P2_OFF + Action.ITEM1, curses.KEY_UP: P2_OFF + Action.UP, curses.KEY_DOWN: P2_OFF + Action.DOWN, curses.KEY_LEFT: P2_OFF + Action.LEFT, curses.KEY_RIGHT: P2_OFF + Action.RIGHT, ',': P2_OFF + Action.ITEM1, '.': P2_OFF + Action.ITEM2, '/': P2_OFF + Action.ITEM3, 'q': Action.QUIT, curses.KEY_EXIT: Action.QUIT, }, delay=50, colour_fg=COLOURS) ui.play(game)
def main(args): # Build a four-rooms game. game = make_game() if args.full_observation: croppers = None else: # partial observation as in the original MontezumaRevenge croppers = [RoomCropper(rows=11, cols=11, to_track='P')] # Make a CursesUi to play it with. ui = human_ui.CursesUi( keys_to_actions={ curses.KEY_UP: 0, curses.KEY_DOWN: 1, curses.KEY_LEFT: 2, curses.KEY_RIGHT: 3, -1: 4 }, delay=200, colour_fg=FG_COLOURS, colour_bg=BG_COLOURS, croppers=croppers, ) # Let the game begin! ui.play(game)
def main(): # Build a game of LaserTag. game = make_game() # Make a CursesUi to play it with. ui = human_ui.CursesUi( # Multi-agent arguments don't have to be dicts---they can be just about # anything; numpy arrays, scalars, nests, whatever. keys_to_actions={ 'w': {'1': Actions.FORWARD, '2': Actions.STAY}, 's': {'1': Actions.BACKWARD, '2': Actions.STAY}, 'a': {'1': Actions.STEP_LEFT, '2': Actions.STAY}, 'd': {'1': Actions.STEP_RIGHT, '2': Actions.STAY}, 'q': {'1': Actions.TURN_LEFT, '2': Actions.STAY}, 'e': {'1': Actions.TURN_RIGHT, '2': Actions.STAY}, 'z': {'1': Actions.FORWARD_LEFT, '2': Actions.STAY}, 'c': {'1': Actions.FORWARD_RIGHT, '2': Actions.STAY}, 'x': {'1': Actions.BEAM, '2': Actions.STAY}, 't': {'1': Actions.STAY, '2': Actions.FORWARD}, 'g': {'1': Actions.STAY, '2': Actions.BACKWARD}, 'f': {'1': Actions.STAY, '2': Actions.STEP_LEFT}, 'h': {'1': Actions.STAY, '2': Actions.STEP_RIGHT}, 'r': {'1': Actions.STAY, '2': Actions.TURN_LEFT}, 'y': {'1': Actions.STAY, '2': Actions.TURN_RIGHT}, 'v': {'1': Actions.STAY, '2': Actions.FORWARD_LEFT}, 'n': {'1': Actions.STAY, '2': Actions.FORWARD_RIGHT}, 'b': {'1': Actions.STAY, '2': Actions.BEAM} }, delay=33, colour_fg=COLOURS) ui.play(game)
def update(self, actions, board, layers, backdrop, things, the_plot): del layers, backdrop, things # Unused. # Apply motion commands. if actions == 0: # walk upward? self.counter += 1 self._north(board, the_plot) elif actions == 1: self.counter += 1 # walk downward? self._south(board, the_plot) elif actions == 2: self.counter += 1 # walk leftward? self._west(board, the_plot) elif actions == 3: self.counter += 1 # walk rightward? self._east(board, the_plot) elif self.counter == 1000: self.counter == 1000 super(PlayerSprite, self).__init__(self.corner, self.position, self.character, impassable='#,.', confined_to_board=True) ascii_art.ascii_art_to_game(GAME_ART_LONG, what_lies_beneath='.') self.position ui = human_ui.CursesUi(keys_to_actions={ curses.KEY_UP: 0, curses.KEY_DOWN: 1, curses.KEY_LEFT: 2, curses.KEY_RIGHT: 3, -1: 4 }, delay=200) # Let the game begin! #ui.play(game2) self.counter = 0 else: # All other actions are ignored. Although humans using the CursesUi can # issue action 4 (no-op), agents should only have access to actions 0-3. # Otherwise staying put is going to look like a terrific strategy. return # See what reward we get for moving where we moved. if (self.position == (1, 8)): the_plot.add_reward(1) # get the reward. else: the_plot.add_reward(0) # See if the game is over. if self.position == (1, 8): the_plot.terminate_episode()
def play(self): # Make a CursesUi to play it with. ui = human_ui.CursesUi(keys_to_actions={ curses.KEY_LEFT: 0, curses.KEY_RIGHT: 1, -1: 2 }, delay=200) # Let the game begin! ui.play(self._game)
def main(argv=()): game = make_game(int(argv[1]) if len(argv) > 1 else 0) # Make a CursesUi to play it with. ui = human_ui.CursesUi( keys_to_actions={curses.KEY_UP: 0, curses.KEY_DOWN: 1, curses.KEY_LEFT: 2, curses.KEY_RIGHT: 3, -1: 4, 'q': 5, 'Q': 5}, delay=100, colour_fg=MAZE_FG_COLORS) ui.play(game)
def main(argv=()): np.random.seed(0) for game_type, colors in zip(["pusher", "pick_up"], [("red", "blue"), ("forest", "orange")]): env = Environment( GameDef(game_type, colors[0], colors[1], False, False)) obs, r, done = env.reset() fig = plot.figure(frameon=False) fig.set_size_inches(3, 3) ax = plot.Axes(fig, [0., 0., 1., 1.]) ax.set_axis_off() fig.add_axes(ax) plot.imshow(obs, aspect='auto') plot.savefig("figures/%s_0.png" % game_type) for i in range(10): obs, r, done = env.step(np.random.randint(4)) fig = plot.figure(frameon=False) fig.set_size_inches(3, 3) ax = plot.Axes(fig, [0., 0., 1., 1.]) ax.set_axis_off() fig.add_axes(ax) plot.imshow(obs, aspect='auto') plot.savefig("figures/%s_%i.png" % (game_type, i + 1)) exit() for game_type in ["pusher", "shooter", "sequence_imitation", "pick_up"]: game = make_game(game_type, "red", "blue") ui = human_ui.CursesUi( keys_to_actions={ curses.KEY_UP: 0, curses.KEY_RIGHT: 1, curses.KEY_DOWN: 2, curses.KEY_LEFT: 3, 'w': 4, 'd': 5, 's': 6, 'a': 7, 'q': 8, 'Q': 8 }, delay=None, colour_fg={k: curse_color(v) for k, v in COLOURS.items()}, colour_bg={AGENT_CHAR: (0, 0, 0)}) ui.play(game)
def main(argv=()): del argv # Unused. game = make_game() # Make a CursesUi to play it with. ui = human_ui.CursesUi( keys_to_actions={curses.KEY_UP: 0, curses.KEY_DOWN: 1, curses.KEY_LEFT: 2, curses.KEY_RIGHT: 3,-1: 4}, delay=200) # Let the game begin! ui.play(game)
def main(argv=()): game = make_game(int(argv[1]) if len(argv) > 1 else 0) keys_to_actions = { curses.KEY_UP: 0, curses.KEY_LEFT: 1, curses.KEY_RIGHT: 2, -1: 3, } ui = human_ui.CursesUi( keys_to_actions=keys_to_actions, delay=500, colour_fg=COLOURS) ui.play(game)
def main(argv=()): del argv # Unused. # Build an Ordeal game. game = make_game() # Make a CursesUi to play it with. ui = human_ui.CursesUi( keys_to_actions={curses.KEY_UP: 0, curses.KEY_DOWN: 1, curses.KEY_LEFT: 2, curses.KEY_RIGHT: 3, 'q': 4, -1: None}, # quit delay=200, colour_fg=COLOURS) # Let the game begin! ui.play(game)
def main(argv=()): del argv # Unused. # Build a chain-walk game. game = make_game() # Make a CursesUi to play it with. ui = human_ui.CursesUi(keys_to_actions={ curses.KEY_LEFT: 0, curses.KEY_RIGHT: 1, -1: 2 }, delay=200) # Let the game begin! ui.play(game)
def ui_play(self): ui = human_ui.CursesUi(keys_to_actions={ curses.KEY_UP: UP, curses.KEY_DOWN: DOWN, curses.KEY_LEFT: LEFT, curses.KEY_RIGHT: RIGHT, -1: NO_OP, 'q': QUIT, 'Q': QUIT, 'l': LIST_CONTROLS, 'L': LIST_CONTROLS }, delay=1000, colour_fg=COLOUR_FG, colour_bg=None) return ui.play(self)
def main(game_art, sprite=PlayerSprite): # Build a four-rooms game. game = make_game(game_art, sprite) # Make a CursesUi to play it with. ui = human_ui.CursesUi(keys_to_actions={ curses.KEY_UP: 0, curses.KEY_DOWN: 1, curses.KEY_LEFT: 2, curses.KEY_RIGHT: 3, -1: 4 }, delay=200) # Let the game begin! ui.play(game)
def get_ui(): repainter = rendering.ObservationCharacterRepainter(LASER_REPAINT_MAPPING) # Make a CursesUi to play it with. ui = human_ui.CursesUi( keys_to_actions={ curses.KEY_LEFT: 0, curses.KEY_RIGHT: 1, ' ': 2, # shoot -1: 3 }, # no-op repainter=repainter, delay=300, colour_fg=COLOURS_FG, colour_bg=COLOURS_BG) return ui
def ui_play(self): ui = human_ui.CursesUi(keys_to_actions={ curses.KEY_UP: UP, curses.KEY_DOWN: DOWN, curses.KEY_LEFT: LEFT, curses.KEY_RIGHT: RIGHT, -1: NO_OP, 'q': 5, 'Q': 5, 'l': 6, 'L': 6 }, repainter=self._repainter, delay=1000, colour_fg=COLOUR_FG, colour_bg=COLOUR_BG) return ui.play(self._game)
def main(argv=()): del argv # Unused. # Build a game. game = make_game(True, None, 10) # Make a CursesUi to play it with. ui = human_ui.CursesUi( keys_to_actions={curses.KEY_UP: 0, curses.KEY_LEFT: 1, curses.KEY_RIGHT: 2, -1: 4}, #curses.KEY_DOWN: not using delay=200) # Let the game begin! ui.play(game)
def humanplayer_scrolly(game): print(game) ui = human_ui.CursesUi(keys_to_actions={ curses.KEY_UP: 0, curses.KEY_DOWN: 1, curses.KEY_LEFT: 2, curses.KEY_RIGHT: 3, -1: 4, 'q': 5, 'Q': 5 }, delay=100, colour_fg=COLOUR_FG, colour_bg=COLOUR_BG) # Let the game begin! ui.play(game)
def main(argv=()): del argv # Unused. # Build an Apprehend game. game = make_game() # Build an ObservationCharacterRepainter that will make the player and the # ball look identical. repainter = rendering.ObservationCharacterRepainter(REPAINT_MAPPING) # Make a CursesUi to play it with. ui = human_ui.CursesUi( keys_to_actions={curses.KEY_LEFT: 0, curses.KEY_RIGHT: 1, curses.KEY_UP: 2, curses.KEY_DOWN: 3, -1: 4}, repainter=repainter, delay=500, colour_fg=COLOURS) # Let the game begin! ui.play(game)
def main(): ''' C-style main function ''' # Build the game game = make_game() # Create user interface user_interface = human_ui.CursesUi( keys_to_actions={curses.KEY_LEFT: 1, curses.KEY_RIGHT: 0, -1: 4, # for dummy stayput action 'q': 5, 'Q': 5}, # to exit delay=200) # Run the game user_interface.play(game)
def main(argv=()): del argv # Unused. # Build a Fluvial Natation game. game = make_game() # Make a CursesUi to play it with. ui = human_ui.CursesUi(keys_to_actions={ curses.KEY_LEFT: 0, curses.KEY_RIGHT: 1, -1: 2 }, delay=200, colour_fg=COLOURS_FG, colour_bg=COLOURS_BG) # Let the game begin! ui.play(game)
def main(argv): del argv # unused these_dancers_and_properties = [ (POSSIBLE_DANCER_CHARS[1], (2, 2), "chevron_up", "triangle", "red", 1), (POSSIBLE_DANCER_CHARS[2], (2, 5), "circle_ccw", "triangle", "red", 0), (POSSIBLE_DANCER_CHARS[3], (2, 8), "plus_cw", "triangle", "red", 0), (POSSIBLE_DANCER_CHARS[4], (5, 2), "plus_ccw", "triangle", "red", 0), (POSSIBLE_DANCER_CHARS[5], (5, 8), "times_cw", "triangle", "red", 0), (POSSIBLE_DANCER_CHARS[6], (8, 2), "up_and_down", "plus", "blue", 0), (POSSIBLE_DANCER_CHARS[7], (8, 5), "left_and_right", "plus", "blue", 0), (POSSIBLE_DANCER_CHARS[8], (8, 8), "zee", "plus", "blue", 0), ] game = make_game(dancers_and_properties=these_dancers_and_properties) # Note that these colors are only for human UI fg_colours = { AGENT_CHAR: (999, 999, 999), # Agent is white WALL_CHAR: (300, 300, 300), # Wall, dark grey FLOOR_CHAR: (0, 0, 0), # Floor } for (c, _, _, _, col, _) in these_dancers_and_properties: fg_colours[c] = (999, 0, 0) if col == "red" else (0, 0, 999) bg_colours = { c: (0, 0, 0) for c in RESERVED_CHARS + POSSIBLE_DANCER_CHARS[1:8] } ui = human_ui.CursesUi( keys_to_actions={ # Basic movement. curses.KEY_UP: DIRECTIONS.N, curses.KEY_DOWN: DIRECTIONS.S, curses.KEY_LEFT: DIRECTIONS.W, curses.KEY_RIGHT: DIRECTIONS.E, -1: 8, # Do nothing. }, delay=500, colour_fg=fg_colours, colour_bg=bg_colours) ui.play(game)
def main(): # Build a game of tennnnnnnnnnnnnnnnnnnnnnnnis. game = make_game() # Build the croppers we'll use to make the observations. croppers = make_croppers() # Make a CursesUi to play it with. ui = human_ui.CursesUi( # Multi-agent arguments don't have to be dicts---they can be just about # anything; numpy arrays, scalars, nests, whatever. keys_to_actions={ 'r': { '1': Actions.UP, '2': Actions.STAY }, 'f': { '1': Actions.DOWN, '2': Actions.STAY }, 'u': { '1': Actions.STAY, '2': Actions.UP }, 'j': { '1': Actions.STAY, '2': Actions.DOWN }, 'q': { '1': Actions.STAY, '2': Actions.STAY, 'quit': True }, -1: { '1': Actions.STAY, '2': Actions.STAY }, }, delay=33, colour_fg=COLOUR_FG, colour_bg=COLOUR_BG, croppers=croppers) # Let the game begin! ui.play(game)