저는 매순간마다 변경이 이루어지는 셀룰러 오토메이션 작업을하고 있습니다. 분명히, 저는 루프를 만들었습니다. 기본적으로 다행히도 작동하지만 맵에 다른 유형의 셀을 추가하려면 한 종류의 셀이 작동하지만 다른 셀은 아무 것도하지 않습니다. 이 예에서 Conway-Automaton은 성장하기 시작하지만 빨간색 테스트 셀은 변경없이 그대로 있습니다.호출 된 함수가 이전 함수의 변경 내용을 지움
Test(fielda,fieldb);
Conway(fielda,fieldb);
end = false;
round++;
for (j = 0; j < fldheight; j++)
{
for (i = 0; i < fldwidth; i++)
{
fielda[i][j] = fieldb[i][j];
}
}
내가 언급 한 바와 같이,이 예에서, 콘웨이 세포 성장하지만, 테스트 세포 그냥 유지 :
#define fldwidth 110
#define fldheight 140
typedef struct tiles
{
unsigned char red, green, blue;
}tiles;
const tiles TEST_ALIVE = {255,0,0};
const tiles TEST_DEAD = {50,0,0};
const tiles CONWAY_ALIVE = {0,255,0};
const tiles CONWAY_DEAD = {0,50,0};
//Maes módszere a struktúrák egyenlőségének vizsgálatára
bool equality(tiles* a, const tiles* b)
{
if (a->red == b->red && a->green == b->green && a->blue == b->blue)
{
return true;
} else {
return false;
}
}
//sejttípus 1.: tesztsejt: minden magányos vagy túlbuzgó sejt meghal
void Test(tiles arra[fldwidth][fldheight], tiles arrb[fldwidth][fldheight])
{
int a,b,i,j,counter;
for (j=1;j<fldheight-1;j++)
{
for (i=1;i<fldwidth-1;i++)
{
if (equality(&arra[i][j], &TEST_ALIVE) == true)
{
counter = -1;
} else {
counter = 0;
}
for (b=j-1;b<=j+1;b++)
{
for (a=i-1;a<=i+1;a++)
{
if (equality(&arra[a][b], &TEST_ALIVE) == true)
{
counter+=1;
}
}
}
arrb[i][j] = arra[i][j];
//itt a sejtek szabályai jönnek; mindig a születést tesszük előre, utána a halált!
if (equality(&arra[i][j], &TEST_ALIVE) == false && counter >= 2)
{
arrb[i][j] = TEST_ALIVE;
}
if (equality(&arra[i][j], &TEST_ALIVE) == true && (counter == 0 || counter > 6))
{
arrb[i][j] = TEST_DEAD;
}
}
}
}
//sejttípus 2.: Conway életjátéka
void Conway(tiles arra[fldwidth][fldheight], tiles arrb[fldwidth][fldheight])
{
int a,b,i,j,counter;
for (j=1;j<fldheight-1;j++)
{
for (i=1;i<fldwidth-1;i++)
{
if (equality(&arra[i][j], &CONWAY_ALIVE) == true)
{
counter = -1;
} else {
counter = 0;
}
for (b=j-1;b<=j+1;b++)
{
for (a=i-1;a<=i+1;a++)
{
if (equality(&arra[a][b], &CONWAY_ALIVE) == true)
{
counter+=1;
}
}
}
arrb[i][j] = arra[i][j];
//itt a sejtek szabályai jönnek; mindig a születést tesszük előre, utána a halált!
if (equality(&arra[i][j], &CONWAY_ALIVE) == false && counter == 3)
{
arrb[i][j] = CONWAY_ALIVE;
}
if (equality(&arra[i][j], &CONWAY_ALIVE) == true && (counter != 2 && counter != 3))
{
arrb[i][j] = CONWAY_DEAD;
}
}
}
}
이 루프의 내용이다. 그것들을 동시에 작동시키는 방법?
(즉,이 문제에 대한 뭔가가있는 경우, 저와 함께 공유 할 주시기 그래서 나는 알레그로 라이브러리를 사용!)
작동합니다! 고맙습니다! 어쨌든 Test와 Conway는 서로 상호 작용할 필요는 없지만이 문제를 해결하는 것이 더 많은 종류의 세포를 추가 할 수 있다는 것이 중요했습니다. 현재 내가 추가하고 싶은 것은 Conway를 차단하지만 다른 것을 차단하지 않는 일종의 "wall-cell"입니다. –