This commit is contained in:
Laure BEL 2024-05-29 18:07:23 +02:00
parent 73662f1c0c
commit 7acff3e638
3 changed files with 20 additions and 17 deletions

View File

@ -36,7 +36,11 @@ public class Sheep extends Agent {
hunger++;
}
this.moveRandom();
return hunger>10;
if (hunger<=10) {
return true;
}else {
return hunger>10;
}
}
private void moveRandom() {

View File

@ -16,8 +16,8 @@ public class Simulator extends Thread {
private MyInterface mjf;
public Rules rules;
//private final int COL_NUM = 100;
//private final int LINE_NUM = 100;
private final int COL_NUM = 100;
private final int LINE_NUM = 100;
private final int LIFE_TYPE_NUM = 4;
//Conway Radius : 1
private final int LIFE_AREA_RADIUS = 1;
@ -66,11 +66,11 @@ public class Simulator extends Thread {
}
public int getWidth() {
return world.getWidth();
return this.getWidth();
}
public int getHeight() {
return world.getHeight();
return this.getHeight();
}
public World getActualWorld(){
@ -160,13 +160,15 @@ public class Simulator extends Thread {
ArrayList<Agent> newAgents = new ArrayList<>();
for(Agent agent : agents) {
ArrayList<Agent> neighbors =this.getNeighboringAnimals(agent.getX(),agent.getY(),ANIMAL_AREA_RADIUS);}
if(!agent.liveTurn(neighbors,this)) {
/*ArrayList<Agent> neighbors =this.getNeighboringAnimals(agent.getX(),agent.getY(),ANIMAL_AREA_RADIUS);}
*/
System.out.println("makeStep Called");
if(!agent.liveTurn(this.getNeighboringAnimals(agent.getX(),agent.getY(),ANIMAL_AREA_RADIUS),world)) {
agents.remove(agent);
}
}
int[][] nextWorld = new int[getWidth()][getHeight()];
/*int[][] nextWorld = new int[getWidth()][getHeight()];
for (int x = 0; x < getWidth(); x++) {
for (int y = 0; y < getHeight(); y++) {
@ -182,7 +184,7 @@ public class Simulator extends Thread {
world.setWorld(nextWorld, getWidth(), getHeight());
}
*/
//then evolution of the field
@ -203,10 +205,7 @@ public class Simulator extends Thread {
*/
}
/*
* leave this as is

View File

@ -3,9 +3,9 @@ package backend;
import java.util.Random;
public class World {
private int width;
private int height;
Simulator simulator;
private int width = simulator.getWidth();
private int height = simulator.getHeight();
private int[][] world;
public World(int width, int height) {