def main(args): host = args.host port = args.port addr = (host, port) s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) BUF_SIZE = 1024 action = actions.get_action(args.action, args.extra_args) data = json.dumps(action.to_data()).encode(encoding="UTF-8") s.settimeout(5) r_data = None try: s.sendto(data, addr) r_data = json.loads(s.recv(BUF_SIZE)) except socket.timeout: print("Socket timeout") finally: s.close() if r_data == "OK": print("Succeed") else: print("Fail")
def parse_action(action): ret = { 'klass': None, 'params': {}, } ret['klass'] = get_action(action.get('action', 'print')) ret['params'] = action.get('params', {}) return ret
def update(self, state): state_vector = get_state_vector(state, self.name) state_vector = tf.convert_to_tensor([state_vector]) logits = self.bot.actor(state_vector) probs = tf.nn.softmax(logits[0]).numpy() probs = (1 - epsilon) * probs + epsilon / ACTION_SIZE best_action_id = np.random.choice(ACTION_SIZE, p=probs) reward = determine_reward(self.old_state, state, self.old_action_id) if (reward != None): allies_killed, enemies_killed = calc_kills(self.old_state, state) if (allies_killed == 0) & (enemies_killed != 0): self.nb_proper_kills += 1 elif (enemies_killed != 0): self.nb_kamikaze += 1 get_value_loss, get_policy_loss = self.get_loss_computers( state_vector, reward, (state["type"] == "endOfGame" )) # calling them in the right order is important self.bot.optimizer_critic.minimize(get_value_loss) self.bot.optimizer_actor.minimize(get_policy_loss) save_step_data(self.id, self.name, self.step - 1, self.old_probs.tolist(), self.old_action_id, reward, (allies_killed == 0) & (enemies_killed != 0), (allies_killed != 0) & (enemies_killed != 0)) if (state["type"] == "endOfGame"): save_episode_data(self.id, self.name, self.step, self.nb_proper_kills, self.nb_kamikaze, state["value"]) self.bot.save() self.old_state_vector = state_vector self.old_action_id = best_action_id self.old_state = state self.old_probs = probs action = get_action(state, best_action_id) self.sio.emit("action-{}".format(self.id), action)
def create_details_dialog(self, path, name, new): return ActionDetailDialog(self.get_parent_window(), actions.get_action(name))
def on_enable_disable(self, action_path): action = actions.get_action(action_path) menu, index = self._items[action_path] menu.entryconfig(index, state=('normal' if action.enabled else 'disabled'))
def on_new_action(self, event): self.setup_action(actions.get_action(event.data))