def play(player1, player2): global p1, p2, p1_position, p2_position, game_over, current_player, next_move # make sure that both names are valid model names if (player1.lower() in (x.lower() for x in actr.mp_models())) and ( player2.lower() in (x.lower() for x in actr.mp_models())): actr.reset() actr.add_command('make-move', make_move, "Model action function in simple capture game.") # create the goal chunks actr.set_current_model(player1) actr.define_chunks([ 'goal', 'isa', 'play', 'my-pos', 'p1', 'p1', 0, 'p2', 5, 'state', 'move' ]) actr.goal_focus('goal') actr.set_current_model(player2) actr.define_chunks([ 'goal', 'isa', 'play', 'my-pos', 'p1', 'p2', 0, 'p2', 5, 'state', 'move' ]) actr.goal_focus('goal') # initialize the game information p1 = player1 p2 = player2 p1_position = 0 p2_position = 5 game_over = False current_player = player1 next_move = None while not (game_over): # until a move is made which breaks the run # or 1000 simulated seconds pass which is a forfeit actr.run(1000) process_move(next_move) # Give them a chance to process results actr.run_full_time(3) actr.remove_command('make-move') return game_over
def test_it (): actr.reset() actr.add_command("relay-speech-output", relay_speech_output, "Handle player speak actions") actr.monitor_command("output-speech","relay-speech-output") for m in actr.mp_models(): actr.set_current_model(m) actr.install_device(["speech","microphone"]) actr.run(10) actr.remove_command_monitor("output-speech", "relay-speech-output") actr.remove_command("relay-speech-output")
def relay_speech_output (model, string): for m in actr.mp_models(): if not (m.lower() == model.lower()): # all other models will hear this actr.set_current_model(m) # Create the originating model's name as a simple chunk if # it isn't one already to avoid a warning of it being # created by default when the sound is generated. if not(actr.chunk_p(model)): actr.define_chunks(model) # Create the sound as a word with location indicating # the speaker. actr.new_word_sound(string, actr.mp_time(), model)
def process_moves(model, string): global p1_position, p2_position, current_player, p1_text, p2_text # Let all other models hear this for m in actr.mp_models(): if not (m.lower() == model.lower()): # all other models will hear this actr.set_current_model(m) # Create the originating model's name as a simple chunk if # it isn't one already to avoid a warning of it being # created by default when the sound is generated. if not (actr.chunk_p(model)): actr.define_chunks(model) # Create the sound as a word with location indicating # the speaker. actr.new_word_sound(string, actr.mp_time(), model) if (string.lower() == "one"): move = 1 elif (string.lower() == "two"): move = 2 else: print("Wrong move assumed to be 1: %s" % string) move = 1 if current_player == p1: p1_position += move else: p2_position -= move actr.clear_exp_window(window) if (p2_position <= p1_position): # if there's a winner actr.schedule_event_relative(3, 'set_game_over', params=[current_player]) actr.add_text_to_exp_window(window, current_player, x=60, y=20, color='green', height=30, width=80, font_size=20) else: # not a winner so update the display with the new position p1_text = actr.add_text_to_exp_window(window, str(p1_position), x=20, y=10, color='red', height=30, width=30, font_size=20) p2_text = actr.add_text_to_exp_window(window, str(p2_position), x=140, y=10, color='blue', height=30, width=30, font_size=20) if current_player == p1: current_player = p2 else: current_player = p1
def play(player1, player2): global window, p1, p2, p1_position, p2_position, current_player, game_over, safety_stop, p1_text, p2_text if (player1.lower() in (x.lower() for x in actr.mp_models())) and ( player2.lower() in (x.lower() for x in actr.mp_models())): actr.reset() actr.set_current_model(player1) # create a goal chunk with the player's color and name actr.define_chunks([ 'goal', 'isa', 'play', 'my-color', 'red', 'my-name', "'%s'" % player1 ]) actr.goal_focus('goal') actr.set_parameter_value(':show-focus', 'red') actr.set_current_model(player2) # create a goal chunk with the player's color and name actr.define_chunks([ 'goal', 'isa', 'play', 'my-color', 'blue', 'my-name', "'%s'" % player2 ]) actr.goal_focus('goal') actr.set_parameter_value(':show-focus', 'blue') window = actr.open_exp_window("game", visible=True, width=200, height=100) safety_window = actr.open_exp_window('Safety', visible=True, height=100, width=100, x=100, y=100) actr.add_command('stop-a-run', stop_a_run, 'Set the flag to terminate the game.') actr.add_button_to_exp_window(safety_window, text="STOP", x=0, y=0, action='stop-a-run', height=80, width=80, color='red') p1 = player1 p2 = player2 game_over = False safety_stop = False current_player = player1 p1_position = 0 p2_position = 5 for m in actr.mp_models(): actr.set_current_model(m) actr.install_device(window) p1_text = actr.add_text_to_exp_window(window, str(p1_position), x=20, y=10, color='red', height=30, width=30, font_size=20) p2_text = actr.add_text_to_exp_window(window, str(p2_position), x=140, y=10, color='blue', height=30, width=30, font_size=20) actr.add_command("process-moves", process_moves, "Handle player speak actions") actr.monitor_command("output-speech", "process-moves") # speak to all models telling them the name # of the first player. for m in actr.mp_models(): actr.set_current_model(m) actr.new_word_sound(p1, 0, 'start') actr.add_command('is-game-over', is_game_over, 'Test whether game should stop running.') actr.add_command('set_game_over', set_game_over, 'Set the flag to stop the game.') actr.run_until_condition('is-game-over', True) actr.remove_command_monitor("output-speech", "process-moves") actr.remove_command("process-moves") actr.remove_command('stop-a-run') actr.remove_command('is-game-over') actr.remove_command('set_game_over') return game_over
def play(player1, player2): global p1, p2, p1_position, p2_position, game_over, current_player, safety_stop, winner, p1p1, p1p2, p2p1, p2p2 if (player1.lower() in (x.lower() for x in actr.mp_models())) and ( player2.lower() in (x.lower() for x in actr.mp_models())): actr.add_command('stop-a-run', stop_a_run, 'Set the flag to terminate the game.') win = actr.open_exp_window('Safety', visible=True, height=100, width=100, x=100, y=300) actr.add_button_to_exp_window('Safety', text='STOP', x=0, y=0, action='stop-a-run', height=90, width=90, color='red') actr.add_command('move', make_move, 'Handle player key presses') actr.monitor_command('output-key', 'move') actr.reset() # initialize the game information p1 = player1 p2 = player2 p1_position = 0 p2_position = 5 game_over = False current_player = player1 safety_stop = False winner = None actr.set_current_model(player1) actr.define_chunks(player2) feats = actr.add_visicon_features([ 'isa', ['player-loc', 'player'], 'screen-x', 0, 'screen-y', 0, 'name', player1, 'position', [False, p1_position], 'turn', [False, True] ], [ 'isa', ['player-loc', 'player'], 'screen-x', 100, 'screen-y', 0, 'name', player2, 'position', [False, p2_position] ]) p1p1 = feats[0] p1p2 = feats[1] actr.set_current_model(player2) actr.define_chunks(player1) feats = actr.add_visicon_features([ 'isa', ['player-loc', 'player'], 'screen-x', 0, 'screen-y', 0, 'name', player1, 'position', [False, p1_position], 'turn', [False, True] ], [ 'isa', ['player-loc', 'player'], 'screen-x', 100, 'screen-y', 0, 'name', player2, 'position', [False, p2_position] ]) p2p1 = feats[0] p2p2 = feats[1] actr.add_command('is-game-over', is_game_over, 'Test whether game should stop running.') actr.add_command('set_game_over', set_game_over, 'Set the flag to stop the game.') actr.run_until_condition('is-game-over') actr.clear_exp_window(win) actr.remove_command('stop-a-run') actr.remove_command_monitor('output-key', 'move') actr.remove_command('move') actr.remove_command('is-game-over') actr.remove_command('set_game_over') return winner
def play(player1, player2): global p1, p2, game_over, safety_stop, current_player, p1_position, p2_position, window if (player1.lower() in (x.lower() for x in actr.mp_models())) and ( player2.lower() in (x.lower() for x in actr.mp_models())): actr.reset() # initialize game info p1 = player1 p2 = player2 game_over = False safety_stop = False current_player = player1 p1_position = 0 p2_position = 5 window = actr.open_exp_window("game", visible=True, width=300, height=100) safety_window = actr.open_exp_window('Safety', visible=True, height=100, width=100, x=100, y=100) actr.add_command('stop-a-run', stop_a_run, 'Set the flag to terminate the game.') actr.add_command('pick-button', pick_button, 'Button action function.') actr.add_button_to_exp_window(safety_window, text="STOP", x=0, y=0, action='stop-a-run', height=80, width=80, color='red') for m in actr.mp_models(): actr.set_current_model(m) actr.install_device(window) for i in range(6): if i == 0: b = "1" c = 'red' elif i == 5: b = "2" c = 'white' else: b = "" c = 'white' spaces[i] = actr.add_button_to_exp_window( window, text=b, x=10 + (i * 40), y=10, action=['pick-button', i], height=35, width=35, color=c) actr.add_command('is-game-over', is_game_over, 'Test whether game should stop running.') actr.add_command('set_game_over', set_game_over, 'Set the flag to stop the game.') # Run ACT-R until the game is over actr.run_until_condition('is-game-over') actr.remove_command('stop-a-run') actr.remove_command('pick-button') actr.remove_command('is-game-over') actr.remove_command('set_game_over') return game_over
with sc2_env.SC2Env( map_name="MoveToBeacon", #map_name="MoveToBeacon", step_mul=step_mul, game_steps_per_episode=steps * step_mul, save_replay_episodes=5, replay_dir='/Users/paulsomers/StarcraftMAC/MyAgents/', screen_size_px=(128, 128)) as env: # # agent = scripted_agent.MoveToBeacon() myAgent = server_agent run_loop.run_loop([myAgent], env, steps) print('Reward: ', myAgent.reward, ' | Episodes: ', myAgent.episodes) #env.save_replay('/Users/paulsomers/StarcraftMAC/MyAgents/') #start the game if __name__ == '__main__': thread = threading.Thread(target=game_thread, args=sys.argv) thread.start() time.sleep(25) act_thread = threading.Thread(target=actr.run, args=[300]) act_thread.start() #for x in range(1000): # actr.process_events() print(actr.mp_models()) print("test")
def play(player1, player2): global p1, p2, game_over, safety_stop, current_player, p1_position, p2_position, p1_window, p2_window, p1_spaces, p2_spaces if (player1.lower() in (x.lower() for x in actr.mp_models())) and ( player2.lower() in (x.lower() for x in actr.mp_models())): actr.reset() # initialize game info p1 = player1 p2 = player2 game_over = False current_player = player1 p1_position = 0 p2_position = 5 # open a window for each model and the safety stop button p1_window = actr.open_exp_window("player1", visible=True, width=300, height=100, x=100, y=100) p2_window = actr.open_exp_window("player2", visible=True, width=300, height=100, x=450, y=100) safety_window = actr.open_exp_window('Safety', visible=True, height=100, width=100, x=100, y=300) actr.add_command('stop-a-run', stop_a_run, 'Set the flag to terminate the game.') actr.add_command('pick-button', pick_button, 'Button action function.') actr.add_button_to_exp_window(safety_window, text="STOP", x=0, y=0, action='stop-a-run', height=80, width=80, color='red') for i in range(6): if i == 0: b = "1" p1_c = 'red' elif i == 5: b = "2" p1_c = 'white' else: b = "" p1_c = 'white' p1_spaces[i] = actr.add_button_to_exp_window( p1_window, text=b, x=(10 + (i * 40)), y=10, action=['pick-button', p1, i], height=35, width=35, color=p1_c) p2_spaces[i] = actr.add_button_to_exp_window( p2_window, text=b, x=(10 + (i * 40)), y=10, action=['pick-button', p2, (5 - i)], height=35, width=35, color='white') actr.set_current_model(p1) actr.install_device(p1_window) actr.set_current_model(p2) actr.install_device(p2_window) actr.run(10000, True) actr.remove_command('stop-a-run') actr.remove_command('pick-button') return game_over