Beispiel #1
0
    def equippedBotWithViableTarget(self, tool):
        """
        Create a scenario in which shooting is allowed.
        """
        world, rules = self.worldAndRules()

        # make square and ore
        square = world.create('square')['id']
        ore = world.create('ore')['id']
        action.Move(ore, square).execute(world)

        # equip bot
        bot = world.create('bot')['id']
        action.Move(bot, square).execute(world)
        action.MakeTool(bot, ore, tool).execute(world)

        # make target
        target = world.create('bot')['id']
        world.setAttr(target, 'hp', 10)
        action.Move(target, square).execute(world)

        self.world = world
        self.rules = rules
        self.square = square
        self.bot = bot
        self.target = target
        return self.bot
Beispiel #2
0
    def test_onlyOneBotPerTeamCanLandWithoutPortal(self):
        """
        If one bot on a team is already on the board, other bots are not
        allowed to go on the board by moving.
        """
        # create a non-fake world
        world, rules = self.worldAndRules()

        # create a bot that's on a team
        bot = world.create('bot')['id']
        yield world.execute(action.CreateTeam(bot, 'ATeam', 'password'))
        yield world.execute(action.JoinTeam(bot, 'ATeam', 'password'))

        # land the bot on a square.
        square = world.create('square')['id']
        rules.isAllowed(world, action.Move(bot, square))
        yield world.execute(action.Move(bot, square))

        # create another bot on the same team
        bot2 = world.create('bot')['id']
        yield action.JoinTeam(bot2, 'ATeam', 'password').execute(world)

        # it should not be allowed to land the bot on a square until the other
        # bot dies.
        yield self.assertFailure(world.execute(action.Move(bot2, square)),
                                 NotAllowed)

        # bot1 is destroyed, now bot2 can land
        yield world.destroy(bot)
        yield world.execute(action.Move(bot2, square))
Beispiel #3
0
    def test_OpenPortal(self):
        """
        You can open a portal
        """
        world, rules = self.worldAndRules()

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

        rules.isAllowed(world, action.OpenPortal(bot, ore, 'user'))
Beispiel #4
0
    def test_ShareEnergy(self):
        """
        You can share energy with another bot.
        """
        world, rules = self.worldAndRules()

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

        rules.isAllowed(world, action.ShareEnergy(bot1, bot2, 2))
Beispiel #5
0
    def test_ShareEnergy_bot(self):
        """
        You can only share energy with another bot.
        """
        world, rules = self.worldAndRules()

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

        self.assertRaises(NotAllowed, rules.isAllowed, world,
                          action.ShareEnergy(bot1, ore, 2))
Beispiel #6
0
    def test_OpenPortal_ore(self):
        """
        You can only open a portal with ore.
        """
        world, rules = self.worldAndRules()

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

        self.assertRaises(NotAllowed, rules.isAllowed, world,
                          action.OpenPortal(bot1, bot2, 'hey'))
Beispiel #7
0
    def test_locks(self):
        """
        You can add/remove a lock on a pylon
        """
        world, rules = self.worldAndRules()

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

        rules.isAllowed(world, action.AddLock(bot, pylon))
        rules.isAllowed(world, action.BreakLock(bot, pylon))
Beispiel #8
0
    def test_ShareEnergy_sameSquare(self):
        """
        You can only share energy with a bot on the same square
        """
        world, rules = self.worldAndRules()

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

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

        self.assertRaises(NotAllowed, rules.isAllowed, world,
                          action.ShareEnergy(bot1, bot2, 2))
Beispiel #9
0
    def test_OpenPortal_sameSquare(self):
        """
        You must be on the same square as the ore being turned into a portal.
        """
        world, rules = self.worldAndRules()

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

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

        self.assertRaises(NotAllowed, rules.isAllowed, world,
                          action.OpenPortal(bot, ore, 'user'))
Beispiel #10
0
    def test_MakeTool(self):
        """
        You can make a tool
        """
        world, rules = self.worldAndRules()

        # make square and ore
        square = world.create('square')['id']
        ore = world.create('ore')['id']
        action.Move(ore, square).execute(world)

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

        rules.isAllowed(world, action.MakeTool(bot, ore, 'cannon'))
Beispiel #11
0
    def test_locks_onlyOnPylons(self):
        """
        You can add/remove a lock on a pylon only
        """
        world, rules = self.worldAndRules()

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

        self.assertRaises(NotAllowed, rules.isAllowed, world,
                          action.AddLock(bot, ore))
        self.assertRaises(NotAllowed, rules.isAllowed, world,
                          action.BreakLock(bot, ore))
Beispiel #12
0
    def test_MakeTool_oreOnly(self):
        """
        You can only make a tool out of ore
        """
        world, rules = self.worldAndRules()

        # make square and ore
        square = world.create('square')['id']
        otherbot = world.create('bot')['id']
        action.Move(otherbot, square).execute(world)

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

        self.assertRaises(NotAllowed, rules.isAllowed, world,
                          action.MakeTool(bot, otherbot, 'cannon'))
Beispiel #13
0
    def test_oneBotCanLandWithoutPortal(self):
        """
        A bot that's part of a team can move onto a square.
        """
        # create a bot that's on a team
        world, rules = self.worldAndRules()

        bot = world.create('bot')['id']
        yield world.execute(action.CreateTeam(bot, 'ATeam', 'password'))
        yield world.execute(action.JoinTeam(bot, 'ATeam', 'password'))

        # it's okay to land on a square.
        square = world.create('square')['id']
        rules.isAllowed(world, action.Move(bot, square))
        self.assertEqual(
            rules.energyRequirement(world, action.Move(bot, square)), 0,
            "It should not take energy to move the bot on to "
            "the square because he can't charge when on deck.")
