def setUp(self) -> None: # Redefine for every test as state persists otherwise PLAYER_1 = Player("orange", clues.by_booklet_entry("alpha", 2), teamname="alpha") PLAYER_2 = Player("cyan", None, teamname="beta") PLAYER_3 = Player("purple", None, teamname="epsilon") PLAYERS = [PLAYER_1, PLAYER_2, PLAYER_3] self.game = Game(MAP_DESCRIPTOR, PLAYERS, STRUCTURES)
def setUp(self) -> None: PLAYER_1 = Player("orange", clues.by_booklet_entry("alpha", 2), teamname="alpha") PLAYER_2 = Player("cyan", None, teamname="beta") PLAYER_3 = Player("purple", None, teamname="epsilon") PLAYERS = [PLAYER_1, PLAYER_2, PLAYER_3] self.game = Game(MAP_DESCRIPTOR, PLAYERS, STRUCTURES)
def test_cougar_clue_accepts_tile_next_to_cougar_zone(self) -> None: # Encountered during manual testing PLAYER_1 = Player("orange", clues.by_booklet_entry("alpha", 2), teamname="alpha") PLAYER_2 = Player("cyan", None, teamname="beta") PLAYER_3 = Player("purple", None, teamname="epsilon") PLAYERS = [PLAYER_1, PLAYER_2, PLAYER_3] game = Game(MAP_DESCRIPTOR, PLAYERS, STRUCTURES) self.assertIn(game.map[1, 1], clues.TWO_FROM_COUGAR.accepted_tiles(game.map), msg="2 from cougar should accept tile next to cougar zone")
def setUp(self) -> None: self.game = Game(["6N", "5S", "2N", "3N", "4N", "1S"], [Player("Red", clue=clues.FOREST_OR_MOUNTAIN), Player("Green"), Player("Brown"), Player("Purple")], [Structure("Blue", "Shack", x=1, y=7), Structure("Blue", "Stone", x=8, y=3), Structure("White", "Stone", x=2, y=2), Structure("White", "Shack", x=11, y=7), Structure("Green", "Shack", x=5, y=6), Structure("Green", "Stone", x=12, y=4)]) self.forest_or_mountain_coordinates = {(1, 2), (1, 3), (1, 5), (1, 6), (2, 2), (2, 5), (2, 6), (2, 7), (2, 9), (3, 6), (3, 7), (3, 8), (3, 9), (4, 7), (4, 9), (5, 2), (5, 7), (5, 9), (6, 1), (6, 2), (6, 3), (6, 7), (7, 3), (7, 7), (7, 8), (7, 9), (8, 3), (8, 8), (8, 9), (9, 1), (9, 2), (9, 3), (9, 4), (9, 5), (10, 1), (10, 2), (10, 3), (10, 4), (10, 6), (11, 1), (11, 4), (11, 6), (12, 4), (12, 6)}
def test_accepted_tiles_maintains_hash(self) -> None: a = Clue(1, set(["bear", "cougar"]), clue_type="animal") b = Clue(1, set(["bear", "cougar"]), clue_type="animal") self.assertEqual(hash(a), hash(b), msg="Fresh clues with same parameters should be comparable") PLAYER_1 = Player("orange", clues.by_booklet_entry("alpha", 2), teamname="alpha") PLAYER_2 = Player("cyan", None, teamname="beta") PLAYER_3 = Player("purple", None, teamname="epsilon") PLAYERS = [PLAYER_1, PLAYER_2, PLAYER_3] game = Game(MAP_DESCRIPTOR, PLAYERS, STRUCTURES) _ = b.accepted_tiles(game.map) self.assertEqual(hash(a), hash(b), msg="Invoking class methods should not change the hash of a clue")
def test_accepted_tiles_comparison(self) -> None: a = Clue(1, set(["bear", "cougar"]), clue_type="animal") b = Clue(1, set(["bear", "cougar"]), clue_type="animal") self.assertEqual(a, b, msg="Instances of same clue should evaluate to be equal") PLAYER_1 = Player("orange", clues.by_booklet_entry("alpha", 2), teamname="alpha") PLAYER_2 = Player("cyan", None, teamname="beta") PLAYER_3 = Player("purple", None, teamname="epsilon") PLAYERS = [PLAYER_1, PLAYER_2, PLAYER_3] game = Game(MAP_DESCRIPTOR, PLAYERS, STRUCTURES) _ = b.accepted_tiles(game.map) self.assertEqual(a, b, msg="Invoking class methods should not change equality comparison of Clue instance")
def test_repeated_calls_are_cached(self) -> None: two_from_cougar = deepcopy(clues.TWO_FROM_COUGAR) PLAYER_1 = Player("orange", clues.by_booklet_entry("alpha", 2), teamname="alpha") PLAYER_2 = Player("cyan", None, teamname="beta") PLAYER_3 = Player("purple", None, teamname="epsilon") PLAYERS = [PLAYER_1, PLAYER_2, PLAYER_3] game = Game(MAP_DESCRIPTOR, PLAYERS, STRUCTURES) _ = two_from_cougar.accepted_tiles(game.map) before_call = two_from_cougar.accepted_tiles.cache_info() _ = two_from_cougar.accepted_tiles(game.map) after_call = two_from_cougar.accepted_tiles.cache_info() self.assertEqual(after_call[0], before_call[0] + 1, msg="Number of cache hits should increase when called with same parameters")
def test_known_clues_return_a_single_tile(self) -> None: PLAYER_1 = Player("red", clues.by_booklet_entry("alpha", 2), teamname="alpha") PLAYER_2 = Player("orange", clues.by_booklet_entry("beta", 79), teamname="beta") PLAYER_3 = Player("purple", clues.by_booklet_entry("epsilon", 28), teamname="epsilon") PLAYERS = [PLAYER_1, PLAYER_2, PLAYER_3] game = Game(MAP_DESCRIPTOR, PLAYERS, STRUCTURES) possible_tiles = game.possible_tiles() self.assertTrue( len(possible_tiles) == 1, msg= "Should always return a single maptile when, all clues are known")
help="Structures as '(color)_([SS/AS])_(x),(y)'") args = parser.parse_args() players = [parse_player(player) for player in args.players] structures = [parse_structure(structure) for structure in args.structures] __minimal_structures = [("white", "stone"), ("white", "shack"), ("green", "stone"), ("green", "shack"), ("blue", "stone"), ("blue", "shack")] assert len(players) >= 3, "Game should have at least three players" assert all( ms in [(s.color.lower(), s.shape.lower()) for s in structures] for ms in __minimal_structures), "All the basic structures should be present" game = Game(args.map, players, structures) while (True): cmd = input().lower().strip() if cmd.startswith("place") and len(cmd.split(" ")) == 4: try: (_, mapObject, x, y) = cmd.split(" ") (x, y) = (int(x), (int(y))) if mapObject == "c": action = game.place_cube(x, y) print("{} placed cube on {}".format(action[0], action[1])) elif mapObject == "d":