Merge branch 'main' of https://gitarero.ecam.fr/guillaume.bonabau/OOP_F1_Project into dev_lch
This commit is contained in:
commit
e501b7feb6
|
|
@ -38,7 +38,7 @@ public class Sheep extends Agent {
|
|||
hunger++;
|
||||
}
|
||||
this.moveRandom();
|
||||
return hunger>10;
|
||||
return hunger<10; //condition to be alive
|
||||
}
|
||||
|
||||
private void moveRandom() {
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ public class Simulator extends Thread {
|
|||
private boolean stopFlag;
|
||||
private boolean pauseFlag;
|
||||
private boolean loopingBorder;
|
||||
private boolean clickActionFlag;
|
||||
private int clickActionFlag;
|
||||
private int loopDelay = 150;
|
||||
|
||||
//TODO : add missing attribute(s)
|
||||
|
|
@ -40,7 +40,9 @@ public class Simulator extends Thread {
|
|||
private int height;
|
||||
private boolean enableLogs;
|
||||
private Table table;
|
||||
private boolean cellDensityToggle;
|
||||
private int lowestCellValue = 0;
|
||||
private int highestCellValue = 0;
|
||||
private int ruleArrayListLength = 0;
|
||||
|
||||
//Rules Arraylists
|
||||
private ArrayList<Rule> ruleArrayList = new ArrayList<Rule>();
|
||||
|
|
@ -52,7 +54,7 @@ public class Simulator extends Thread {
|
|||
stopFlag=false;
|
||||
pauseFlag=false;
|
||||
loopingBorder=false;
|
||||
clickActionFlag=false;
|
||||
clickActionFlag=1; //1 for cell, 2 for sheep, 3 for wolf
|
||||
|
||||
agents = new ArrayList<Agent>();
|
||||
fieldBirthValues = new ArrayList<Integer>();
|
||||
|
|
@ -64,12 +66,11 @@ public class Simulator extends Thread {
|
|||
this.height=LINE_NUM;
|
||||
enableLogs = true; // for debugging purposes
|
||||
table = new Table(height, width, this);
|
||||
cellDensityToggle=true;
|
||||
|
||||
|
||||
|
||||
//Default rule : Survive always, birth never
|
||||
loadRule("ressources\\Rule\\conwayRule.json");
|
||||
loadRule("ressources/Rule/conwayRule.json");
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -124,17 +125,19 @@ public class Simulator extends Thread {
|
|||
// only modify if sure of what you do
|
||||
// to modify agent behavior, see liveTurn method
|
||||
// in agent classes
|
||||
for(Agent agent : agents) {
|
||||
/*for(Agent agent : agents) {
|
||||
ArrayList<Agent> neighbors =
|
||||
this.getNeighboringAnimals(
|
||||
agent.getX(),
|
||||
agent.getY(),
|
||||
ANIMAL_AREA_RADIUS);
|
||||
if(!agent.liveTurn(
|
||||
neighbors,
|
||||
this)) {
|
||||
this.getNeighboringAnimals(agent.getX(), agent.getY(), ANIMAL_AREA_RADIUS);
|
||||
if(!agent.liveTurn(neighbors,this)) {
|
||||
agents.remove(agent);
|
||||
}
|
||||
}*/
|
||||
|
||||
for(int i=0; i<agents.size(); i++){
|
||||
ArrayList<Agent> neighbors = this.getNeighboringAnimals(agents.get(i).getX(), agents.get(i).getY(), ANIMAL_AREA_RADIUS);
|
||||
if(!agents.get(i).liveTurn(neighbors,this)) {
|
||||
agents.remove(i);
|
||||
}
|
||||
}
|
||||
//then evolution of the field
|
||||
//TODO-INPROGRESS : apply game rule to all cells of the field
|
||||
|
|
@ -186,32 +189,42 @@ public class Simulator extends Thread {
|
|||
* method called when clicking on a cell in the interface
|
||||
*/
|
||||
public void clickCell(int x, int y) {
|
||||
if (clickActionFlag) {
|
||||
//ruleArrayList
|
||||
if (ruleArrayListLength == 0 && highestCellValue == 0){
|
||||
|
||||
int ruleArrayListLength = ruleArrayList.size();
|
||||
|
||||
for (int i = 0; i < ruleArrayListLength; i++) {
|
||||
if (ruleArrayList.get(i).getValue() > highestCellValue) {
|
||||
highestCellValue = ruleArrayList.get(i).getValue();
|
||||
}
|
||||
}
|
||||
int lowestCellValue = 0;
|
||||
|
||||
for (int i = 0; i < ruleArrayListLength; i++) {
|
||||
if (ruleArrayList.get(i).getValue() < lowestCellValue) {
|
||||
lowestCellValue = ruleArrayList.get(i).getValue();
|
||||
}
|
||||
}
|
||||
|
||||
System.out.println("ruleArrayListLength: " + ruleArrayListLength);
|
||||
System.out.println("highestCellValue: " + highestCellValue);
|
||||
System.out.println("lowestCellValue: " + lowestCellValue);
|
||||
}
|
||||
|
||||
int currentCellValue = getCell(x, y);
|
||||
//TODO : find highest value in ruleArrayList
|
||||
int newCellValue = 0;
|
||||
if(cellDensityToggle) {
|
||||
if (currentCellValue <6) {
|
||||
if(clickActionFlag == 1) { //cell
|
||||
if (currentCellValue != highestCellValue) {
|
||||
newCellValue = currentCellValue +1;
|
||||
} else {
|
||||
newCellValue=-1;
|
||||
}
|
||||
} else {
|
||||
if (currentCellValue == 0) {
|
||||
newCellValue = 1;
|
||||
} else {
|
||||
newCellValue = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (enableLogs) {
|
||||
System.out.println("clickCell Called, cell :" + x + "," + y + " is now" + newCellValue + "");
|
||||
}
|
||||
|
||||
this.setCell(x, y, newCellValue);
|
||||
|
||||
|
||||
}
|
||||
else {
|
||||
newCellValue = lowestCellValue;
|
||||
}
|
||||
this.setCell(x, y, newCellValue);
|
||||
}
|
||||
else if(clickActionFlag == 2) { //sheep
|
||||
int i=0;
|
||||
Agent agent = new Sheep(x,y);
|
||||
|
||||
|
|
@ -248,7 +261,13 @@ public class Simulator extends Thread {
|
|||
System.out.println("clickAgent Called, Agent created at: " + x + "," + y + "");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
else if(clickActionFlag == 3) { //wolf
|
||||
//Make agent sheep/wolf
|
||||
return;
|
||||
}
|
||||
if (enableLogs) {
|
||||
System.out.println("clickCell Called, cell :" + x + "," + y + " is now" + newCellValue + "");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -423,13 +442,13 @@ public class Simulator extends Thread {
|
|||
|
||||
public void toggleClickAction() {
|
||||
//TODO-COMPLETE : complete method
|
||||
clickActionFlag = !clickActionFlag;
|
||||
if (enableLogs) {
|
||||
if (clickActionFlag) {
|
||||
System.out.println("toggleClickAction called, set clickActionFlag to true");
|
||||
if (clickActionFlag != 3) {
|
||||
clickActionFlag++;
|
||||
} else {
|
||||
System.out.println("toggleClickAction called, set clickActionFlag to false");
|
||||
clickActionFlag = 1;
|
||||
}
|
||||
if (enableLogs) {
|
||||
System.out.println("toggleClickAction called, set clickActionFlag to : " + clickActionFlag);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -472,6 +491,9 @@ public class Simulator extends Thread {
|
|||
}
|
||||
//DEBUG
|
||||
//printRules(ruleArrayList);
|
||||
lowestCellValue = 0;
|
||||
highestCellValue = 0;
|
||||
ruleArrayListLength = 0;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
|
|
@ -578,22 +600,19 @@ public class Simulator extends Thread {
|
|||
* @return String representation of click action
|
||||
*/
|
||||
public String clickActionName() {
|
||||
// TODO-COMPLETE : initially return "sheep" or "cell"
|
||||
// depending on clickActionFlag
|
||||
if (clickActionFlag){
|
||||
if (clickActionFlag == 1){
|
||||
return "cell";
|
||||
}
|
||||
else {
|
||||
else if (clickActionFlag == 2){
|
||||
return "sheep";
|
||||
}
|
||||
else if (clickActionFlag == 3){
|
||||
return "wolf";
|
||||
}
|
||||
else {
|
||||
return "error";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//debug print the list of rules
|
||||
public void printRules(ArrayList<Rule> ruleArrayList) {
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ public class Table {
|
|||
private ArrayList<ArrayList<Cell>> table;
|
||||
private Simulator simulator;
|
||||
|
||||
//TODO-INPROGRESS : create constructor
|
||||
//TODO-COMPLETE : create constructor
|
||||
public Table(int height, int width, Simulator tempSimulator) {
|
||||
this.height = height;
|
||||
this.width = width;
|
||||
|
|
|
|||
|
|
@ -210,6 +210,8 @@ public class MyInterface extends JFrame {
|
|||
mySimu = new Simulator(this);
|
||||
panelDraw.setSimu(mySimu);
|
||||
panelDraw.repaint();
|
||||
randSlider.setValue(50);
|
||||
speedSlider.setValue(30);
|
||||
}
|
||||
|
||||
public void setStepBanner(String s) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue