人工智能猴子摘香蕉代码_猴子妈妈有14个香蕉

2022-11-09 16:11:32 浏览数 (1)

大家好,又见面了,我是你们的朋友全栈君。

只有简单的状态显示

代码语言:javascript复制
#include "iostream"
using namespace std;
void AT(char monkeyplace, char boxplace)
{
cout << "AT(monkey," << monkeyplace << ")" << endl;
cout << "AT(box," << boxplace << ")" << endl;
}
void STATE(int on, int HB)
{
if (on == 0)
cout << "!ONBOX" << endl;
else
cout << "ONBOX" << endl;
if (HB == 0)
cout << "!HB" << endl;
else
cout << "HB" << endl;
}
char GOTO(char ST, char LT)
{
if (ST != LT)
return LT;
else
return ST;
}
void ACT(char monkey, char box, char banana, int on, int HB)
{
if (monkey != banana)
{
cout << "=============GOTO(" << monkey << "," << box << ")===============>" << endl;
monkey = GOTO(monkey, box);
AT(monkey, box);
STATE(on, HB);
cout << endl;
}//猴子移动至箱子处
if (monkey != banana)
{
cout << "=============PUSH(" << monkey << "," << banana << ")===============>" << endl;
monkey = GOTO(monkey, banana);
AT(monkey, banana);
STATE(on, HB);
cout << endl;
}//猴子搬运箱子至香蕉处
if (monkey == banana && on == 0)
{
cout << "=============CLIMBBOX===============>" << endl;
AT(monkey, banana);
on  ;
STATE(on, HB);
cout << endl;
}//猴子爬上箱子
if (monkey == banana && on == 1 && HB == 0)
{
cout << "=============GRASP===============>" << endl;
AT(monkey, banana);
HB  ;
STATE(on, HB);
cout << endl;
}//猴子摘香蕉
}
int main()
{
char monkey, box, banana;
int on = 0, HB = 0;
cout << "猴子的位置:";
cin >> monkey;
cout << "箱子的位置:";
cin >> box;
cout << "香蕉的位置:";
cin >> banana;
cout << endl;
cout << "=============开始===============>" << endl;
AT(monkey, box);
STATE(on, HB);
cout << endl;//初始状态
ACT(monkey, box, banana, on, HB);
system("pause");//按任意键退出
return 0;
}

第一次用这个博客编辑器 先搞个简单的试试怎么用

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。

0 人点赞