写学习abcde的简单AI(C++实现)
2021/8/9 17:35:49
本文主要是介绍写学习abcde的简单AI(C++实现),对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
#include <iostream> #include <time.h> #include <stdlib.h> #include <cmath> using namespace std; #define random(a,b) (rand() % (b-a+1))+ a /* run this program using the console pauser or add your own getch, system("pause") or input loop */ const int association = 70;//产生联想的概率 const int divergence = 29;//产生发散的概率 bool Forget = false;//是否会发生战争 const int lenth = 5; int main() { srand(time(NULL)); int map[lenth][lenth]; for(int i = 0;i < lenth;++i) { for(int j = 0;j < lenth;++j) { map[i][j] = -1; } } string show[lenth][lenth]; for(int i = 0;i < lenth;++i) { for(int j = 0;j < lenth;++j) { show[i][j] = "warn"; } } int x, y;//坐标点 int tempX, tempY; bool first = false;//记录是否为第一次 int development;//记录发展的趋势 string learn[lenth] = {"a", "b", "c", "d", "e"}; string answer[lenth]; int i = 0; while(true) { while(true) { if(!first) {//随机初始化坐标 i = 0; x = random(0,lenth-1); y = random(0,lenth-1); map[x][y] = i; show[x][y] = learn[i]; first = true; ++i; } else { development = random(1,100);//随机出发展的趋势 if(development > 0 && development <= association) {//如果随机的发展趋势为百分之70,则进入联想模式 tempX = random(0,2) - 1; x = x + tempX; tempY = random(0,2) - 1; y = y + tempY; while((x < 0 || x >= lenth) || (y < 0 || y >= lenth)) { x = x - tempX; tempX = random(0,2) - 1; x = x + tempX; y = y - tempY; tempY = random(0,2) - 1; y = y + tempY; } map[x][y] = i; show[x][y] = learn[i]; ++i; } else if(development > association && development <= (association + divergence)) {//如果随机的发展趋势为百分之29,则进入发散模式 tempX = x; x = random(0,lenth-1); tempY = y; y = random(0,lenth-1); while(((x > (tempX - 1))&&(x < (tempX + 1)))||((y > (tempY - 1))&&(y < (tempY + 1)))){ x = random(0,lenth-1); y = random(0,lenth-1); } map[x][y] = i; show[x][y] = learn[i]; ++i; } else {//是否遗忘 x = random(0,lenth-1); y = random(0,lenth-1); map[x][y] = -1; show[x][y] = "warn"; ++i; Forget = true; } if(i >= lenth || Forget == true) { break; } } } if(Forget == true) { Forget = false; first = false; continue; } else { break; } } for(int i = 0;i < lenth;++i) { for(int j = 0;j < lenth;++j) { if(map[i][j] != -1){ answer[map[i][j]] = show[i][j]; } } } for(int i = 0;i < lenth;++i) { cout << answer[i] << endl; } return 0; }
这篇关于写学习abcde的简单AI(C++实现)的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2025-01-11国产医疗级心电ECG采集处理模块
- 2025-01-10Rakuten 乐天积分系统从 Cassandra 到 TiDB 的选型与实战
- 2025-01-09CMS内容管理系统是什么?如何选择适合你的平台?
- 2025-01-08CCPM如何缩短项目周期并降低风险?
- 2025-01-08Omnivore 替代品 Readeck 安装与使用教程
- 2025-01-07Cursor 收费太贵?3分钟教你接入超低价 DeepSeek-V3,代码质量逼近 Claude 3.5
- 2025-01-06PingCAP 连续两年入选 Gartner 云数据库管理系统魔力象限“荣誉提及”
- 2025-01-05Easysearch 可搜索快照功能,看这篇就够了
- 2025-01-04BOT+EPC模式在基础设施项目中的应用与优势
- 2025-01-03用LangChain构建会检索和搜索的智能聊天机器人指南