Results 1 to 2 of 2
Like Tree1Likes
  • 1 Post By KevinWorkman

Thread: Logic error in cellular automaton

  1. #1
    Keesjuh is offline Member
    Join Date
    Jul 2013
    Posts
    8
    Rep Power
    0

    Default 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 Im doing something wrong and it gives me:
    *
    ****
    * *
    ****
    * *

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

    Java 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;
                                }
                            }
    Last edited by Keesjuh; 09-16-2013 at 02:47 PM.

  2. #2
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,956
    Rep Power
    8

    Default 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.
    gimbal2 likes this.
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

Similar Threads

  1. Question about dk.brics.automaton
    By kjkrum in forum Advanced Java
    Replies: 0
    Last Post: 03-29-2012, 01:22 AM
  2. Logic Error
    By Norris80 in forum New To Java
    Replies: 1
    Last Post: 02-18-2012, 06:32 AM
  3. logic error?
    By droidus in forum New To Java
    Replies: 2
    Last Post: 01-21-2012, 03:17 PM
  4. cellular automaton (A 1D CA)
    By neshkid123 in forum New To Java
    Replies: 6
    Last Post: 10-14-2011, 09:02 PM
  5. help with a logic error
    By ShinTec in forum Advanced Java
    Replies: 11
    Last Post: 05-02-2010, 10:19 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •