参考书目《元胞自动机理论研究及其仿真应用》科学出版社
邻居类型:Moore邻居
元胞状态:0 1 (正方与反方)
演化规则:当周围元胞状态为1的个数多余4,则元胞状态变为1,否则为0 (992号规则)
演化特点:每个元胞倾向于其周围占大多数的意见,若干步之后基本达稳定,且相同状态的元胞倾向于聚在一起,呈现出“物以类聚”的现象
与邻居接触较广的规则聚类现象明显于接触较少的规则。反应出在传播模型中人际交往密切的网络其舆论引导性更强
#include<Windows.h>
#include<graphics.h>
#include<stdlib.h>
#include<time.h>
#include<stdio.h>
int main()
{
int orgData[100][100], resData[100][100];
int nCount, nRows, nCols, i, j, times;
int GraphDriver = DETECT, GraphMode;
int rnd;
// srand(time(0));
for (i = 0; i < 100; i++)
for (j = 0; j < 100; j++)
{
rnd = rand() % 100;
if (rnd < 50)
orgData[i][j] = 0;
else orgData[i][j] = 1;
}
initgraph(&GraphDriver, &GraphMode, "");
setcolor(WHITE);
rectangle(270, 190, 370, 290);
for (nRows = 0; nRows < 100; nRows++)
for (nCols = 0; nCols < 100; nCols++)
{
int tx, ty, rx, ry;
nCount = 0;
for (tx = nRows - 1; tx <= nRows + 1; tx++)
for (ty = nCols - 1; ty <= nCols + 1; ty++)
{
if (tx >= 0)
if (tx < 100)
rx = tx;
else rx = tx - 100;
else rx = tx + 100;
if (ty >= 0)
if (ty < 100)
ry = ty;
else ry = ty - 100;
else ry = ty + 100;
if (orgData[rx][ry] == 1)
nCount++;
}
if (nCount >= 5)
{
putpixel(nCols + 270, 190 + nRows, BLACK);
resData[nRows][nCols] = 1;
}
else
{
resData[nRows][nCols] = 0;
putpixel(nCols + 270, 190 + nRows, WHITE);
}
for (i = 1; i < 99; i++)
for (j = 1; j < 99; j++)
orgData[i][j] = resData[i][j];
}
system("pause");
return 0;
}