写学习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++实现)的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-09-19Excel数据导出课程:初学者必备教程
- 2024-09-19Excel数据导入课程:新手入门指南
- 2024-09-19RBAC的权限管理入门教程
- 2024-09-19如何使用Svg Sprite Icon制作图标
- 2024-09-19uniapp 如何实现点赞后全局更新数据-icode9专业技术文章分享
- 2024-09-19云函数怎么运行wx-server-sdk-icode9专业技术文章分享
- 2024-09-19"dependencies": { "wx-server-sdk": "latest" },是什么意思-icode9专业技术文章分享
- 2024-09-16优化批处理流程:自定义BatchProcessorUtils的设计与应用
- 2024-09-15laravel collect游标批量插入的方法示例-icode9专业技术文章分享
- 2024-09-15怎么修改laravel的中间件 把获取IP改成X-Real-IP-icode9专业技术文章分享