def multiplayer_client(self, event): self.ip = self.entr.get() if not client.check_connection(self.ip): win = tkinter.Toplevel(self.window) lab = tkinter.Label(win, text="Wrong IP") lab.pack() return None save_ip(self.ip) self.two_players_variant('multiplayer_client') d = Data_Maker() def blocking_board(event): pass self.board.make_usability(blocking_board) state = client.get_state(self.board, load_ip()) state = json.loads(state) state[1]['regim'] = 'multiplayer_client' d.decode_board(self.board, self.game, state)
def change_side(self, board): def blocking_board(event): pass self.move_whites = not self.move_whites if self.regim == 'multiplayer_client': d = datamaker.Data_Maker() state = json.dumps(d.encode_board(board, self)) board.make_usability(blocking_board) client.send_state(state, board, load_ip()) state = client.get_state(board, load_ip()) state = json.loads(state) state[1]['regim'] = 'multiplayer_client' d.decode_board(board, self, state) if self.regim == 'multiplayer_server': d = datamaker.Data_Maker() state = json.dumps(d.encode_board(board, self)) board.make_usability(blocking_board) server.send_state(state, board) state = server.get_state(board) state = json.loads(state) state[1]['regim'] = 'multiplayer_server' d.decode_board(board, self, state)
return "left" else: return "right" else: # We can stop turning now if distance > Bounds.MAX_DISTANCE: # But we need to move closer return "forward" else: # We are close enough return "stop" action = "stop" while True: state = client.get_state() if MY_NUM not in state["labels"] or TARGET_NUM not in state["labels"]: continue my_pose = state["labels"][MY_NUM] target_pose = state["labels"][TARGET_NUM] action = next_action(my_pose, target_pose, action) print(action) robot.action(action) time.sleep(0.2)
def reset(self): self.curr_state = client.get_state() return self.curr_state
def step(self, action): client.set_speed(action) next_state = client.get_state() reward = self.get_reward(self.curr_state, next_state) done = False return obs, reward, done, None