猴子摘香蕉

2023-03-29 15:03:10   第一文档网     [ 字体: ] [ 阅读: ] [ 文档下载 ]
说明:文章内容仅供预览,部分内容可能不全。下载后的文档,内容与下面显示的完全一致。下载之前请确认下面内容是否您想要的,是否完整无缺。下载word有问题请添加QQ:admin处理,感谢您的支持与谅解。点击这里给我发消息

#第一文档网# 导语】以下是®第一文档网的小编为您整理的《猴子摘香蕉》,欢迎阅读!
香蕉,猴子



猴子摘香蕉



实验分析

1. 定义描述环境状态的谓词。

Monkey(a):猴子在a点,本题中取abc Hold(x,t)x手中拿着t Onbox(a)abox上。 Box(a)boxa点。 Banana(a):bananaa点。

2. 使用谓词、连结词、量词来表示环境状态。 问题的初始状态可表示为: SoMonkey(a)˄Box(c) ˄Banana(b) 要达到的目标状态为:

S: Monkey(b) ˄Box(b) ˄Onbox(monkey) ˄Hold(monkey,banana) 谓词:

goto(a,b):猴子从a走到b处。 push(a,b):猴子把b推到a处。 climb(a):猴子爬上a reach(a):猴子去拿a 猴子的路线是:

goto(a,c)push(c,box)climb(box)reach(banana)

在上述过程中,我们应该注意,当猴子执行某一个操作之前,需要检查当前状态是否可使所要求的条件得到满足,即证明当前状态是否蕴涵操作所要求的状态的过程。在行动过程中, 检查条件的满足性后才进行变量的代换。代入新条件后的新状态如果是目标状态,则问题解决;否则看是否满足下面的操作,如果不满足或即使满足却又回到了原来的状态,那么代入无效。










源代码

#include struct State {

int monkey; /*0:Monkey at A;1: Monkey at B;2:Monkey at C;*/

int box; /*0:box at A;1:box at B;2:box at C;*/

int monbox; /*1: monkey on the box;0: monkey are not on the box;*/ };

char* routesave[10];

void nextStep(struct State States,int i){ if (States.monkey == States.box){ if (States.monkey == 1) { if (States.monbox == 1) {

printf("you've got the result:\n"); routesave[i]="Monkey get the banana!"; }else{

States.monbox = 1;

routesave[i]="Monkey climbs on the box!"; nextStep(States,i+1); } }else{

States.monkey = 1; States.box = 1;

routesave[i]="Monkey pushes the box to B!"; nextStep(States,i+1); }




本文来源:https://www.dywdw.cn/05972035a000a6c30c22590102020740bf1ecd79.html

相关推荐
推荐阅读