Ejemplo n.º 1
0
    def __init__(self, bzrc):
        super(NonConformingAgent, self).__init__(bzrc)

        self.invocations_before_update = 0
        self.invocation_count = 0
        self.boundaries = WorldBoundaries(bzrc)
        self.enemies = Enemies(bzrc)
        self.last_vector = Vec2d(0.0, 0.0)
Ejemplo n.º 2
0
class NonConformingAgent(Agent):
    """Class handles all command and control logic for a teams tanks."""

    def __init__(self, bzrc):
        super(NonConformingAgent, self).__init__(bzrc)

        self.invocations_before_update = 0
        self.invocation_count = 0
        self.boundaries = WorldBoundaries(bzrc)
        self.enemies = Enemies(bzrc)
        self.last_vector = Vec2d(0.0, 0.0)

    def get_field_vector(self, tank):
        if self.invocation_count < self.invocations_before_update:
            self.invocation_count += 1
            return self.last_vector, False

        self.invocation_count = 0
        self.invocations_before_update = random.randrange(100, 600)
        print "updated invocations_before_update to %s" % self.invocations_before_update

        print "checking for boundaries"
        field_vec, shoot = self.boundaries.vector_at(tank.x, tank.y)
        if field_vec.x != 0 or field_vec.y != 0:
            print "avoiding boundaries"
            print ""
            self.last_vector = field_vec
            return field_vec, False

        print "checking for enemy tanks"
        field_vec, shoot = self.enemies.vector_at(tank.x, tank.y)
        if field_vec.x != 0 or field_vec.y != 0:
            print "avoiding enemy tanks"
            print ""
            self.last_vector = field_vec
            return field_vec, False

        print "generating 'random' vector"
        print ""
        vx = random.uniform(-1.0, 1.0)
        vy = random.uniform(-1.0, 1.0)
        scale = random.uniform(-1.0, 1.0)
        self.last_vector = Vec2d(vx, vy).normalized()
        return self.last_vector * scale, False
Ejemplo n.º 3
0
class StraightAgent(Agent):
    """Class handles all command and control logic for a teams tanks."""
    def __init__(self, bzrc):
        super(StraightAgent, self).__init__(bzrc)

        self.target_velocity = random.uniform(0.5, 1)
        self.boundaries = WorldBoundaries(bzrc)
        self.enemies = Enemies(bzrc)

    def get_field_vector(self, tank):
        field_vec, shoot = self.boundaries.vector_at(tank.x, tank.y)
        if field_vec.x != 0 or field_vec.y != 0:
            return field_vec, False

        field_vec, shoot = self.enemies.vector_at(tank.x, tank.y)
        if field_vec.x != 0 or field_vec.y != 0:
            return field_vec, False

        # if the tank has some velocity, then just use that
        if tank.vx != 0 and tank.vy != 0:
            return Vec2d(tank.vx, tank.vy), False

        # just go in the direction that the tank is currently pointing
        return Vec2d(math.cos(tank.angle), math.sin(tank.angle)), False
Ejemplo n.º 4
0
    def __init__(self, bzrc):
        super(StraightAgent, self).__init__(bzrc)

        self.target_velocity = random.uniform(0.5, 1)
        self.boundaries = WorldBoundaries(bzrc)
        self.enemies = Enemies(bzrc)