wolf and movement of agent updated

This commit is contained in:
Laure BEL 2024-05-30 12:44:52 +02:00
parent 0cfe8fc9b5
commit 7c178df648
2 changed files with 10 additions and 2 deletions

View File

@ -32,6 +32,7 @@ public class Sheep extends Agent {
public boolean liveTurn(ArrayList<Agent> neighbors, Simulator world) {
if(world.getCell(x, y)==1) {
world.setCell(x, y, 0);
hunger=hunger-1;
} else {
hunger++;
}
@ -39,7 +40,7 @@ public class Sheep extends Agent {
if (hunger<=10) {
return true;
}else {
return hunger>10;
return false;
}
}

View File

@ -31,13 +31,20 @@ public class Wolf extends Agent {
if(world.typeAnimals(x,y, neighbors)== "Sheep") {
Sheep sheep = new Sheep(x,y) ;
world.getAnimals().remove(sheep);
hunger=hunger-1;
}else {
hunger++;
}
} else {
hunger++;
}
this.moveRandom();
return hunger>10;
if (hunger<=10) {
return true;
}else {
return false;
}
}
private void moveRandom() {