Exemplo n.º 1
0
    def test_valid_board_1(self):
        tiles = [
            ["d", None, "b", "a", "d"],
            ["a", None, "a", "s", None],
            ["d", "a", "d", None, None],
            ["s", None, None, None, None],
            [None, None, None, None, None],
        ]

        board = Board("test", 5, TestWordManager({"dads", "dad", "bad", "as"}))
        board._set_board(tiles)

        invalid_points = board.board_is_valid_crossword()
        assert set() == invalid_points
Exemplo n.º 2
0
    def test_invalid_board_not_connected(self):
        tiles = [
            ["d", None, "b", "a", "d"],
            ["a", None, "a", "s", None],
            ["d", "a", "d", None, None],
            ["s", None, None, None, None],
            [None, None, "d", "a", "dad"],
        ]

        board = Board("test", 5, TestWordManager({"dads", "dad", "bad", "as"}))
        board._set_board(tiles)

        invalid_points = board.board_is_valid_crossword()
        # Invalid because not all tiles are connected
        assert {(4, 2), (4, 3), (4, 4)} == invalid_points
Exemplo n.º 3
0
    def test_invalid_board_invalid_word(self):
        tiles = [
            ["d", None, "b", "a", "d"],
            ["a", None, "a", "z", None],
            ["d", "a", "d", None, None],
            ["s", None, None, None, None],
            [None, None, None, None, None],
        ]

        board = Board("test", 5, TestWordManager({"dads", "dad", "bad", "as"}))
        board._set_board(tiles)

        invalid_points = board.board_is_valid_crossword()
        # Invalid because the two instances of "az" are not valid words
        assert {(0, 3), (1, 2), (1, 3)} == invalid_points
Exemplo n.º 4
0
    def test_shift_up_invalid(self):
        tiles = [
            ["d", None, "b", "a", "d"],
            ["a", None, "a", "s", None],
            ["d", "a", "d", None, None],
            ["s", None, None, None, None],
            [None, None, None, None, None],
        ]
        board = Board("test", 5, TestWordManager({"dads", "dad", "bad", "as"}))
        board._set_board(tiles)

        assert not board.shift_board_up()

        # Tiles should not have moved
        assert tiles == board.board
Exemplo n.º 5
0
    def new_player(self, player_id: str, player_name: str) -> bool:
        """
        Method to call when a new player joins the game.
        Players can only join games that are not in progress.

        Args:
            player_id: The ID of the player
            player_name: The display name of the player

        Returns:
            True if the player successfully joined the game, False otherwise.
        """

        if self.game_running:
            self._log_info(
                f"Player {player_id}/{player_name} attempted to join a game that has already started."
            )
            return False
        else:
            self._log_info(
                f"Player {player_id}/{player_name} has joined game.")
            self.player_ids_to_names[player_id] = player_name
            self.player_ids_to_boards[player_id] = Board(
                player_id, BOARD_SIZE, self.word_manager)
            self.player_ids_to_tiles[player_id] = []
            return True
Exemplo n.º 6
0
    def test_shift_down_valid(self):
        tiles = [
            ["d", None, "b", "a", "d"],
            ["a", None, "a", "s", None],
            ["d", "a", "d", None, None],
            ["s", None, None, None, None],
            [None, None, None, None, None],
        ]
        board = Board("test", 5, TestWordManager({"dads", "dad", "bad", "as"}))
        board._set_board(tiles)

        assert board.shift_board_down()

        expected_tiles = [
            [None, None, None, None, None],
            ["d", None, "b", "a", "d"],
            ["a", None, "a", "s", None],
            ["d", "a", "d", None, None],
            ["s", None, None, None, None],
        ]

        assert expected_tiles == board.board
Exemplo n.º 7
0
    def start_game(self):
        # Reset the boards
        for player_id in self.player_ids_to_boards:
            self.player_ids_to_boards[player_id] = Board(
                player_id, BOARD_SIZE, self.word_manager)

        # Reset the tiles
        self.tiles_left = TILES_PER_PLAYER * len(
            self.player_ids_to_names.keys())
        self._generate_player_tiles()

        self.game_running = True
        self._log_info("Game started")