from warground import * from whrandom import * #Privat Classes: it's allowed to examine all variables and instances, but not to change #clan-class is in warground.py and has the variables id [0..9], count [0..10], and n #robot-class is has the variables x, y, id [00..99], look(), get_robots(), clan and n #All APT-functions are functions of the robot class. the clan class has no API class robot(robot_base): #Clan functions def get_clan_id(self): return int(self.clan.id) def get_clan_members(self): ret = [] for r in self.get_robots(): if r.clan is self.clan: ret.append(r) return r def can_make(self): return (10 - self.clan.count) def set_clan_info(self, key, value): setattr(self.clan, key, value) def get_clan_info(self, key): try: return getattr(self.clan, key) except: return None def clan_counter(self): n = get_clan_info('counter') if n == None: n = 1 else: n = n + 1 set_clan_info('counter', n) return n def set_clan_target(self, t): self.set_clan_info('clan_target', t) def get_clan_target(self): return self.get_clan_info('clan_target') def get_clan_dir(self): friend = self.get_closest_friend() if self.distance(friend) > 1: return self.direction(friend) else: return self.direction(self.get_clan_target()) #eRobot functions def get_robot_id(self): return int(self.id) def get_closest_friend(self): close = None for r in self.get_robots(): if (self.distance(r) < self.distance(close)) and r.get_clan_id() == self.get_clan_id() and r is not self: close = r return close def get_closest_enemy(self): close = None for r in self.get_robots(): if (self.distance(r) < self.distance(close)) and r.get_clan_id() != self.get_clan_id(): close = r return close def set_robot_info(self, key, value): setattr(self, key, value) def get_robot_info(self, key): try: return getattr(self, key) except: return None def robot_counter(self): n = get_robot_info('counter') if n == None: n = 1 else: n = n + 1 set_robot_info('counter', n) return n def distance(self, to): if to == None: return None else: return (abs(self.x-to.x) + abs(self.y-to.y)) def direction(self, to): if to == None: return None else: dx, dy = to.x - self.x, to.y - self.y if abs(dx) > abs(dy): if dx <= 0: ret = "left" else: ret = "right" else: if dy <= 0: ret = "up" else: ret = "down" return ret #Other functions def cmd_random(self): return ["pass", "move", "make"][randint(0,2)] def dir_random(self): return ["up", "left", "down", "right"][randint(0,3)] def dir_opposite(self, dir): if dir == "up": return "down" elif dir == "down": return "up" elif dir == "left": return "right" elif dir == "rigth": return "left" else: return ""