views:

95

answers:

2

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?

+1  A: 

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 6x6, 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.

mazzzzz
Yeah that was my thoughts as well just not sure how effective it actually would be...food for thought...
emalamisura
Well, I don't think all puzzles are designed this way. For example, all sudoku puzzles in the newspaper I see are symmetrical (ie either rotate them 180 or mirrored about the central vertical or horizontal axes)
apoorv020
+1  A: 

I did it once.

I started with the red block at the exit and the other blocks in random non-overlapping positions, then applied a minimum number of random feasible moves (1,000,000). If the red is far enough from the exit, and it can't be moved there (typically the case), you're done, otherwise repeat.

Mau