开发者_开发百科
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this questionA 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?
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.
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.
精彩评论