def test_recursive_goose(self): player = 'Pippo' goose = [8, 10] engine = RuleEngine([BasicMoveRule(), GooseMoveRule(set(goose))]) current_pos = 6 step = 2 moves = engine.apply_rules(player, current_pos, step) self.assertEqual(len(moves), 3) # basic and the 2 goose self.assertTrue( isinstance(moves[0].rule_applied, BasicMoveRule)) self.assertEqual(moves[0].start_pos, current_pos) self.assertEqual(moves[0].end_pos, current_pos + step) self.assertEqual(moves[0].player, player) self.assertTrue( isinstance(moves[1].rule_applied, GooseMoveRule)) self.assertEqual(moves[1].start_pos, goose[0]) self.assertEqual(moves[1].end_pos, goose[0] + step) self.assertEqual(moves[1].player, player) self.assertTrue( isinstance(moves[2].rule_applied, GooseMoveRule)) self.assertEqual(moves[2].start_pos, goose[1]) self.assertEqual(moves[2].end_pos, goose[1] + step) self.assertEqual(moves[2].player, player)
def test_basic(self): player = 'Pippo' engine = RuleEngine([BasicMoveRule()]) current_pos = 6 step = 2 moves = engine.apply_rules(player, current_pos, step) self.assertEqual(len(moves), 1) self.assertTrue(isinstance(moves[0].rule_applied, BasicMoveRule)) self.assertEqual(moves[0].start_pos, current_pos) self.assertEqual(moves[0].end_pos, current_pos + step) self.assertEqual(moves[0].player, player)
def test_aliases(self, *args): rules = [args[0](), args[0]()] engine = RuleEngine(rules) game = Game(self.repo, engine, self.validator) self.assertEqual(game.get_space_aliases(), {0: 'Start'}) self.assertEqual(args[0]().get_space_aliases.call_count, 2)
def test_simple_goose(self): player = 'Pippo' goose = 8 engine = RuleEngine([BasicMoveRule(), GooseMoveRule({goose})]) current_pos = 6 step = 2 moves = engine.apply_rules(player, current_pos, step) self.assertEqual(len(moves), 2) # basic and the goose self.assertTrue(isinstance(moves[0].rule_applied, BasicMoveRule)) self.assertEqual(moves[0].start_pos, current_pos) self.assertEqual(moves[0].end_pos, current_pos + step) self.assertEqual(moves[0].player, player) self.assertTrue(isinstance(moves[1].rule_applied, GooseMoveRule)) self.assertEqual(moves[1].start_pos, goose) self.assertEqual(moves[1].end_pos, goose + step) self.assertEqual(moves[1].player, player)
def game_factory(rules=None): repo = DictPlayerRepository() rules = rules or [ BasicMoveRule(), BounceMoveRule(N_SPACES), GooseMoveRule(GOOSE_SPACES), BridgeMoveRule(BRIDGE_START, BRIDGE_END), PrankMoveRule(repo) ] return Game(repo, RuleEngine(rules))
def create_default_game() -> BaseGame: """ Factory that creates the default game, ie a game with the following rules: BounceMoveRule, BridgeMoveRule, GooseMoveRule, PrankMoveRule :return: a BaseGame instance """ from goose.repositories import DictPlayerRepository from goose.rules import RuleEngine, BasicMoveRule, BounceMoveRule, \ BridgeMoveRule, GooseMoveRule, PrankMoveRule repo = DictPlayerRepository() rule_engine = RuleEngine([ BasicMoveRule(), BounceMoveRule(N_SPACES), BridgeMoveRule(BRIDGE_START, BRIDGE_END), GooseMoveRule(GOOSE_SPACES), PrankMoveRule(repo) ]) return Game(repo, rule_engine)
def setUp(self, *args): self.repo = DictPlayerRepository() self.rule_engine = RuleEngine([]) self.validator = PositionValidator() self.game = Game(self.repo, self.rule_engine, self.validator)