J'ai un problème assez simple mais je n'arrive pas à le comprendre. Je crois que c'est une erreur de logique ayant à voir avec la vérification des voisins dans les automates cellulaires. Voici mon code qui fonctionne une fois par seconde pour la culture et la vérification voisins:Automates cellulaires vérifiant les voisins
public void grow(){
Cell[][] next = new Cell[100][100];
for(int row = 0; row < (SIZE_X/SIZE); row++){
for(int col = 0; col < (SIZE_Y/SIZE); col++){
Cell cell = grid[row][col];
Cell nCell = grid[row][col]; // gets
if(cell != null){
int amount = neighbors(row, col); // find out how many neighbors are ALIVE/ON
if(cell.isOn() == true && amount != 3) // if the current cell is on but doesnt have 3 alive neighbors, it gets turned off
nCell.onOff(false);
else if(cell.isOn() == false && (amount >= 1 && amount <= 4)) // if it is off and has 1-5 alive neighbors it gets turned on
nCell.onOff(true);
next[row][col] = nCell;
}
}
}
grid = next;
}
public int neighbors(int row, int col){ // checks the amount of neighbors that are ALIVE/ON
int amount = 0;
for(int r = row-1; r <= row+1; r++){ // stepping through a 3x3 area of the grid, which surrounds the selected block
for(int c = col-1; c <= col+1; c++){
// clamp
if((r > 0 && r < 99) && (c > 0 && c < 99)){
if(grid[r][c].isOn() == true && (r != row && c != col)) // checks if the current neighbor is ALIVE/ON
amount++; // if it is then add one to the count
}
}
}
return amount;
}
Im en utilisant un 12345/3 simple (survie/naissance) règle dans mon Cellular Automata. Le problème actuellement est que j'ai une grille de 100x100 avec un espace de 10x10 cellules ALIVE/ON dans le centre. Après que mon code s'exécute une fois, toutes les cellules meurent.
Si quelqu'un a besoin de plus d'informations, n'hésitez pas à demander. Merci d'avance!
Désolé pour la réponse tardive. J'ai donc mis en place quelques changements qui ont résolu les problèmes dont vous avez parlé. Cependant, un autre problème est apparu: il s'agit maintenant d'une pyramide massive à droite des blocs de départ et qui se développe lentement avec apparemment aucune rime ou raison. Iv a mis à jour mon code –