c++ - Called function clears changes of previous one -


i'm working on cellular automaton changes happen in every rounds. obviously, made loop - works, fortunately, if want add type of cells map, 1 type of cells works, other doesn't anything: game begins , e.g. in example, conway-automaton starts growing, red test-cells staying without changes.

#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 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;      (j=1;j<fldheight-1;j++)     {         (i=1;i<fldwidth-1;i++)         {             if (equality(&arra[i][j], &test_alive) == true)             {             counter = -1;             } else {                 counter = 0;             }             (b=j-1;b<=j+1;b++)             {                 (a=i-1;a<=i+1;a++)                 {                     if (equality(&arra[a][b], &test_alive) == true)                     {                         counter+=1;                     }                 }             }             arrb[i][j] = arra[i][j];             //itt sejtek szabályai jönnek; mindig születést tesszük előre, utána 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;      (j=1;j<fldheight-1;j++)     {         (i=1;i<fldwidth-1;i++)         {             if (equality(&arra[i][j], &conway_alive) == true)             {             counter = -1;             } else {                 counter = 0;             }             (b=j-1;b<=j+1;b++)             {                 (a=i-1;a<=i+1;a++)                 {                     if (equality(&arra[a][b], &conway_alive) == true)                     {                         counter+=1;                     }                 }             }             arrb[i][j] = arra[i][j];             //itt sejtek szabályai jönnek; mindig születést tesszük előre, utána 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;             }         }     } } 

this content of loop:

test(fielda,fieldb); conway(fielda,fieldb); end = false; round++; (j = 0; j < fldheight; j++)     {         (i = 0; < fldwidth; i++)         {             fielda[i][j] = fieldb[i][j];         }     } 

as mentioned, in example, conway cells grow, test cells stay. how make them work simultaneously?

(i use allegro libraries if has problem, feel free share me!)

test(fielda,fieldb); sets every cell of fieldb based on current value of fielda. , conway(fielda,fieldb); sets every cell of fieldb based on current value of fielda, overwriting fieldb test did gone. 1 way fix change loop to:

test(fielda,fieldb); conway(fieldb,fielda);  //switched parameters end = false; round++; //there no need copy fieldb fielda here because conway did 

but might not right fix depending on how want test , conway interact each other.


Comments

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

delphi - Dynamic file type icon -