예제 #1
0
 def test_move_to_wall(self):
     world = World()
     old_location = Location(1, 1)
     bot = Bot(old_location, world)
     world.update_cell(old_location, bot)
     bot.direction = Direction.NW
     bot.move(0)
     self.assertEqual(CellType.WALL, world.get_cell(Location(0, 0)))
     self.assertTrue(isinstance(world.get_cell(old_location), Bot))
     self.assertEqual(Direction.NW, bot.direction)
     self.assertEqual(ROTATE_45_DEGREE_GENE, bot.genes.get_next())
예제 #2
0
 def test_lookup_empty(self):
     world = World()
     location = Location(2, 2)
     bot = Bot(location, world)
     world.update_cell(location, bot)
     world.update_cell(Location(3, 1), CellType.EMPTY)
     bot.energy = 77
     bot.direction = Direction.NE
     bot.lookup(0)
     self.assertEqual(77, bot.energy)
     self.assertEqual(Direction.NE, bot.direction)
     self.assertEqual(ROTATE_45_DEGREE_GENE, bot.genes.get_next())
     self.assertTrue(isinstance(world.get_cell(location), Bot))
예제 #3
0
 def test_move_to_poison(self):
     world = World()
     old_location = Location(3, 1)
     expected_future_location = Location(4, 2)
     world.update_cell(expected_future_location, CellType.POISON)
     bot = Bot(old_location, world)
     world.update_cell(old_location, bot)
     bot.direction = Direction.E
     bot.move(1)
     self.assertEqual(CellType.POISON,
                      world.get_cell(expected_future_location))
     self.assertEqual(CellType.EMPTY, world.get_cell(old_location))
     self.assertEqual(Direction.E, bot.direction)
예제 #4
0
 def test_move_to_empty(self):
     world = World()
     old_location = Location(2, 2)
     bot = Bot(old_location, world)
     world.update_cell(old_location, bot)
     expected_future_location = Location(2, 1)
     world.update_cell(expected_future_location, CellType.EMPTY)
     bot.direction = Direction.N
     bot.move(0)
     self.assertTrue(
         isinstance(world.get_cell(expected_future_location), Bot))
     self.assertEqual(CellType.EMPTY, world.get_cell(old_location))
     self.assertEqual(Direction.N, bot.direction)
예제 #5
0
 def test_peek_wall(self):
     world = World()
     bot_location = Location(1, 1)
     bot = Bot(bot_location, world)
     world.update_cell(bot_location, bot)
     bot.energy = 77
     bot.direction = Direction.E
     bot.lookup(7)
     self.assertEqual(77, bot.energy)
     self.assertEqual(Direction.E, bot.direction)
     self.assertEqual(CellType.WALL, world.get_cell(Location(0, 0)))
     self.assertTrue(isinstance(world.get_cell(bot_location), Bot))
     self.assertEqual(ROTATE_45_DEGREE_GENE, bot.genes.get_next())
예제 #6
0
 def test_peek_food(self):
     world = World()
     bot_location = Location(2, 2)
     bot = Bot(bot_location, world)
     world.update_cell(bot_location, bot)
     bot.energy = 77
     bot.direction = Direction.E
     food_location = Location(3, 2)
     world.update_cell(food_location, CellType.FOOD)
     bot.lookup(0)
     self.assertEqual(77, bot.energy)
     self.assertEqual(Direction.E, bot.direction)
     self.assertTrue(isinstance(world.get_cell(bot_location), Bot))
     self.assertEqual(8, bot.genes.get_next())
예제 #7
0
 def test_move_to_food(self):
     world = World()
     old_location = Location(2, 2)
     expected_future_location = Location(3, 1)
     world.update_cell(expected_future_location, CellType.FOOD)
     bot = Bot(old_location, world)
     world.update_cell(old_location, bot)
     bot.direction = Direction.NE
     bot.energy = 11
     bot.move(0)
     self.assertTrue(
         isinstance(world.get_cell(expected_future_location), Bot))
     self.assertEqual(CellType.EMPTY, world.get_cell(old_location))
     self.assertEqual(Direction.NE, bot.direction)
     self.assertEqual(22, bot.energy)
