simulator qui fonctionne

This commit is contained in:
yoenm 2024-05-21 14:46:32 +02:00
parent 7e6bc0923c
commit e15cbd9400
1 changed files with 11 additions and 15 deletions

View File

@ -128,23 +128,19 @@ public class Simulator extends Thread {
* and the count is in the birth list,
* then the cell becomes alive
*/
}
{
int[][] newGrid= new int [COL_NUM][LINE_NUM]; // creating a new grid which is an integer with colum_num for nb of columns and line_num for nb of lines
for (int x=0; x< COL_NUM; x++) {
for (int y=0; y<LINE_NUM; y++) { // to apply what is under to all cells
int aliveCount= countSurroundingValues(x,y,1);
if (grid[x][y]==1) { // cell is alive
newGrid[x][y]=fieldSurviveValues.contains(aliveCount) ? 1:0;
}else { // cell is dead
newGrid[x][y] = fieldBirthValues.contains(aliveCount) ? 1 : 0;
} //here we set the alive cells and dead cells for the next stage of the game
int[][] newGrid= new int [COL_NUM][LINE_NUM]; // creating a new grid which is an integer with colum_num for nb of columns and line_num for nb of lines
for (int x=0; x< COL_NUM; x++) {
for (int y=0; y<LINE_NUM; y++) { // to apply what is under to all cells
int aliveCount= countSurroundingValues(x,y,1);
if (grid[x][y]==1) { // cell is alive
newGrid[x][y]=fieldSurviveValues.contains(aliveCount) ? 1:0;
}else { // cell is dead
newGrid[x][y] = fieldBirthValues.contains(aliveCount) ? 1 : 0;
} //here we set the alive cells and dead cells for the next stage of the game
}
}
grid = newGrid; // we set the new grid which we computed just above to actual grid ( we put the next stage as actual stage)
}
grid = newGrid; // we set the new grid which we computed just above to actual grid ( we put the next stage as actual stage)
}
public int countSurroundingValues(int x, int y, int typeToCount) { // we create the method to count surrounding values