Beispiel #1
0
    def test_failIfNotOnBoard(self):
        """
        The following actions require a bot to be on the board.
        """
        world = World(MagicMock())
        rules = StandardRules()

        bot = world.create('bot')['id']

        actions = [
            action.Charge(bot),
            action.ShareEnergy(bot, 'foo', 2),
            action.ConsumeEnergy(bot, 2),
            action.Shoot(bot, 'foo', 1),
            action.Repair(bot, 'foo', 1),
            action.MakeTool(bot, 'foo', 'foo'),
            action.OpenPortal(bot, 'foo', 'foo'),
            action.AddLock(bot, 'foo'),
            action.BreakLock(bot, 'foo'),
            action.LookAt(bot, 'foo'),
        ]

        for a in actions:
            try:
                rules.isAllowed(world, a)
            except NotAllowed:
                pass
            else:
                self.fail("You must be on a square to do %r" % (a,))
Beispiel #2
0
    def test_failIfNotOnBoard(self):
        """
        The following actions require a bot to be on the board.
        """
        world = World(MagicMock())
        rules = StandardRules()

        bot = world.create('bot')['id']

        actions = [
            action.Charge(bot),
            action.ShareEnergy(bot, 'foo', 2),
            action.ConsumeEnergy(bot, 2),
            action.Shoot(bot, 'foo', 1),
            action.Repair(bot, 'foo', 1),
            action.MakeTool(bot, 'foo', 'foo'),
            action.OpenPortal(bot, 'foo', 'foo'),
            action.AddLock(bot, 'foo'),
            action.BreakLock(bot, 'foo'),
            action.LookAt(bot, 'foo'),
        ]

        for a in actions:
            try:
                rules.isAllowed(world, a)
            except NotAllowed:
                pass
            else:
                self.fail("You must be on a square to do %r" % (a, ))
Beispiel #3
0
    def test_energyRequirement_default(self):
        """
        Most things require 0 energy
        """
        world = World(MagicMock())
        rules = StandardRules()

        self.assertEqual(
            rules.energyRequirement(world, action.ListSquares('foo')), 0)
Beispiel #4
0
    def test_energyRequirement_default(self):
        """
        Most things require 0 energy
        """
        world = World(MagicMock())
        rules = StandardRules()

        self.assertEqual(rules.energyRequirement(world,
                         action.ListSquares('foo')), 0)
Beispiel #5
0
    def test_onlyBotsCanExecute(self):
        """
        Only bots can execute commands.
        """
        world = World(MagicMock())
        rules = StandardRules()

        bot = world.create('bot')['id']
        rules.isAllowed(world, action.ListSquares(bot))

        nonbot = world.create('foo')['id']
        self.assertRaises(NotAllowed, rules.isAllowed, world,
                          action.ListSquares(nonbot))
Beispiel #6
0
    def test_onlyBotsCanExecute(self):
        """
        Only bots can execute commands.
        """
        world = World(MagicMock())
        rules = StandardRules()

        bot = world.create('bot')['id']
        rules.isAllowed(world, action.ListSquares(bot))

        nonbot = world.create('foo')['id']
        self.assertRaises(NotAllowed, rules.isAllowed, world,
                          action.ListSquares(nonbot))
Beispiel #7
0
 def worldAndRules(self):
     """
     Get a fresh world and set of rules.
     """
     auth = MemoryStoredPasswords()
     rules = StandardRules()
     engine = XatroEngine(rules)
     world = World(MagicMock(), engine, auth)
     return world, rules
Beispiel #8
0
 def test_energyRequirement_Shoot(self):
     """
     Shooting energy proportional to damage (with some bonus for more energy)
     """
     world = World(MagicMock())
     rules = StandardRules()
     expectations = [
         # hp, energy
         (1, 1),
         (2, 2),
         (3, 2),
         (4, 3),
         (5, 3),
         (6, 3),
     ]
     for hp, energy in expectations:
         actual = rules.energyRequirement(world,
                                          action.Shoot('foo', 'bar', hp))
         self.assertEqual(actual, energy,
                          "Expected shooting for %r to take %r energy, not "
                          "%r energy" % (hp, energy, actual))
Beispiel #9
0
 def test_energyRequirement_Shoot(self):
     """
     Shooting energy proportional to damage (with some bonus for more energy)
     """
     world = World(MagicMock())
     rules = StandardRules()
     expectations = [
         # hp, energy
         (1, 1),
         (2, 2),
         (3, 2),
         (4, 3),
         (5, 3),
         (6, 3),
     ]
     for hp, energy in expectations:
         actual = rules.energyRequirement(world,
                                          action.Shoot('foo', 'bar', hp))
         self.assertEqual(
             actual, energy,
             "Expected shooting for %r to take %r energy, not "
             "%r energy" % (hp, energy, actual))
Beispiel #10
0
 def test_energyRequirement_required(self):
     """
     Various actions require the following amounts of energy.
     """
     world = World(MagicMock())
     rules = StandardRules()
     expectations = [
         (0, action.Look('foo')),
         (1, action.LookAt('foo', 'bar')),
         (0, action.Charge('foo')),
         (0, action.ShareEnergy('foo', 'bar', 3)),
         (0, action.ConsumeEnergy('foo', 2)),
         (1, action.MakeTool('foo', 'ore', 'tool')),
         (1, action.OpenPortal('foo', 'ore', 'user')),
         (0, action.UsePortal('foo', 'portal')),
         (0, action.ListSquares('foo')),
         (2, action.AddLock('foo', 'target')),
         (2, action.BreakLock('foo', 'target')),
     ]
     for energy, cmd in expectations:
         self.assertEqual(
             rules.energyRequirement(world, cmd), energy,
             "Expected command %r to require %r energy" % (cmd, energy))
Beispiel #11
0
 def test_energyRequirement_required(self):
     """
     Various actions require the following amounts of energy.
     """
     world = World(MagicMock())
     rules = StandardRules()
     expectations = [
         (0, action.Look('foo')),
         (1, action.LookAt('foo', 'bar')),
         (0, action.Charge('foo')),
         (0, action.ShareEnergy('foo', 'bar', 3)),
         (0, action.ConsumeEnergy('foo', 2)),
         (1, action.MakeTool('foo', 'ore', 'tool')),
         (1, action.OpenPortal('foo', 'ore', 'user')),
         (0, action.UsePortal('foo', 'portal')),
         (0, action.ListSquares('foo')),
         (2, action.AddLock('foo', 'target')),
         (2, action.BreakLock('foo', 'target')),
     ]
     for energy, cmd in expectations:
         self.assertEqual(rules.energyRequirement(world, cmd), energy,
                          "Expected command %r to require %r energy" % (
                          cmd, energy))
Beispiel #12
0
    def test_failIfOnBoard(self):
        """
        The following actions may only be done when NOT on a board.
        """
        world = World(MagicMock())
        rules = StandardRules()

        bot = world.create('bot')['id']
        square = world.create('square')['id']
        action.Move(bot, square).execute(world)

        actions = [
            action.UsePortal(bot, 'foo'),
            action.JoinTeam(bot, 'team', 'foo'),
            action.CreateTeam(bot, 'team', 'foo'),
        ]

        for a in actions:
            try:
                rules.isAllowed(world, a)
            except NotAllowed:
                pass
            else:
                self.fail("You must be off of a square to do %r" % (a, ))
Beispiel #13
0
    def test_failIfOnBoard(self):
        """
        The following actions may only be done when NOT on a board.
        """
        world = World(MagicMock())
        rules = StandardRules()

        bot = world.create('bot')['id']
        square = world.create('square')['id']
        action.Move(bot, square).execute(world)

        actions = [
            action.UsePortal(bot, 'foo'),
            action.JoinTeam(bot, 'team', 'foo'),
            action.CreateTeam(bot, 'team', 'foo'),
        ]

        for a in actions:
            try:
                rules.isAllowed(world, a)
            except NotAllowed:
                pass
            else:
                self.fail("You must be off of a square to do %r" % (a,))
Beispiel #14
0
 def test_IXatroEngine(self):
     verifyObject(IXatroEngine, StandardRules())