map / graph display issue "NP-complete". This means that the scientific community is almost certain that any given problem algorithm will spend exponential (huge) amounts of time on specific instances of the problem (i.e.Puzzles). This is why any algorithm you implement (including your brute force mechanism) will overwhelm some puzzle examples.
I would recommend that you implement a couple of different algorithms to solve your puzzles, for example.
Algorithm 1 - one by one, select a random area and give it a color that is still "suitable", i.e. is not the color of any color neighbor. If you encounter a conflict (cannot paint the selected area), stop the algorithm. Run this cycle, say, N times, and count the number of cycles that actually actually color the entire map; let it be K. Here you get the K / N score (in percent), 0% = difficult problem (possibly impossible), 100% = very simple problem
Algorithm 2 - add the amount of backtracking to algorithm 1, for example. allow a maximum of 1000 indentation steps. Run the same “fetch” cycle. You get one more point 0% -100%.
Then use the resulting points (you will get higher points from Alg. 2 than from Alg.1 because they are more powerful) to get the relative difficulty for the puzzles.
The key to this is that if you get a score (0%, 0%), that is, you don’t know if the puzzles are solvable, YOU REFUSE it because you don’t want to present problems to your audience, it can be unsolvable :)
Finally, use your own judgment to “match” scores with “readable” descriptions of difficulties — select a couple of puzzles, solve them manually, check the score your program calculates, and then see how percentages are mapped to your perception of difficulty.
Antti huima
source share