佳礼资讯网

 找回密码
 注册

ADVERTISEMENT

查看: 1010|回复: 5

Prolog - recursion问题!! 帮帮忙!!!

[复制链接]
发表于 5-10-2006 12:51 AM | 显示全部楼层 |阅读模式
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 不会做。。。
任何高手能帮帮忙吗???
回复

使用道具 举报


ADVERTISEMENT

发表于 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 | 显示全部楼层

回复 #3 月崖 的帖子

把出现问题的部分放上来。
回复

使用道具 举报

 楼主| 发表于 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 | 显示全部楼层
我的问题已经解决了。。。

请版主删帖。。
谢谢。。。
回复

使用道具 举报

Follow Us
您需要登录后才可以回帖 登录 | 注册

本版积分规则

 

ADVERTISEMENT



ADVERTISEMENT



ADVERTISEMENT

ADVERTISEMENT


版权所有 © 1996-2023 Cari Internet Sdn Bhd (483575-W)|IPSERVERONE 提供云主机|广告刊登|关于我们|私隐权|免控|投诉|联络|脸书|佳礼资讯网

GMT+8, 23-9-2024 09:19 PM , Processed in 0.130108 second(s), 25 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表