Esempio n. 1
0
    def test_currently_alive_one_alive_neighbor(self):
        world = [
            ['a', '.', '.'],
            ['.', 'a', '.'],
            ['.', '.', '.'],
        ]

        neighbors = world_helper.getNeighbors(world, 1, 1)
        new_state = world_helper.determineCellState(neighbors, 'a')

        self.assertEqual(new_state, 'd')
Esempio n. 2
0
    def test_top_left_cell(self):
        world = [
            ['.', 'a', '.'],
            ['a', 'a', '.'],
            ['.', '.', '.'],
        ]

        neighbors = world_helper.getNeighbors(world, 0, 0)
        expected = ['a', 'a', 'a']

        self.assertEqual(neighbors, expected)
Esempio n. 3
0
    def test_bottom_right_cell(self):
        world = [
            ['a', 'a', 'a'],
            ['a', '.', '.'],
            ['a', '.', 'a'],
        ]

        neighbors = world_helper.getNeighbors(world, 2, 2)
        expected = ['.', '.', '.']

        self.assertEqual(neighbors, expected)
Esempio n. 4
0
    def test_center_cell_some_alive(self):
        world = [
            ['a', '.', 'a'],
            ['.', 'a', '.'],
            ['a', 'a', 'a'],
        ]

        neighbors = world_helper.getNeighbors(world, 1, 1)
        expected = ['a', '.', 'a', '.', '.', 'a', 'a', 'a']

        self.assertEqual(neighbors, expected)
Esempio n. 5
0
    def test_center_cell_surrounded_by_dead(self):
        world = [
            ['.', '.', '.'],
            ['.', 'a', '.'],
            ['.', '.', '.'],
        ]

        neighbors = world_helper.getNeighbors(world, 1, 1)
        expected = ['.', '.', '.', '.', '.', '.', '.', '.']

        self.assertEqual(neighbors, expected)
Esempio n. 6
0
File: geom.py Progetto: orel33/ants
def foodDir(world, antpos):
    maxfood = 0
    bestdir = -1
    for direction in world.getNeighbors(antpos,
                                        onlyvalid=True,
                                        allowfood=True,
                                        returndir=True):
        neighborpos = world.getNeighbor(antpos, direction)
        food = world.getFood(neighborpos)
        if (food > maxfood):
            maxfood = food
            bestdir = direction
    return bestdir
Esempio n. 7
0
File: geom.py Progetto: orel33/ants
def pheromoneDir(world, antpos, homepos, optdist):
    antdist = distance(homepos, antpos)
    maxpheromone = 0
    bestdir = -1
    for direction in world.getNeighbors(antpos, onlyvalid=True,
                                        returndir=True):
        neighborpos = world.getNeighbor(antpos, direction)
        pheromone = world.getPheromone(neighborpos)
        neighbordist = distance(homepos, neighborpos)
        if ((not optdist) and (pheromone > maxpheromone)):
            maxpheromone = pheromone
            bestdir = direction
        if (optdist and (pheromone > maxpheromone)
                and (neighbordist > antdist)):
            maxpheromone = pheromone
            bestdir = direction
    return bestdir
Esempio n. 8
0
File: geom.py Progetto: orel33/ants
def targetDir(world, antpos, targetpos):
    if antpos == targetpos:
        return -1
    b = bresenham.bresenham(antpos[0], antpos[1], targetpos[0], targetpos[1])
    nextpos = next(b)
    if (nextpos == antpos):
        nextpos = next(b)
    # find direction
    bestdir = -1
    for direction in world.getNeighbors(antpos,
                                        onlyvalid=True,
                                        allowblock=False,
                                        allowfood=False,
                                        returndir=True):
        pos = world.getNeighbor(antpos, direction)
        if nextpos == pos:
            bestdir = direction
            break
    return bestdir