def test_mineral_init(self):
     """
     Check that minerals can be instantiated irregularly
     """
     stash   = parameters.get('stash_size')
     mineral = ResourceParticle(Vector.arrp(15,15))
     self.assertEqual(mineral.stash, stash)
     self.assertEqual(mineral.vel, Vector.arrp(0,1))
 def test_mineral_init(self):
     """
     Check that minerals can be instantiated irregularly
     """
     stash = parameters.get('stash_size')
     mineral = ResourceParticle(Vector.arrp(15, 15))
     self.assertEqual(mineral.stash, stash)
     self.assertEqual(mineral.vel, Vector.arrp(0, 1))
    def test_periodic_find_closest(self):
        """
        Test that the find nearest can see periodic boundaries
        """
        agents = [
            Particle(Vector.arrp(10, 10), Vector.rand(6), 'a'),
            Particle(Vector.arrp(10, 990), Vector.rand(6), 'b'),
            Particle(Vector.arrp(990, 10), Vector.rand(6), 'c'),
            Particle(Vector.arrp(990, 990), Vector.rand(6), 'd'),
        ]
        world = World(agents=agents, world_size=1000)

        expected = world.agents[1]
        observed = world.agents[0].find_nearest(100, 360)
        self.assertEqual(expected, observed)
    def test_periodic_find_closest(self):
        """
        Test that the find nearest can see periodic boundaries
        """
        agents = [
            Particle(Vector.arrp(10, 10), Vector.rand(6), 'a'),
            Particle(Vector.arrp(10, 990), Vector.rand(6), 'b'),
            Particle(Vector.arrp(990, 10), Vector.rand(6), 'c'),
            Particle(Vector.arrp(990, 990), Vector.rand(6), 'd'),
        ]
        world = World(agents=agents, world_size=1000)

        expected = world.agents[1]
        observed = world.agents[0].find_nearest(100, 360)
        self.assertEqual(expected, observed)
Example #5
0
    def __init__(self, pos, **kwargs):
        # Create the stash that the minerals contain
        self.stash = kwargs.get('stash_size', world_parameters.get('stash_size'))

        # Pass everything else back to super
        kwargs['team'] = kwargs.get('team', 'mineral')  # Add the default team
        super(ResourceParticle, self).__init__(pos, Vector.arrp(0,1), **kwargs)
    def test_periodic_neighborhood(self):
        """
        Test that the neighborhood can see periodic boundaries
        """
        agents = [
            Particle(Vector.arrp(10, 10), Vector.rand(6), 'a'),
            Particle(Vector.arrp(10, 990), Vector.rand(6), 'b'),
            Particle(Vector.arrp(990, 10), Vector.rand(6), 'c'),
            Particle(Vector.arrp(990, 990), Vector.rand(6), 'd'),
        ]
        world = World(agents=agents, world_size=1000)

        expected = {'b', 'c', 'd'}
        observed = set([])
        for neighbor in world.agents[0].neighbors(100, 360):
            observed.add(neighbor.idx)
        self.assertEqual(expected, observed)
    def test_periodic_neighborhood(self):
        """
        Test that the neighborhood can see periodic boundaries
        """
        agents = [
            Particle(Vector.arrp(10, 10), Vector.rand(6), 'a'),
            Particle(Vector.arrp(10, 990), Vector.rand(6), 'b'),
            Particle(Vector.arrp(990, 10), Vector.rand(6), 'c'),
            Particle(Vector.arrp(990, 990), Vector.rand(6), 'd'),
        ]
        world = World(agents=agents, world_size=1000)

        expected = {'b','c','d'}
        observed = set([])
        for neighbor in world.agents[0].neighbors(100, 360):
            observed.add(neighbor.idx)
        self.assertEqual(expected, observed)
Example #8
0
    def __init__(self, pos, **kwargs):
        # Create the stash that the minerals contain
        self.stash = kwargs.get('stash_size',
                                world_parameters.get('stash_size'))

        # Pass everything else back to super
        kwargs['team'] = kwargs.get('team', 'mineral')  # Add the default team
        super(ResourceParticle, self).__init__(pos, Vector.arrp(0, 1),
                                               **kwargs)
Example #9
0
 def relative_pos(self, point):
     size_x = self.world.size[0]
     size_y = self.world.size[1]
     rel_x = self.pos.x
     rel_y = self.pos.y
     if (abs(self.pos.x - point.x) > size_x / 2):
         rel_x += (-1 if (self.pos.x - point.x) > 0 else 1) * size_x
     if (abs(self.pos.y - point.y) > size_y / 2):
         rel_y += (-1 if (self.pos.y - point.y) > 0 else 1) * size_y
     return Vector.arrp(rel_x, rel_y)
Example #10
0
 def relative_pos(self, point):
     size_x = self.world.size[0]
     size_y = self.world.size[1]
     rel_x = self.pos.x
     rel_y = self.pos.y
     if (abs(self.pos.x - point.x) > size_x / 2):
         rel_x += (-1 if (self.pos.x - point.x) > 0 else 1) * size_x
     if (abs(self.pos.y - point.y) > size_y/ 2):
         rel_y += (-1 if (self.pos.y - point.y) > 0 else 1) * size_y
     return Vector.arrp(rel_x, rel_y)
    def test_mineral_mine(self):
        """
        Test mineral mining
        """
        stash = parameters.get('stash_size')
        mineral = ResourceParticle(Vector.arrp(15, 15))
        self.assertEqual(mineral.stash, stash)

        for i in xrange(0, stash):
            self.assertTrue(mineral.mine())

        self.assertFalse(mineral.mine())
        self.assertFalse(mineral)
    def test_mineral_mine(self):
        """
        Test mineral mining
        """
        stash   = parameters.get('stash_size')
        mineral = ResourceParticle(Vector.arrp(15,15))
        self.assertEqual(mineral.stash, stash)

        for i in xrange(0, stash):
            self.assertTrue(mineral.mine())

        self.assertFalse(mineral.mine())
        self.assertFalse(mineral)
