How far can you get with this formulation? Currently, I found a path of length 48. Oh yes, there are! Now it does make sense to rule out such paths. Are there really any cycles? Let's ask that first:Į = state(void,on(c,void),on(a,on(b,void))) Now, is this really the best way to ask? After all, many of the answers might be simple cycles, putting a block into one place and back again. And out of a sudden Prolog answered with a shorter answer than you expected! See what I did? I only added length(X, N) in front. Path( state(on(c,on(b,on(a,void))), void, void), OK, so let's try out any length! Also this is something Prolog loves. How long shall that list be? We know not (that is, I don't). Instead of asking for a concrete answer which demands from your Prolog system quite a bit of ingenuity, let's formulate your answer as a query! I tried it and realized that you have some nasty syntax errors in them, and after that, the query failed.īut there is a cheaper way! Let's just limit the length of the list and let Prolog fill out the rest. Instead, you can reformulate your queries sparingly. State(on(c,on(b,on(a,void))), void, void)].įor a first test, there is no need to rewrite your code. State(void, on(c,void), on(void(a,on(b,void))), I got ERROR: Out of local stack, but I want that that X would be X=[state(void, void, on(c,on(a,on(b,void)))), The problem is that the predicate path doesn't work as I want, i.e., if I type path(state(on(c,on(b,on(a,void))), void, void), state(void, void, on(c,on(a,on(b,void)))), X). Where move give us the possible movements that you can use and path should give us the path that you have to take from X to Y. Move(state(X, OldY, on(Z, NewZ)), state(X, on(Z, OldY), NewZ)). Move(state(OldX, Y, on(Z, NewZ)), state(on(Z, OldX), Y, NewZ)). Move(state(X, on(Y, NewY), OldZ), state(X, NewY, on(Y, OldZ))). Move(state(OldX, on(Y, NewY), Z), state(on(Y, OldX), NewY, Z)). Move(state(on(X, NewX), Y, OldZ), state(NewX, Y, on(X, OldZ))). I have the following code: move(state(on(X, NewX), OldY, Z), state(NewX, on(X, OldY), Z)).
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |