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))
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')
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.")
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")
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]))
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, ))