Esempio n. 1
0
    def test_get_board_target_tile(self):
        game = Game()

        three = game.player_1.get_piece_by_type(PieceType.three)
        tile = game.board.get_tile(1, 4)

        placement_move = PlacementMove(piece=three,
                                       tile=tile,
                                       board=game.board)
        target_tile = placement_move.get_board_target_tile()

        assert target_tile.x == 1 and target_tile.y == 3
Esempio n. 2
0
    def test_execute(self):
        game = Game()

        three = game.player_1.get_piece_by_type(PieceType.three)
        tile = game.board.get_tile(4, 2)

        placement_move = PlacementMove(piece=three,
                                       tile=tile,
                                       board=game.board)
        placement_move.execute()

        assert game.board.get_tile(4, 2).piece == three
Esempio n. 3
0
    def test_obvious_second_placement_move(self, clean_tree_search_caches_before_tests):
        # Here we are going to set up a game where player 1 has a single option to win immediately,
        # and he's going to play second (he doesn't need to account for a move of the opponent before the
        # board execution)
        game = Game()
        game.starting_player = game.player_2

        PlacementMove(
            piece=game.player_1.get_piece_by_type(PieceType.four),
            tile=game.board.get_tile(0, 2),
            board=game.board,
        ).execute()
        PlacementMove(
            piece=game.player_1.get_piece_by_type(PieceType.three),
            tile=game.board.get_tile(0, 3),
            board=game.board,
        ).execute()
        game.board.execute_board_movements(PLAYER_1_ID)
        game.board.execute_board_movements(PLAYER_1_ID)

        PlacementMove(
            piece=game.player_1.get_piece_by_type(PieceType.two),
            tile=game.board.get_tile(0, 1),
            board=game.board,
        ).execute()
        PlacementMove(
            piece=game.player_1.get_piece_by_type(PieceType.five),
            tile=game.board.get_tile(4, 1),
            board=game.board,
        ).execute()

        game.board.execute_board_movements(PLAYER_1_ID)
        game.starting_player = game.player_2

        PlacementMove(
            piece=game.player_2.get_piece_by_type(PieceType.five),
            tile=game.board.get_tile(4, 3),
            board=game.board,
        ).execute()

        # Player 1 can win the game by placing a one in tile (2, 0) or a three/four on (3, 0)
        # But he only has piece one available in hand
        best_move = get_best_move(game.player_1, game.player_2, is_first_move=False, depth=1)
        assert best_move.x == 2
        assert best_move.y == 0
        assert best_move.piece_type == PieceType.one
        assert best_move.score == WIN_CONDITION_SCORE - DEPTH_PENALTY
Esempio n. 4
0
 def get_legal_placement_moves(self) -> List[PlacementMove]:
     legal_tiles = self.board.get_legal_tiles()
     available_pieces = self.get_available_pieces()
     legal_moves: List[PlacementMove] = list()
     for tile in legal_tiles:
         for piece in available_pieces:
             move = PlacementMove(piece, tile, self.board)
             legal_moves.append(move)
     return legal_moves
Esempio n. 5
0
 def evaluate_drop(self):
     if self.selected_piece is None:
         return
     drop_tile: Tile = self.get_mouse_position_object(self.selectable_tiles)
     if drop_tile is not None:
         legal_moves = self.game.get_active_player(
         ).get_legal_placement_moves()
         move = PlacementMove(self.selected_piece, drop_tile,
                              self.game.board)
         if move in legal_moves:
             self.consumable_move = move
             self.move_input_event.set()
     self.selected_piece = None
Esempio n. 6
0
    def test_symmetric_movements_removal(self):
        game = Game()

        # With an empty board, there should only be 2 valid tiles on which to play
        assert len(get_legal_abstract_moves(
            game.player_1, True)) == 2 * len(game.player_1.pieces)

        PlacementMove(
            piece=game.player_1.get_piece_by_type(PieceType.two),
            tile=game.board.get_tile(0, 2),
            board=game.board,
        ).execute()
        PlacementMove(
            piece=game.player_2.get_piece_by_type(PieceType.four),
            tile=game.board.get_tile(4, 2),
            board=game.board,
        ).execute()
        game.board.execute_board_movements(PLAYER_1_ID)

        # Now both players should have 7 legal tiles at which to place their pieces
        # as the board now has x-axis symmetry
        assert len(get_legal_abstract_moves(
            game.player_1,
            True)) == 7 * len(game.player_1.get_available_pieces())
        assert len(get_legal_abstract_moves(
            game.player_2,
            True)) == 7 * len(game.player_2.get_available_pieces())

        game.board.execute_board_movements(PLAYER_2_ID)

        # The game still has x-axis symmetry
        assert len(get_legal_abstract_moves(
            game.player_1,
            True)) == 7 * len(game.player_1.get_available_pieces())
        assert len(get_legal_abstract_moves(
            game.player_2,
            True)) == 7 * len(game.player_2.get_available_pieces())
Esempio n. 7
0
    def test_non_symmetric_movements(self):
        game = Game()

        PlacementMove(
            piece=game.player_1.get_piece_by_type(PieceType.two),
            tile=game.board.get_tile(0, 1),
            board=game.board,
        ).execute()

        # All tiles except 1 (the one occupied by player 1) should need to be considered
        assert len(get_legal_abstract_moves(
            game.player_2, True)) == 11 * len(game.player_2.pieces)

        # No after executing the movement, all possible movements need to be explored
        game.board.execute_board_movements(PLAYER_1_ID)
        assert len(get_legal_abstract_moves(
            game.player_2, True)) == 12 * len(game.player_2.pieces)