A fast algorithm for creating a puzzle

前端 未结 1 1313
星月不相逢
星月不相逢 2021-01-31 22:41

I found a puzzle in http://www.puzzles.ca/wordsearch/transportation.html where one has to find word in a grid and (s)he can read words from 8 directions. The following question

相关标签:
1条回答
  • 2021-01-31 22:49

    An algorithm is described in this SO question also

    https://stackoverflow.com/a/23435654/3591273

    Hope this helps

    UPDATE: Summary of an algorithm (as given in previous link)

    1. Randomly select the first empty wordslot to be filled from the grid and fill it with a suitable word

    2. Find all empty wordslots that have intersections to already filled wordslots

    3. Sort them by a constraint ratio (eg number of available solutions for each one)

    4. Loop through the empty slots of previous step and try a number of candidate words (from the available words)

    5. Select the wordslot and the word to fill that retains grid consistency (ie grid has a solution after this word slot is filled with this word) and also the number of solutions in next step is maximum (this minimises bactracks in next steps) and go to step 2

    6. If no word found in previous step, try to backtrack to a previous word and use an alternative candidate (unless available candidates are exhausted)

    7. Optionally reset any word slots that might need reset after the backtrack (ie mark them as empty again) and go to step 2

    8. If no backtrack found then this configuration has no solution

    9. If all empty slots are filled you have one solution

    0 讨论(0)
提交回复
热议问题