Esempio n. 1
0
class TestDiskPlacement(unittest.TestCase):
    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_disk_added_to_player(self) -> None:

        before_placement = len(self.game.players[0].disks)

        self.game.place_disk(1, 1)

        self.assertEqual(len(self.game.players[0].disks), before_placement + 1)

    def test_gametick_advances(self) -> None:

        before_placement = self.game.gametick

        self.game.place_disk(1, 1)

        self.assertEqual(self.game.gametick, before_placement + 1)
Esempio n. 2
0
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")
Esempio n. 3
0
    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)
Esempio n. 4
0
    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)
Esempio n. 5
0
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")
Esempio n. 6
0
    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")
Esempio n. 7
0
    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")
Esempio n. 8
0
 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)}
Esempio n. 9
0
def possible_tiles(
        game: Game,
        inverted_clues: bool = False) -> List[Tuple[MapTile, float]]:
    """
    Infer possible tiles from the clue possible clue combinations.

    Args:
        game: Game - Current game.
        inverted_clues: bool - Playing with inverted clue?

    Returns:
        Dict[MapTile: int]] - MapTile with number of clue combinations pointing on them
    """

    return game.possible_tiles(inverted_clues)
Esempio n. 10
0
    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")
Esempio n. 11
0
    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")
Esempio n. 12
0
    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")
Esempio n. 13
0
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)
Esempio n. 14
0
                        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":