Ejemplo n.º 1
0
 def test_bugged_code(self):
     attack_code = """
         DO ATTACKlol;
         DO ATTACK;
     """
     r1 = Robot(name="AndriodRobot", damage=1, max_health=6, health=6, code=attack_code, energy=10, IPS=1, memory=2)
     r2 = Robot(name="NelichRobot", damage=1, max_health=6, health=6, code=attack_code, energy=10, IPS=1, memory=2)
     code_runner = CodeRunner([r1, r2])
     result = code_runner.fight()
     result.print_logs()
Ejemplo n.º 2
0
 def test_crash(self):
     attack_code = """
         DO ATTACK;
         DO ATTACK;
     """
     r1 = Robot(name="AndriodRobot", damage=1, max_health=6, health=6, code=attack_code, energy=10, IPS=1, memory=2)
     r2 = Robot(name="NelichRobot", damage=1, max_health=6, health=6, code=attack_code, energy=10, IPS=1, memory=2)
     code_runner = CodeRunner([r1, r2])
     result = code_runner.fight()
     self.assertIn("Robot AndriodRobot crashed: Your robot ran out of code", result.logs)
Ejemplo n.º 3
0
 def test_to_much_code(self):
     attack_code = """
         DO ATTACK;
         DO ATTACK;
     """
     r1 = Robot(name="AndriodRobot", damage=1, max_health=6, health=6, code=attack_code, energy=10, IPS=1, memory=1)
     r2 = Robot(name="NelichRobot", damage=1, max_health=6, health=6, code=attack_code, energy=10, IPS=1, memory=2)
     code_runner = CodeRunner([r1, r2])
     result = code_runner.fight()
     self.assertIn("Warning AndriodRobot: Insufficient memory for all instructions from code. Dropped some instructions.", result.logs)
     self.assertEquals(1, len(r1.instructions))
Ejemplo n.º 4
0
 def test_basic_fight(self):
     attack_code = """
         DO ATTACK;
         DO ATTACK;
     """
     r1 = Robot(name="AndriodRobot", damage=1, max_health=6, health=6, code=attack_code, energy=10, IPS=1, memory=2)
     r2 = Robot(name="NelichRobot", damage=1, max_health=6, health=6, code=attack_code, energy=10, IPS=1, memory=2)
     code_runner = CodeRunner([r1, r2])
     result = code_runner.fight()
     self.assertEqual(4, r1.health)
     self.assertEqual(4, r2.health)
     self.assertEqual(8, r1.energy)
     self.assertEqual(8, r2.energy)
Ejemplo n.º 5
0
 def test_loop_fight_ips_advantage(self):
     attack_code = """
         LOOP START;
             DO ATTACK;
         LOOP END;
     """
     r1 = Robot(name="AndriodRobot", damage=2, max_health=6, health=6, code=attack_code, energy=10, IPS=2, memory=3)
     r2 = Robot(name="NelichRobot", damage=2, max_health=6, health=6, code=attack_code, energy=10, IPS=1, memory=3)
     code_runner = CodeRunner([r1, r2])
     result = code_runner.fight()
     self.assertEqual(4, r1.health)
     self.assertEqual(0, r2.health)
     self.assertEqual(2, r1.energy)
     self.assertEqual(6, r2.energy)
     self.assertEqual(r1.name, result.winner.name)