A rather specific question, does anyone know an existing piece of code on how to generate solvable levels for the game unblock me? OR what would the best approach to writing my own be? Typically how would you go about writing an algorithm to test and generate solvability and such?
Share
Well, I code these problems by just brute forcing it. create a way to input what the board looks like (where the rectangles are, and their orientation), then write a recursive function that goes into every possible move.
Not to hard, theoretically 😉
Note the board is 6×6, and don’t forget to make a way for the program to output each move.
Max
EDIT: after thinking about it for a while, you should actually figure out which block is holding the red block from moving to the right, then figure out which direction it should go (only can be a vertical block). If it’s 3 high, the block must go down, otherwise, create a fork in the recursive function, and test what would happen if the block moved in either direction. Then figure out which block is blocking the last block, until nothing is being blocked.
It’s a possibility.