Exemplo n.º 1
0
 def tick(self):
     if self.next_dir == None:
         self.keypress()
     else:
         new_msg = PacmanCommand()
         new_msg.dir = self.next_dir
         self.write(new_msg.SerializeToString(), MsgType.PACMAN_COMMAND)
         self.next_dir = None
Exemplo n.º 2
0
    def tick(self):
        if self.state and self.state.mode == LightState.RUNNING:
            p_loc = (self.state.pacman.x, self.state.pacman.y)
            
            # update game state
            if self.grid[p_loc[0]][p_loc[1]] in [o, O]:
                self.grid[p_loc[0]][p_loc[1]] = e
 
            path = bfs(self.grid, p_loc, self.state, [o, O])
            print(path)

            if path != None:
                next_loc = path[1]
                # Figure out position we need to move
                new_msg = PacmanCommand()
                new_msg.dir = self._get_direction(p_loc, next_loc)
                self.write(new_msg.SerializeToString(), MsgType.PACMAN_COMMAND)
                return

        new_msg = PacmanCommand()
        new_msg.dir = PacmanCommand.STOP
        self.write(new_msg.SerializeToString(), MsgType.PACMAN_COMMAND)
 def _send_stop_command(self):
     new_msg = PacmanCommand()
     new_msg.dir = PacmanCommand.STOP
     self.write(new_msg.SerializeToString(), MsgType.PACMAN_COMMAND)
 def _send_command_message_to_target(self, p_loc, target):
     new_msg = PacmanCommand()
     new_msg.dir = self._get_direction(p_loc, target)
     self.write(new_msg.SerializeToString(), MsgType.PACMAN_COMMAND)