Example #1
0
 def poporder(oldloc, vectors):
     try:
         vector = vectors.next()
     except StopIteration:
         vector = '='
     newloc = self.wrap(antmath.displace_loc(vector, oldloc))
     return (newloc, vector) \
            if newloc not in self.water and newloc not in self.food \
            else poporder(oldloc, vectors)
Example #2
0
    def ray(self, origin, target):
        '''Is there a direct path from the origin to the target?'''
        origin = self.wrap(self.int(origin))
        target = self.unwrap(origin, self.int(target))

        # return a stored answer
        try:
            return self.rays[origin, target]
        except KeyError:
            pass

        # trivial
        if origin == target:
            return True

        # don't check long paths
        if self.dist2(origin, target) > self.rad2:
            return False

        # check path
        o = [origin]
        t = [target]
        # this loop has a bug and sometimes ran forever as a while loop
        # changed it to a for loop because the contest end was near!
        for _ in xrange(150):
            v, _ = am.naive_dir(o[-1], t[-1])
            o.append(self.wrap(am.displace_loc(v, o[-1])))
            t.append(self.unwrap(o[-1], t[-1]))
            if o[-1] == t[-1]:
                break

        # did the path pass through water?
        if self.water.viewkeys() & o:
            return False

        # remember the result
        for co, ct in itertools.izip(o[:-1], t[:-1]):
            self.rays[co, ct] = True

        return self.rays[origin, target]