ICode9

精准搜索请尝试: 精确搜索
首页 > 编程语言> 文章详细

写学习abcde的简单AI(C++实现)

2021-08-09 17:34:13  阅读:252  来源: 互联网

标签:map show AI random abcde ++ C++ int lenth


#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;
}

  

标签:map,show,AI,random,abcde,++,C++,int,lenth
来源: https://www.cnblogs.com/carmine/p/15119662.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有