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 6 of 6

Thread: not sure where to go with this code, need to make it into an AI code

  1. #1
    Junior Member
    Join Date
    Nov 2011
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default not sure where to go with this code, need to make it into an AI code

    not sure how to turn this into a AI class. i have been trying to use int distanceToClosetFrontObject();



    public class RandomMower extends Mower
    {
    private int state=0;

    /**
    * Act - do whatever the AIMower wants to do. This method is called whenever
    * the 'Act' or 'Run' button gets pressed in the environment.
    */
    public void act()
    {
    switch (state)
    {
    case 0:
    throttleUp();
    state=1;
    break;
    case 1:
    if (bumpSensor()==true)
    {
    turnLeft(15);
    }
    else
    {
    switch (Greenfoot.getRandomNumber(5))
    {
    case 0:
    turnLeft(Greenfoot.getRandomNumber(2)*15);
    break;
    case 1:
    turnRight(Greenfoot.getRandomNumber(2)*15);
    break;
    }
    }
    state=1;
    break;
    }

    // Call the Mower.act() method
    super.act();
    }

    }


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    18,619
    Thanks
    45
    Thanked 1,958 Times in 1,932 Posts

    Default Re: not sure where to go with this code, need to make it into an AI code

    how to turn this into a AI class
    Can you define what an AI class is?
    How does it differ from the class that you show?

  3. #3
    Junior Member
    Join Date
    Nov 2011
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: not sure where to go with this code, need to make it into an AI code

    this is random. could i use a loop? one that would cause me to turn 90 degrees every time i hit something?

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    18,619
    Thanks
    45
    Thanked 1,958 Times in 1,932 Posts

    Default Re: not sure where to go with this code, need to make it into an AI code

    cause me to turn 90 degrees every time i hit something
    You need to explain the problem in programming terms. I don't understand your question.
    Is there a value that you want to change when an event happens?

  5. #5
    Junior Member
    Join Date
    Nov 2011
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: not sure where to go with this code, need to make it into an AI code

    i have a world that is a rectangle, there are objects in that world that move and some dont. i have this class called mower, this mower needs to cut the worlds lawn. all of the code for this is already made. all i need to do is write the code for the mower. all i want to do is to have it move by itself around the world but when it come into contact with an object or hits the edge of the world i would like it to turn 90 degrees. do i used the checkBumpSensor(), if true, turn(90). ? if i am still not making sense please let me know

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    18,619
    Thanks
    45
    Thanked 1,958 Times in 1,932 Posts

    Default Re: not sure where to go with this code, need to make it into an AI code

    when it come into contact with an object or hits the edge of the world i would like it to turn 90 degrees
    How do you detect it coming into contact? Is there an event or do you test the locations of it vs the object and/or the bounds?
    What determines what direction it faces? Is that information in a variable?
    What are the range of values for that variable? How much would you change the value of that variable to "turn 90 degrees"?

Similar Threads

  1. How to make this code even simpler
    By blakmaze in forum What's Wrong With My Code?
    Replies: 1
    Last Post: October 30th, 2011, 03:00 PM
  2. How to make code more efficient?
    By Apocalypse in forum Java Theory & Questions
    Replies: 2
    Last Post: October 21st, 2011, 09:07 AM
  3. need help to make my code flexible.
    By sagar474 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: September 29th, 2011, 12:11 PM
  4. How to make HyperLink in java code?
    By abhiM in forum Java Theory & Questions
    Replies: 1
    Last Post: August 24th, 2011, 07:16 AM
  5. Make my code follow MVC
    By alpvii in forum What's Wrong With My Code?
    Replies: 6
    Last Post: November 29th, 2010, 06:48 AM