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

View File

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