Beispiel #14
0
    def test_MakeTool_sameSquare(self):
        """
        You can only make a tool out of a piece of ore in the same square.
        """
        world, rules = self.worldAndRules()

        # make square and ore
        square = world.create('square')['id']
        ore = world.create('ore')['id']
        action.Move(ore, square).execute(world)

        # make bot in different square
        square2 = world.create('square')['id']
        bot = world.create('bot')['id']
        action.Move(bot, square2).execute(world)

        self.assertRaises(NotAllowed, rules.isAllowed, world,
                          action.MakeTool(bot, ore, 'cannon'))
Beispiel #15
0
    def test_locks_sameSquare(self):
        """
        You can add/remove a lock only if you're on the same square.
        """
        world, rules = self.worldAndRules()

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

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

        self.assertRaises(NotAllowed, rules.isAllowed, world,
                          action.AddLock(bot, pylon))
        self.assertRaises(NotAllowed, rules.isAllowed, world,
                          action.BreakLock(bot, pylon))
Beispiel #16
0
    def test_LookAt_sameSquare(self):
        """
        You can only look at things in the same square.
        """
        world, rules = self.worldAndRules()

        s1 = world.create('square')['id']
        s2 = world.create('square')['id']

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

        rules.isAllowed(world, action.LookAt(bot, ore))

        action.Move(ore, s2).execute(world)
        self.assertRaises(NotAllowed, rules.isAllowed, world,
                          action.LookAt(bot, ore))
Beispiel #17
0
    def test_mustHaveTeamToLandWithoutPortal(self):
        """
        A bot must be a member of a team to move from the deck onto the board.
        """
        world, rules = self.worldAndRules()

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

        square = world.create('square')['id']
        self.assertRaises(NotAllowed, rules.isAllowed, world,
                          action.Move(bot, square))
Beispiel #18
0
    def test_Repair_mustBeOnSameSquare(self):
        """
        A bot must be on the same square as the target it is Repairing.
        """
        self.equippedBotWithViableTarget('wrench')

        square2 = self.world.create('square')['id']
        action.Move(self.target, square2).execute(self.world)

        self.assertRaises(NotAllowed, self.rules.isAllowed, self.world,
                          action.Repair(self.bot, self.target, 1))
Beispiel #19
0
    def test_Repair_targetMustBeVulnerable(self):
        """
        You can only Repair things that are vulnerable
        """
        self.equippedBotWithViableTarget('wrench')

        invulnerable = self.world.create('ore')['id']
        action.Move(invulnerable, self.square).execute(self.world)

        self.assertRaises(NotAllowed, self.rules.isAllowed, self.world,
                          action.Repair(self.bot, invulnerable, 1))
Beispiel #20
0
    def test_Charge_once(self):
        """
        You may only charge to create one energy at a time.
        """
        world, rules = self.worldAndRules()

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

        # charge once
        yield world.execute(action.Charge(bot))

        self.assertFailure(world.execute(action.Charge(bot)), NotAllowed)
Beispiel #21
0
    def test_botIsGivenHPWhenItLands(self):
        world, rules = self.worldAndRules()

        square = world.create('square')['id']
        world.setAttr(square, 'coordinates', (0, 0))
        bot = world.create('bot')
        bot_id = bot['id']

        yield world.execute(action.CreateTeam(bot_id, 'bar', 'password'))
        yield world.execute(action.JoinTeam(bot_id, 'bar', 'password'))

        world.execute(action.Move(bot_id, square))
        self.assertEqual(bot['hp'], rules.bot_starting_hp, "When a bot lands"
                         " the bot should be given hp")

        # moving to a new square won't increase health
        world.setAttr(bot_id, 'hp', rules.bot_starting_hp - 2)
        square2 = world.create('square')['id']
        world.setAttr(square2, 'coordinates', (0, 1))
        world.execute(action.Move(bot_id, square2))

        self.assertEqual(bot['hp'], rules.bot_starting_hp - 2,
                         "Moving to a new square should not restore health")
Beispiel #22
0
    def test_Move_adjacentSquaresOnly(self):
        """
        You can only move to adjacent squares.
        """
        world, rules = self.worldAndRules()

        grid = {}
        for i in xrange(3):
            for j in xrange(3):
                square = world.create('square')['id']
                world.setAttr(square, 'coordinates', (i, j))
                grid[i, j] = square

        bot = world.create('bot')['id']
        yield action.CreateTeam(bot, 'foo', 'password').execute(world)
        yield action.JoinTeam(bot, 'foo', 'password').execute(world)
        yield action.Move(bot, grid[1, 1]).execute(world)

        for c in [(1, 0), (0, 1), (2, 1), (1, 2)]:
            rules.isAllowed(world, action.Move(bot, grid[c]))

        for c in [(0, 0), (2, 0), (0, 2), (2, 2)]:
            self.assertRaises(NotAllowed, rules.isAllowed, world,
                              action.Move(bot, grid[c]))
Beispiel #23
0
    def test_afterWinNothingIsAllowed(self):
        """
        If there is a winner to the game, then nothing is allowed.
        """
        world, rules = self.worldAndRules()

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

        yield world.execute(action.CreateTeam(bot_id, 'bar', 'password'))
        yield world.execute(action.JoinTeam(bot_id, 'bar', 'password'))

        world.execute(action.Move(bot_id, square))
        rules.winner = 'foo'
        self.assertRaises(NotAllowed, rules.isAllowed, world, 'anything')
Beispiel #24
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, ))