so i'm working on some project for my final semester. then, i got stuck at programming my AI....
P.S my game is about maze, there is player, AI, and FLAG.... the goal is to get to flag both player and AI is racing to reach the flag
P.S.S player, and AI detect the wall by looking for a color white as the path, black as the wall....
public void lariKeFlag (Flag finish){ //this should be the code for the AI to chase the flag. but here my code just "detect" the flag but the AI can't turn around a wall
double deltaX = getX()-finish.getX();
double deltaY = getY() - finish.getY();
World world = getWorld();
GreenfootImage background = world.getBackground();
if(Math.abs(deltaX) > Math.abs(deltaY)){
if(deltaX>0&&background.getColorAt(getX()-7,getY()).equals(white)){
setLocation(getX() - 1, getY());
}
else if (deltaX<0&&background.getColorAt(getX() + 7, getY()).equals(white)){
setLocation(getX() +1, getY());
}
}
else {
if (deltaY >0&&background.getColorAt(getX(), getY() + 7).equals(white)) {
setLocation(getX(), getY()-1);
}
else if (deltaY<0&&background.getColorAt(getX(), getY() - 4).equals(white)) {
setLocation(getX(), getY() +1);
}
}
}