예제 #8
0
 def test_peek_poison(self):
     world = World()
     bot_location = Location(2, 2)
     bot = Bot(bot_location, world)
     world.update_cell(bot_location, bot)
     bot.energy = 77
     bot.direction = Direction.E
     poison_location = Location(3, 3)
     world.update_cell(poison_location, CellType.POISON)
     bot.lookup(1)
     self.assertEqual(77, bot.energy)
     self.assertEqual(Direction.E, bot.direction)
     self.assertEqual(CellType.POISON, world.get_cell(poison_location))
     self.assertTrue(isinstance(world.get_cell(bot_location), Bot))
     self.assertEqual(24, bot.genes.get_next())
예제 #9
0
 def test_move_to_bot(self):
     world = World()
     other_bot_location = Location(2, 4)
     current_bot_location = Location(1, 3)
     other_bot = Bot(other_bot_location, world)
     current_bot = Bot(current_bot_location, world)
     world.update_cell(other_bot_location, other_bot)
     world.update_cell(current_bot_location, current_bot)
     current_bot.direction = Direction.S
     current_bot.energy = 10
     current_bot.move(7)
     self.assertEqual(current_bot, world.get_cell(current_bot_location))
     self.assertEqual(other_bot, world.get_cell(other_bot_location))
     self.assertEqual(Direction.S, current_bot.direction)
     self.assertEqual(12, current_bot.energy)
     self.assertEqual(ROTATE_45_DEGREE_GENE, current_bot.genes.get_next())
예제 #10
0
    def test_peek_bot(self):
        world = World()
        current_bot_location = Location(3, 4)
        current_bot = Bot(current_bot_location, world)
        world.update_cell(current_bot_location, current_bot)
        current_bot.energy = 77
        current_bot.direction = Direction.NW

        other_bot_location = Location(2, 3)
        other_bot = Bot(other_bot_location, world)
        world.update_cell(other_bot_location, other_bot)

        current_bot.lookup(7)
        self.assertEqual(77, current_bot.energy)
        self.assertEqual(Direction.NW, current_bot.direction)
        self.assertEqual(other_bot, world.get_cell(other_bot_location))
        self.assertEqual(current_bot, world.get_cell(current_bot_location))
        self.assertEqual(ROTATE_45_DEGREE_GENE, current_bot.genes.get_next())
예제 #11
0
 def test_update(self):
     world = World()
     location = Location(2, 3)
     world.update_cell(location, CellType.EMPTY)
     self.assertEqual(CellType.EMPTY, world.get_cell(location))
     world.update_cell(location, CellType.FOOD)
     self.assertEqual(CellType.FOOD, world.get_cell(location))
     world.update_cell(location, CellType.EMPTY)
     self.assertEqual(CellType.EMPTY, world.get_cell(location))
예제 #12
0
 def test_update_empty_when_empty(self):
     world = World()
     location = Location(1, 1)
     world.update_cell(location, CellType.EMPTY)
     world.update_cell(location, CellType.EMPTY)
예제 #13
0
 def test_update_when_is_not_free(self):
     world = World()
     world.put_cell(Location(1, 1), CellType.FOOD)
     old_value = world.update_cell(Location(1, 1), CellType.POISON)
     self.assertEqual(old_value, CellType.FOOD)
예제 #14
0
 def test_update_when_is_free(self):
     world = World()
     old_value = world.update_cell(Location(1, 1), CellType.POISON)
     self.assertIsNone(old_value)
예제 #15
0
 def test_update_on_wall(self):
     world = World()
     location = Location(0, 0)
     result = world.update_cell(location, CellType.POISON)
     self.assertEqual(CellType.WALL, result)