Logic error in cellular automaton

• 09-16-2013, 03:41 PM
Keesjuh
Logic error in cellular automaton
Hello all,

I was asked to make a cellular automaton. This should be the input:
A 5 5 (the A is for the automaton, the first 5 for the length of the automaton and the second 5 for the amount of generations)
init_start 3 init_end (this sentence will turn the 3th place of the automaton to true)

This is supposed to give this result:
*
* *
* * *
* *
* * *

For some reason I´m doing something wrong and it gives me:
*
****
* *
****
* *

I can´t seem to figure out what the problem is. Can someone please look into it?

Code:

```if (!"init_end".equals(end)) {                 System.out.println("error");             } else {                 for (int i = 0; i < G; i++) {                     for (int j = 1; j < (L - 1); j++) {                         if ((nextGen[j]) == true) {                             uitkomst = uitkomst + "*";                         } else {                             uitkomst = uitkomst + " ";                         }                     }                     if (input.equals("A")) {                         System.out.println(uitkomst);                         uitkomst = "";                         for (int j = 1; j < L - 1; j++) {                             System.arraycopy(nextGen, 0, currentGen, 0, L);                             if ((currentGen[j] == true) && ((currentGen[j - 1]) == (currentGen[j + 1]))) {                                 nextGen[j] = false;                             } else if ((currentGen[j] == false) && ((currentGen[j - 1] == true) || (currentGen[j + 1] == true))) {                                 nextGen[j] = true;                             }                         }```
• 09-16-2013, 04:02 PM
KevinWorkman
Re: Logic error in cellular automaton
Time to step through this with a debugger, or at least add some print statements, to figure out when the code's execution differs from what you'd expect.