查看: 1025|回复: 5
|
Prolog - recursion问题!! 帮帮忙!!!
[复制链接]
|
|
Imagine a grid consisting of (evenly spaced) horizontal and vertical lines;assume that it is possible to place an object at the intersection of any two lines.
A possible configuration of objects on the grid might be:
| | | |
----[A]---[B]--- +----[C]----
| | | |
----[D]---[E]---[F]---[G]----
| | | |
---- + ---[H]--- + --- + ----
| | | |
---- + ---[I]--- + --- + ----
| | | |
Describe the position of the objects relative to each other(after all, Prolog is a relational language)
Now we write some rules will check if
l. an object is immediately to the right of another.
2. an object is immediately to the left of another.
3. an object is immediately above another
4. an object is immediately below another an object is exactly between two others, either in a horizontal or vertical direction
5. an object is directly beside another in a diagonal direction.
Finally, generalise the above so that they return all objects to the right/left or above/below another ( using recursion)
我剩下 recursion part 不会做。。。
任何高手能帮帮忙吗??? |
|
|
|
|
|
|
|
发表于 5-10-2006 09:23 AM
|
显示全部楼层
recursion 函数功能就是自己 call 回自己。
功课自己尝试做先。 |
|
|
|
|
|
|
|
楼主 |
发表于 5-10-2006 01:01 PM
|
显示全部楼层
原帖由 白日梦 于 5-10-2006 09:23 AM 发表
recursion 函数功能就是自己 call 回自己。
功课自己尝试做先。
尝试过了。。。
但是不能用。。。
有问题。。 |
|
|
|
|
|
|
|
发表于 5-10-2006 01:43 PM
|
显示全部楼层
|
|
|
|
|
|
|
楼主 |
发表于 5-10-2006 02:03 PM
|
显示全部楼层
is_right(Obj1,Obj2):-right(Obj1,Obj2).
is_right(Obj1,Obj2):-right(Obj1,Obj3),is_right(Obj3,Obj2).
这个是 right part, 但是below and diagonal part的recursion有点头痛..
[ 本帖最后由 月崖 于 5-10-2006 03:43 PM 编辑 ] |
|
|
|
|
|
|
|
楼主 |
发表于 6-10-2006 02:21 AM
|
显示全部楼层
我的问题已经解决了。。。
请版主删帖。。
谢谢。。。 |
|
|
|
|
|
|
| |
本周最热论坛帖子
|