Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

Breadth-first tree creation in C

Name: Anonymous 2010-05-21 8:51

'sup /prog/, I'm trying to create a c-based program to solve tipover (http://www.puzzlebeast.com/crate/) puzzles and generate a file with all the moves for the fastest solution(min number of moves) . So far, I'm thinking of doing a tree with 4 directions (N,S,E,W), a list with temporary boards and a queue with the movements made.

I was thinking of doing it breadth-first, but I'm having trouble coming up with an algorithm for breadth-first GENERATION of the tree (i.e. a level at a time, if it reaches the solution it stops, avoiding having to build the whole tree). Does anybody have any suggestions?

Name: Anonymous 2010-05-21 9:06

Since the number of possible movements is limited and relatively small I suggest you to use brute force generation of all posibilities, then take the most efficient. Sure is possible to make a better algorithm, but i think it should come as a natural consequence of the brute force algorithm.
Probably using backtracking is a good idea, but i cannot visualize how at this moment.

Name: Anonymous 2010-05-21 9:41

Have you read your Xarn today?

Name: Anonymous 2010-05-21 9:46

Yeah the problem is how would I avoid situations for example where I move up, down, left and right indefinitely. Can't seem to find a stop condition.

extra info: I'm using a two-dimensional array for the boards, with an initial and final position. Empty spaces are 0s, and boxes are numbers depending on number of boxes.

Name: Anonymous 2010-05-21 10:02

Protip: keep a list of visited states. It doesn't have to be a complete list.
And take >>3's advice. Xarn isn't good for much, but he wrote blog posts specifically covering this fairly nicely.

Name: Anonymous 2010-05-21 10:06

>>1
Use Haskell and exploit laziness and the nondeterminism monad.

Name: Anonymous 2010-05-21 10:07

Thanks, gonna check it out.

Name: Anonymous 2011-02-04 18:10

Don't change these.
Name: Email:
Entire Thread Thread List