CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Apr 2010
    Posts
    9

    rule 30 finite automaton

    Hello all,

    This is my finite automaton rule 30. Some reason it is not printing out the correct pattern and I can not figure it out

    public class CA_1D2S
    {
    public CA_1D2S() {
    try {
    jbInit();
    } catch (Exception ex) {
    ex.printStackTrace();
    }
    }

    byte[][] DOUBLE_BUFFER;
    int CurRow = 0;
    int nxtRow = 1;
    int RowSize = 181;
    int cellStates = 2;
    byte[] rules = {0,1,1,1,1,0,0,0};


    public CA_1D2S(int RowSize)
    {
    DOUBLE_BUFFER = new byte[2][RowSize];
    Initialize();
    }

    private void Initialize()
    {
    CurRow = 0; nxtRow = 1;

    // Setting a variable to the length of my double buffer array
    int len = DOUBLE_BUFFER[0].length;


    for ( int i = 0; i < len; ++i)
    {
    // Initializing my DOUBlE_BUFFER to 0
    DOUBLE_BUFFER[0][i] = 0;
    DOUBLE_BUFFER[1][i] = 0;
    }

    // ** Middle bit ***
    DOUBLE_BUFFER[CurRow][(len/2)] = 1;
    }


    public void reset()
    {
    Initialize();
    }

    public int CellCount()
    {
    return DOUBLE_BUFFER[0].length;
    }

    public byte[] GetCurRow()
    {

    return DOUBLE_BUFFER[CurRow].clone();

    }

    public int GetRowSize()
    {
    return RowSize;
    }

    public void TimeStep()
    {

    for(int i=1; i < DOUBLE_BUFFER[0].length-1; i++)
    {
    DOUBLE_BUFFER[nxtRow][i] = rules[ Map(i)];

    //System.out.print(DOUBLE_BUFFER[CurRow][i]);

    CurRow = 1 - CurRow; nxtRow = 1 - nxtRow;


    }

    System.out.print("\n");

    }

    private int Map(int Pos)
    {
    int n = 0;
    for (int i = Pos-1; i <= Pos+1; ++i)
    {
    n *=2;
    n += DOUBLE_BUFFER[CurRow][i] % 2;

    }

    return n;
    }

    private void jbInit() throws Exception {
    }


    }


    class Test_CA
    {
    private int n = 50;

    public Test_CA()
    {
    CA_1D2S ca = new CA_1D2S(n);
    if (ca.GetRowSize()!= n)
    {
    System.out.print("ca.GetCutRow() !=50\n");
    return;
    }

    }


    }

  2. #2
    Join Date
    Apr 2010
    Posts
    11

    Re: rule 30 finite automaton

    Dear Sir: The program you had on there called SimpleModel has the wrong algorithm. It is plotting rule 222. Under the method NextGen you have this comment:

    // Set the array list element to an asterix when one or the
    // other neighbour is an asterix, but not both.

    Those are not the rules that you want. Rule 30 looks like this in binary:
    00011110

    You want to simulate this situation according to Mr. Wolfram.
    111 110 101 100 011 010 001 000 This is converted to the next row
    0 0 0 1 1 1 1 0 = 30



    You have to reflect that in your rectangle drawing method. Ex.

    for (int i=0; i<=80; i++) {
    if ((arlPrev.get(i) == ASTERIX) && (i > 0) && (i < 80)) {
    // byte 1
    if (arlPrev.get(i-1).equals(ASTERIX) && (arlPrev).get(i+1).equals(ASTERIX)) {
    arList.set(i, BLANKS);
    }
    // byte 2
    if (arlPrev.get(i-1).equals(ASTERIX) && (arlPrev.get(i+1)).equals(BLANKS)){
    arList.set(i,BLANKS);
    }
    // byte 5
    if (arlPrev.get(i-1).equals(BLANKS) && (arlPrev.get(i+1)).equals(ASTERIX)){
    arList.set(i,ASTERIX);
    }


    etc.

    After those changes it ought to work. At least I got it to. Good luck.

  3. #3
    Join Date
    Apr 2010
    Posts
    11

    Re: rule 30 finite automaton

    Dear Sir: Ignore a good part of what I had written. SimpleModel was one of my old programs, not yours! It's been a while since I worked with that stuff. I didn't recognize one of my programs. However the algorithm works and when I made changes for Rule 30, the random patterns pop up. There are probably other approaches, ie. bit pushing. I just used simple line by line processing of blanks and astericks in an ArrayList to build the next generation. Hope that wasn't too confusing! Good Luck!

  4. #4
    Join Date
    Apr 2010
    Posts
    9

    Re: rule 30 finite automaton

    Hey

    The only part that i need to implement is the actual mapping of the bits. I need to get the pattern to output. Can you show me how you coded it?

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured