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 distanceToClosetFrontO:confused:bject();
:confused:
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();
}
}
Re: not sure where to go with this code, need to make it into an AI code
Quote:
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?
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?
Re: not sure where to go with this code, need to make it into an AI code
Quote:
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?
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
Re: not sure where to go with this code, need to make it into an AI code
Quote:
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"?