Example #13
0
    def update_position(self):
        """
        Adds the velocity to get a new position, also ensures a periodic
        world by using modulo against the width and height of the world.
        """

        if self.state == STUNNED:
            self._pos = self.pos
            return

        newpos = self.pos + self._vel
        x = newpos.x % self.world.size[0]
        y = newpos.y % self.world.size[1]
        self._pos = Vector.arrp(x, y)
Example #14
0
    def update_position(self):
        """
        Adds the velocity to get a new position, also ensures a periodic
        world by using modulo against the width and height of the world.
        """

        if self.state == STUNNED:
            self._pos = self.pos
            return

        newpos = self.pos + self._vel
        x = newpos.x % self.world.size[0]
        y = newpos.y % self.world.size[1]
        self._pos = Vector.arrp(x,y)
    def setUp(self):
        agents = [
            Particle(Vector.arrp(90, 90), Vector.arrp(10, 10), 'a'),
            Particle(Vector.arrp(100, 140), Vector.arrp(10, 0), 'b'),
            Particle(Vector.arrp(120, 160), Vector.arrp(10, 0), 'c'),
            Particle(Vector.arrp(140, 140), Vector.arrp(0, 10), 'd'),
            Particle(Vector.arrp(140, 120), Vector.arrp(10, 10), 'e'),
            Particle(Vector.arrp(180, 220), Vector.arrp(10, 0), 'f'),
            Particle(Vector.arrp(60, 50), Vector.arrp(-10, -10), 'g'),
        ]

        self.world = World(agents=agents)
        self.particle = self.world.agents[0]
        assert self.particle.idx == 'a'
    def setUp(self):
        agents = [
            Particle(Vector.arrp(90,90),   Vector.arrp(10, 10),   'a', team='blue'),
            Particle(Vector.arrp(50,50),   Vector.arrp(10, 0),    'b', team='blue'),
            Particle(Vector.arrp(130,130), Vector.arrp(10, 0),    'c', team='blue'),
            Particle(Vector.arrp(90, 50),  Vector.arrp(0 , 10),   'd', team='blue'),
            Particle(Vector.arrp(90, 130), Vector.arrp(10, 10),   'e', team='blue'),
            Particle(Vector.arrp(50, 90),  Vector.arrp(10, 0),    'f', team='gold'),
            Particle(Vector.arrp(130, 90), Vector.arrp(-10,-10),  'g', team='gold'),
            Particle(Vector.arrp(130, 50), Vector.arrp(10, 0),    'h', team='gold'),
            Particle(Vector.arrp(50, 130), Vector.arrp(10, -10),  'i', team='gold'),
            Particle(Vector.arrp(50, 70),  Vector.arrp( -10, 10), 'j', team='gold'),
            Particle(Vector.arrp(80, 75),  Vector.arrp(-10,-10),  'k', team='enemy'),
        ]

        self.world    = World(agents=agents)
        self.particle = self.world.agents[0]
        assert self.particle.idx == 'a'
    def setUp(self):
        agents = [
            Particle(Vector.arrp( 90 ,90 ), Vector.arrp( 10, 10), 'a'),
            Particle(Vector.arrp( 100,140), Vector.arrp( 10, 0 ), 'b'),
            Particle(Vector.arrp( 120,160), Vector.arrp( 10, 0 ), 'c'),
            Particle(Vector.arrp( 140,140), Vector.arrp( 0 , 10), 'd'),
            Particle(Vector.arrp( 140,120), Vector.arrp( 10, 10), 'e'),
            Particle(Vector.arrp( 180,220), Vector.arrp( 10, 0 ), 'f'),
            Particle(Vector.arrp( 60 ,50 ), Vector.arrp(-10,-10), 'g'),
        ]

        self.world    = World(agents=agents)
        self.particle = self.world.agents[0]
        assert self.particle.idx == 'a'
    def setUp(self):
        agents = [
            Particle(Vector.arrp(90, 90),
                     Vector.arrp(10, 10),
                     'a',
                     team='blue'),
            Particle(Vector.arrp(50, 50), Vector.arrp(10, 0), 'b',
                     team='blue'),
            Particle(Vector.arrp(130, 130),
                     Vector.arrp(10, 0),
                     'c',
                     team='blue'),
            Particle(Vector.arrp(90, 50), Vector.arrp(0, 10), 'd',
                     team='blue'),
            Particle(Vector.arrp(90, 130),
                     Vector.arrp(10, 10),
                     'e',
                     team='blue'),
            Particle(Vector.arrp(50, 90), Vector.arrp(10, 0), 'f',
                     team='gold'),
            Particle(Vector.arrp(130, 90),
                     Vector.arrp(-10, -10),
                     'g',
                     team='gold'),
            Particle(Vector.arrp(130, 50),
                     Vector.arrp(10, 0),
                     'h',
                     team='gold'),
            Particle(Vector.arrp(50, 130),
                     Vector.arrp(10, -10),
                     'i',
                     team='gold'),
            Particle(Vector.arrp(50, 70),
                     Vector.arrp(-10, 10),
                     'j',
                     team='gold'),
            Particle(Vector.arrp(80, 75),
                     Vector.arrp(-10, -10),
                     'k',
                     team='enemy'),
        ]

        self.world = World(agents=agents)
        self.particle = self.world.agents[0]
        assert self.particle.idx == 'a'