Hello!
Im creating an AI for the Wombat scenario, the part Im currently stuck at is detecting a wall before the wombat would move. GetIntersectingObjects did not lead me to victory, the wombat once steps on a wall, it stays there since GetIntersectingObjects is returning true. My code below.
act() calls the actual movement, if the way is free, it should move.
This one just spins the wombat with randomDirection(), and moves it by one block.
randomDirection() makes a random turn on the actor.
IsWombatOnWall() method, this one is making the wombat stuck on a wall.
The extra I got in the Wombat scenario is a Wall class, its an empty one.
Is there a way to detect an object before moving the wombat? Or can isTouching() be modified to return the direction of the Wall.class, where its positioned by the wombat?
public void act()
{
if(foundLeaf()) {
eatLeaf();
}
else if(canMove()){
smarterMove();
if (IsWombatOnWall()){
smarterMove();
}
}
else {
randomDirection();
}
}public void smarterMove()
{
randomDirection();
move();
}public void randomDirection()
{
int i = (int )(Math.random() * 4 + 1);
direction = i;
switch(direction){
case 1:
setDirection(EAST);
break;
case 2:
setDirection(NORTH);
break;
case 3:
setDirection(WEST);
break;
case 4:
setDirection(SOUTH);
break;
}
}public boolean IsWombatOnWall(){
if (!getIntersectingObjects(Wall.class).isEmpty()){
return true;
}
else
{
return false;
}
}
