Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 5 of 5

Thread: Creating Langton's Ant and I need serious help with it (it's a block that moves around on a grid changing the symbol at each index)

  1. #1
    Junior Member
    Join Date
    Mar 2013
    Posts
    20
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Question Creating Langton's Ant and I need serious help with it (it's a block that moves around on a grid changing the symbol at each index)

    In my code there are multiple packages and methods but I will try to keep it as simple as possible.

    The grid and ant look like this:

    // prints ant and board
    System.out.print("+");
    for (int j = 0; j < board.getWidth(); ++j) {
    System.out.print("-");
    }
    System.out.println("+");

    for (int i = 0; i < board.getHeight(); ++i) {
    System.out.print("|");
    for (int j = 0; j < board.getWidth(); ++j) {
    if (i == ant.getIPos() && j == ant.getJPos()) {
    switch (ant.getDirection()) {
    case NORTH:
    System.out.print("^");
    break;
    case SOUTH:
    System.out.print("V");
    break;
    case EAST:
    System.out.print(">");
    break;
    case WEST:
    System.out.print("<");
    break;
    }
    } else {
    if (board.isWhite(i, j)) {
    System.out.print(" ");
    } else {
    System.out.print("*");
    }
    }
    }
    System.out.println("|");
    }

    System.out.print("+");
    for (int j = 0; j < board.getWidth(); ++j) {
    System.out.print("-");
    }
    System.out.println("+");

    I am using a class called execute step which makes the ant move in a certain direction. There is also a direction class called enum direction{ NORTH SOUTH EAST WEST}. Basically I want to know how to get the ant moving.I know that not many of you will understand this because I'm mainly appealing to those who have done the same thing before unless you want to challenge yourself. But please ask me if you want more information on the code, of course I can't post all of it due to it being in multiple packages.


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    21,101
    Thanks
    52
    Thanked 2,285 Times in 2,256 Posts

    Default Re: Creating Langton's Ant and I need serious help with it (it's a block that moves around on a grid changing the symbol at each index)

    Please edit your post and wrap your code with code tags:
    [code=java]
    <YOUR CODE HERE>
    [/code]
    to get highlighting and preserve formatting.

    how to get the ant moving.
    Can you explain what "moving" means and how the program "moves" the ant?

    How is the ant's location determined? How does it change its location?
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Mar 2013
    Posts
    20
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: Creating Langton's Ant and I need serious help with it (it's a block that moves around on a grid changing the symbol at each index)

    sorry for the lateness:
    Essentially by ant moving I mean I want to shift a unique block to another index based on the symbol at that the index (ie. if it lands on a symbol * it means it should change the symbol to a blank space and turn left OR if it lands on a blank space it should turn it into * and turn right. It is quite complicated I know). If you want a better explanation you can look up Langton's Ant however I think my explanation of what it does is more than satisfactory in terms of what the code should do.
    How is the ant's location...change its location..?
    I can't determine the ant's location unfortunately (it is beyond what I can do but it would solve a lot of the problems) as I am kind of going out on a limb here.

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    21,101
    Thanks
    52
    Thanked 2,285 Times in 2,256 Posts

    Default Re: Creating Langton's Ant and I need serious help with it (it's a block that moves around on a grid changing the symbol at each index)

    Is a "move" a change in the row, column values for the ant? If the ant is at a certain r,c location, what determines the next r,c location it is going to move to?
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Junior Member
    Join Date
    Mar 2013
    Posts
    20
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: Creating Langton's Ant and I need serious help with it (it's a block that moves around on a grid changing the symbol at each index)

    Don't worry about it, it's a lost cause.

Similar Threads

  1. Tic-Tac-Toe Invalid Moves
    By XP360 in forum What's Wrong With My Code?
    Replies: 6
    Last Post: April 11th, 2013, 10:33 AM
  2. Creating and Using a Heap. Index out of Bounds
    By yooste89 in forum What's Wrong With My Code?
    Replies: 4
    Last Post: May 9th, 2012, 02:37 AM
  3. Creating Block cipher without the use of inbuilt java funcs
    By fortune2k in forum Algorithms & Recursion
    Replies: 0
    Last Post: November 15th, 2010, 08:43 AM
  4. How to represent a chain of moves?
    By maikeru in forum Collections and Generics
    Replies: 0
    Last Post: December 31st, 2009, 12:24 AM
  5. Method for legal moves in connect four.
    By mandar9589 in forum Algorithms & Recursion
    Replies: 3
    Last Post: December 27th, 2009, 04:28 PM

Tags for this Thread