Merge branch 'master' of https://gitarero.ecam.fr/laure.bel/OOP_F3_Project.git
This commit is contained in:
commit
17c204a812
|
|
@ -10,20 +10,12 @@ public class Rules {
|
||||||
|
|
||||||
public Rules() {
|
public Rules() {
|
||||||
|
|
||||||
survivalRulesArray = new int[0];
|
//survivalRulesArray = new int[0];
|
||||||
birthRulesArray = new int[0];
|
//birthRulesArray = new int[0];
|
||||||
}
|
}
|
||||||
//initialize my arrays to empty
|
//initialize my arrays to empty
|
||||||
|
|
||||||
public int[] getBirthRulesArray() {
|
|
||||||
return this.birthRulesArray;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public int[] getSurvivalRulesArray() {
|
|
||||||
return this.survivalRulesArray;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public void loadRule(ArrayList<String> row) {
|
public void loadRule(ArrayList<String> row) {
|
||||||
String surviveRulesRow = row.get(0);
|
String surviveRulesRow = row.get(0);
|
||||||
|
|
@ -42,14 +34,14 @@ public class Rules {
|
||||||
|
|
||||||
}else {
|
}else {
|
||||||
for (int x = 0; x < surviveCells.length; x++) {
|
for (int x = 0; x < surviveCells.length; x++) {
|
||||||
String elem = surviveCells[x];
|
String eleme = surviveCells[x];
|
||||||
int value = Integer.parseInt(elem);
|
int value = Integer.parseInt(eleme);
|
||||||
survivalRulesArray[x] = value;
|
survivalRulesArray[x] = value;
|
||||||
}
|
}
|
||||||
//determines the number of alive neighboring cells needed to survive, and places them in the survivalRulesArray
|
//determines the number of alive neighboring cells needed to survive, and places them in the survivalRulesArray
|
||||||
for (int x = 0; x < birthCells.length; x++) {
|
for (int x = 0; x < birthCells.length; x++) {
|
||||||
String elem = birthCells[x];
|
String elemee = birthCells[x];
|
||||||
int value = Integer.parseInt(elem);
|
int value = Integer.parseInt(elemee);
|
||||||
birthRulesArray[x] = value;
|
birthRulesArray[x] = value;
|
||||||
}
|
}
|
||||||
//determines the number of alive neighboring cells needed to birth, and places them in the birthRules list
|
//determines the number of alive neighboring cells needed to birth, and places them in the birthRules list
|
||||||
|
|
@ -58,5 +50,15 @@ public class Rules {
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int[] getBirthRulesArray() {
|
||||||
|
return this.birthRulesArray;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public int[] getSurvivalRulesArray() {
|
||||||
|
return this.survivalRulesArray;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -36,7 +36,11 @@ public class Sheep extends Agent {
|
||||||
hunger++;
|
hunger++;
|
||||||
}
|
}
|
||||||
this.moveRandom();
|
this.moveRandom();
|
||||||
return hunger>10;
|
if (hunger<=10) {
|
||||||
|
return true;
|
||||||
|
}else {
|
||||||
|
return hunger>10;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void moveRandom() {
|
private void moveRandom() {
|
||||||
|
|
|
||||||
|
|
@ -16,8 +16,8 @@ public class Simulator extends Thread {
|
||||||
private MyInterface mjf;
|
private MyInterface mjf;
|
||||||
public Rules rules;
|
public Rules rules;
|
||||||
|
|
||||||
//private final int COL_NUM = 100;
|
private final int COL_NUM = 100;
|
||||||
//private final int LINE_NUM = 100;
|
private final int LINE_NUM = 100;
|
||||||
private final int LIFE_TYPE_NUM = 4;
|
private final int LIFE_TYPE_NUM = 4;
|
||||||
//Conway Radius : 1
|
//Conway Radius : 1
|
||||||
private final int LIFE_AREA_RADIUS = 1;
|
private final int LIFE_AREA_RADIUS = 1;
|
||||||
|
|
@ -66,11 +66,11 @@ public class Simulator extends Thread {
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getWidth() {
|
public int getWidth() {
|
||||||
return world.getWidth();
|
return this.getWidth();
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getHeight() {
|
public int getHeight() {
|
||||||
return world.getHeight();
|
return this.getHeight();
|
||||||
}
|
}
|
||||||
|
|
||||||
public World getWorld(){
|
public World getWorld(){
|
||||||
|
|
@ -158,28 +158,23 @@ public class Simulator extends Thread {
|
||||||
// in agent classes
|
// in agent classes
|
||||||
|
|
||||||
|
|
||||||
/*ArrayList<Agent> newAgents = new ArrayList<>();
|
ArrayList<Agent> newAgents = new ArrayList<>();
|
||||||
for(Agent agent : agents) {
|
for(Agent agent : agents) {
|
||||||
ArrayList<Agent> neighbors =
|
/*ArrayList<Agent> neighbors =this.getNeighboringAnimals(agent.getX(),agent.getY(),ANIMAL_AREA_RADIUS);}
|
||||||
this.getNeighboringAnimals(
|
*/
|
||||||
agent.getX(),
|
System.out.println("makeStep Called");
|
||||||
agent.getY(),
|
if(!agent.liveTurn(this.getNeighboringAnimals(agent.getX(),agent.getY(),ANIMAL_AREA_RADIUS),world)) {
|
||||||
ANIMAL_AREA_RADIUS);}
|
|
||||||
if(!agent.liveTurn(
|
|
||||||
neighbors,
|
|
||||||
this)) {
|
|
||||||
agents.remove(agent);
|
agents.remove(agent);
|
||||||
}*/
|
}
|
||||||
|
}
|
||||||
|
|
||||||
int[][] nextWorld = new int[getWidth()][getHeight()];
|
/*int[][] nextWorld = new int[getWidth()][getHeight()];
|
||||||
|
|
||||||
for (int x = 0; x < getWidth(); x++) {
|
for (int x = 0; x < getWidth(); x++) {
|
||||||
for (int y = 0; y < getHeight(); y++) {
|
for (int y = 0; y < getHeight(); y++) {
|
||||||
int aliveNeighbors = countAliveNeighbors(x, y);
|
int aliveNeighbors = countAliveNeighbors(x, y);
|
||||||
if (world.getCell(x, y) == 1) {
|
if (world.getCell(x, y) == 1) {
|
||||||
nextWorld[x][y] = 1;
|
nextWorld[x][y] = survives(aliveNeighbors) ? 1 : 0;
|
||||||
//survives(aliveNeighbors) ? 1 : 0;
|
|
||||||
} else {
|
} else {
|
||||||
nextWorld[x][y] = bornes(aliveNeighbors) ? 1 : 0;
|
nextWorld[x][y] = bornes(aliveNeighbors) ? 1 : 0;
|
||||||
}
|
}
|
||||||
|
|
@ -189,7 +184,7 @@ public class Simulator extends Thread {
|
||||||
world.setWorld(nextWorld, getWidth(), getHeight());
|
world.setWorld(nextWorld, getWidth(), getHeight());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
//then evolution of the field
|
//then evolution of the field
|
||||||
|
|
||||||
|
|
@ -210,10 +205,7 @@ public class Simulator extends Thread {
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* leave this as is
|
* leave this as is
|
||||||
|
|
|
||||||
|
|
@ -3,9 +3,9 @@ package backend;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
|
||||||
public class World {
|
public class World {
|
||||||
|
Simulator simulator;
|
||||||
private int width;
|
private int width = simulator.getWidth();
|
||||||
private int height;
|
private int height = simulator.getHeight();
|
||||||
private int[][] world;
|
private int[][] world;
|
||||||
|
|
||||||
public World(int width, int height) {
|
public World(int width, int height) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue