Пример #1
0
    def ParseGameState(self, s):
        game_log(s)
        game_log("go\n")

        self._planets = []
        self._fleets = []
        lines = s.split("\n")
        planet_id = 0

        for line in lines:
            line = line.split("#")[0]  # remove comments
            tokens = line.split(" ")
            if len(tokens) == 1:
                continue
            if tokens[0] == "P":
                if len(tokens) != 6:
                    return 0
                p = Planet(
                    planet_id,  # The ID of this planet
                    int(tokens[3]),  # Owner
                    int(tokens[4]),  # Num ships
                    int(tokens[5]),  # Growth rate
                    float(tokens[1]),  # X
                    float(tokens[2]))  # Y
                planet_id += 1
                self._planets.append(p)
            elif tokens[0] == "F":
                if len(tokens) != 7:
                    return 0
                f = Fleet(
                    int(tokens[1]),  # Owner
                    int(tokens[2]),  # Num ships
                    int(tokens[3]),  # Source
                    int(tokens[4]),  # Destination
                    int(tokens[5]),  # Total trip length
                    int(tokens[6]))  # Turns remaining
                self._fleets.append(f)
            else:
                return 0
        return 1
Пример #2
0
  def ParseGameState(self, s):
    game_log(s)
    game_log("go\n")

    self._planets = []
    self._fleets = []
    lines = s.split("\n")
    planet_id = 0

    for line in lines:
      line = line.split("#")[0] # remove comments
      tokens = line.split(" ")
      if len(tokens) == 1:
        continue
      if tokens[0] == "P":
        if len(tokens) != 6:
          return 0
        p = Planet(planet_id, # The ID of this planet
                   int(tokens[3]), # Owner
                   int(tokens[4]), # Num ships
                   int(tokens[5]), # Growth rate
                   float(tokens[1]), # X
                   float(tokens[2])) # Y
        planet_id += 1
        self._planets.append(p)
      elif tokens[0] == "F":
        if len(tokens) != 7:
          return 0
        f = Fleet(int(tokens[1]), # Owner
                  int(tokens[2]), # Num ships
                  int(tokens[3]), # Source
                  int(tokens[4]), # Destination
                  int(tokens[5]), # Total trip length
                  int(tokens[6])) # Turns remaining
        self._fleets.append(f)
      else:
        return 0
    return 1