class TestAcceptsCube(unittest.TestCase): 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 test_rejects_when_cube_present(self) -> None: self.game.place_cube(1, 1) self.assertFalse( self.game.accepts_cube(1, 1), msg="Cubes cannot be placed on tiles with other cubes") def test_accepts_when_no_cube_present(self) -> None: self.assertTrue(self.game.accepts_cube(1, 1), msg="Cubes can be placed on tiles with other cubes")
class TestPossibleClues(unittest.TestCase): 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 test_returns_non_empty_collection(self) -> None: self.assertTrue(len(self.game.players[0].possible_clues(self.game.map)) != 0, msg="Should always return non-empty collection") def test_defaults_to_return_all_clues(self) -> None: # PLAYER_2 does not have a clue assigned player = self.game.players[1] original_collection = clues.CLUE_COLLECTION.difference([clues.THREE_FROM_BLACK]) possible_clues = player.possible_clues(self.game.map) self.assertSetEqual(original_collection, possible_clues, msg="Should return all clues when no cubes or disks are present") def test_cubes_limit_possibile_clues(self) -> None: # Place a cube for the 1st player self.game.place_cube(1, 1) player = self.game.players[0] possible_clues = player.possible_clues(self.game.map) # Cube on (1, 1) excludes the following clues: 2 from cougar, 1 from animal, swamp, 1 from swamp original_collection = clues.CLUE_COLLECTION.difference([clues.THREE_FROM_BLACK]) reduced_collection = original_collection.difference([ clues.FOREST_OR_SWAMP, clues. DESERT_OR_SWAMP, clues.WATER_OR_SWAMP, clues.SWAMP_OR_MOUNTAIN, clues.ONE_FROM_SWAMP, clues.ONE_FROM_ANIMAL, clues.TWO_FROM_COUGAR ]) self.assertSetEqual(reduced_collection, possible_clues, msg="Placement of cube should remove associated clues")
class TestCubePlacement(unittest.TestCase): 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 test_cube_added_to_player(self) -> None: before_placement = len(self.game.players[0].cubes) # Confers to the players clue self.game.place_cube(1, 1) self.assertEqual(len(self.game.players[0].cubes), before_placement + 1) def test_gametick_advances(self) -> None: before_placement = self.game.gametick self.game.place_cube(1, 1) self.assertEqual(self.game.gametick, before_placement + 1) def test_rejects_placement_when_cube_present(self) -> None: self.game.place_cube(1, 1) with self.assertRaises( ValueError, msg="Cubes cannot be placed on tiles with cubes"): self.game.place_cube(1, 1)
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": action = game.place_disk(x, y) print("{} placed disk on {}".format(action[0], action[1])) else: raise ValueError except ValueError: pass elif cmd.startswith("answer") and len(cmd.split(" ")) == 5: # TODO Rewrite this to safer form try: (_, color, mapObject, x, y) = cmd.split(" ")