Пример #1
0
    def run(rows, columns, depth, weights):
        def update_board_with_matches(board, matches):
            for piece, clusters in matches:
                for r, c in clusters:
                    board.update(r, c, type(piece))

        b = Board.create_randomized_board(5, 6)
        # b = Board([Fire,  Wood,  Water, Dark,  Light, Light,
        #           Water, Fire, Water, Light, Heart, Light,
        #           Fire,  Water, Dark,  Heart, Heart, Wood,
        #           Light, Water, Light, Fire,  Wood,  Wood,
        #           Dark,  Heart, Dark,  Light, Heart, Light], 5, 6)

        m = Board.create_empty_board(rows, columns)
        update_board_with_matches(m, b.get_matches())

        h = GreedyDfs(weights) if False else PrunedBfs(weights)
        h.diagonals = True
        start = time.time()
        moves = h.solve(b, depth)
        performance = time.time() - start

        print('---------------------------------------------')
        print(b)
        print(m)
        print('run time : ' + str(performance))
        print('best move score : ' + str(moves[0]))
        print('start : ' + str(moves[1][0]))
        print('moves : ' + str(moves[1][1:]))
        print(moves[2])

        m = Board.create_empty_board(rows, columns)
        update_board_with_matches(m, moves[2].get_matches())

        print(m)
Пример #2
0
def test_empty_board():
    # empty board should contain only Unknown pieces
    b = Board.create_empty_board(5, 6)
    unknown_pieces = [
        b.cell(r, c) for c in range(b.columns) for r in range(b.rows)
        if isinstance(b.cell(r, c), Unknown)
    ]
    assert len(
        unknown_pieces
    ) == 30, "Creating empty board does not contain only Unknown pieces!"
Пример #3
0
def test_empty_board():
    # empty board should contain only Unknown pieces
    b = Board.create_empty_board(5, 6)
    unknown_pieces = [b.cell(r, c) for c in range(b.columns) for r in range(b.rows) if isinstance(b.cell(r, c), Unknown)]
    assert len(unknown_pieces) == 30, "Creating empty board does not contain only Unknown pieces!"