This commit is contained in:
Balthazar SQUINABOL 2024-05-29 17:07:30 +02:00
parent e97f4e3861
commit 1b432953a1
1 changed files with 8 additions and 20 deletions

View File

@ -12,7 +12,6 @@ public class Sheep extends Agent {
int hunger;
Random rand;
Simulator simulator;
Sheep(int x,int y){
//first we call the constructor of the superClass(Animal)
@ -25,37 +24,24 @@ public class Sheep extends Agent {
rand = new Random();
}
boolean loopingBorder = simulator.isLoopingBorder();
int width = simulator.getWidth();
int height = simulator.getHeight();
/**
* action of the animal
* it can interact with the cells or with other animals
* as you wish
*/
public boolean liveTurn(ArrayList<Agent> neighbors, Simulator word) {
//we check if the sheep is on the border of the world
//If loopingBorder == true, the world is a torus
//If loopingBorder == false, the world is a square and the sheep can't go out of the world
if(simulator.getCell(x, y)==1) {
simulator.setCell(x, y, 0);
hunger = hunger--;
public boolean liveTurn(ArrayList<Agent> neighbors, Simulator world) {
if(world.getCell(x, y)==1) {
world.setCell(x, y, 0);
} else {
hunger++;
}
this.moveRandom(world);
this.moveRandom();
return hunger<10; //condition to be alive
}
private void moveRandom() {
//check if the sheep is on the border of the world
//If loopingBorder == true, the world is a torus
int direction = rand.nextInt(4);
if(direction == 0) {
x+=1;
@ -70,4 +56,6 @@ public class Sheep extends Agent {
y-=1;
}
}
}
}