I believe that we can reduce the contained problem of maximal variety to boolean satisifability and show NP-completeness through any dependence on this subtask. Because of this, the spinning_plate algorithms provided are reasonable, since heuristics, computer pre-processing, and machine learning are reasonable , and the trick is finding the best heuristic solution if we want to miss here.
Consider the following board:
..S........ #.#..#..### ........... ........... ..........F
This has many problems that make greedy and gate-related solutions fail. If we look at this second line:
#.
Our logic is in a 0-based 2D array, ordered as [row][column] :
[1][4], [1][5], [1][6], [1][7], [1][8]
We can re-imagine this as an equation to satisfy a block:
if ([1][9] AND ([1][10] AND [1][11]) AND ([1][12] AND [1][13]): traversal_cost = INFINITY; longest = False # Infinity does not qualify
Except for infinity as an unsatisfactory case, we go back and relay this as:
if ([1][14] AND ([1][15] AND [1][16]) AND [1][17]: traversal_cost = 6; longest = True
And our hidden logical relationships fall among all these gates. You can also show that geometric proofs cannot be fractionalized recursively, because we can always create a wall that has exactly N-1 width or height, and this is an important part of the solution in all cases (therefore, divide and conquer will not help you).
In addition, since the perturbations in different lines are significant:
..S........ #.#........ ...#..#.... .......#..# ..........F
We can show that without a complete set of computable geometric identities, the full search space reduces to N-SAT.
In addition to this, we can also show that it is trivial to check and non-polynomially solve, since the number of gates is approaching infinity. It is not surprising that therefore tower defense games remain so fun for people to play. Obviously a more rigorous proof is desirable, but this is a skeletal beginning.
Note that you can significantly reduce the n-term with respect to n-select-k. Since we can recursively show that each perturbation must lie on the critical path and because the critical path is always calculated in O (V + E) time (with several optimizations to speed up the process for each perturbation), you can significantly reduce your space search in a breadth-first search score of each additional tower added to the board.
Since we can very likely take O (n ^ k) for a deterministic solution, a heuristic approach is reasonable. My advice, therefore, lies somewhere between the spinning_plate answer and Soravux , with an eye on machine learning methods applicable to the problem.
Solution 0: use a valid but suboptimal AI in which spinning_plate provided two applicable algorithms. Indeed, these approximate numbers of naive players are approaching the game, and this should be enough for a simple game, albeit with a high degree of exploitation.
1st order solution: use a database. Given the formulation of the problem, you have not quite proved the need to calculate the optimal solution on the fly. Therefore, if we relax the restriction of approaching a random board without information, we can simply precommute the optimal for all K admissible for each board. Obviously, this only works for a small number of boards: with V! potential states of the board for each configuration, we cannot highly compromise all the optima, since V becomes very large.
2nd order solution: use the machine learning step. Facilitate every step as you close the gap, which leads to a very high cost of crawling, until your algorithm converges or a more optimal solution is found than greedy ones. Many algorithms are applicable here, so I recommend following the classics and literature to choose the right one that works within the limits of your program.
The best heuristic can be a simple heatmap created by a local state recursive depth traversal, sorting the results by most of them, as a rule, intersect after traversing O (V ^ 2). Fulfilling this conclusion, he eagerly identifies all bottlenecks, and to do this without making impossible paths is quite possible (checking this is O (V + E)).
Combining all this, I would try to intersect with these approaches by combining the heatmap and critical path identifiers. I would suggest that here is enough to come up with a good functional geometric proof that satisfies all the limitations of the problem.