Merge branch 'main' of https://gitarero.ecam.fr/guillaume.bonabau/OOP_F1_Project
This commit is contained in:
commit
dee5805c28
|
|
@ -37,7 +37,7 @@ public class Sheep extends Agent {
|
||||||
} else {
|
} else {
|
||||||
hunger++;
|
hunger++;
|
||||||
}
|
}
|
||||||
this.moveRandom(world);
|
this.moveRandom();
|
||||||
return hunger<10; //condition to be alive
|
return hunger<10; //condition to be alive
|
||||||
//if the sheep can reproduce it creates a new sheep in agents
|
//if the sheep can reproduce it creates a new sheep in agents
|
||||||
//if(canReproduce(neighbors, world)) {
|
//if(canReproduce(neighbors, world)) {
|
||||||
|
|
|
||||||
|
|
@ -70,7 +70,8 @@ public class Simulator extends Thread {
|
||||||
|
|
||||||
|
|
||||||
//Default rule : Survive always, birth never
|
//Default rule : Survive always, birth never
|
||||||
loadRule("ressources/Rule/conwayRule.json");
|
//loadRule("ressources/Rule/conwayRule.json");
|
||||||
|
loadRule("OOP_F1_Project/ressources/Rule/conwayRule.json");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -393,9 +394,28 @@ public class Simulator extends Thread {
|
||||||
* the simulated world in its present state
|
* the simulated world in its present state
|
||||||
*/
|
*/
|
||||||
public ArrayList<String> getSaveState() {
|
public ArrayList<String> getSaveState() {
|
||||||
//TODO : complete method with proper return
|
ArrayList<String> saveState = new ArrayList<>();
|
||||||
return null;
|
|
||||||
|
// Ensure height and width are properly initialized
|
||||||
|
int height = getHeight(); // Replace getHeight() with your method to get the height
|
||||||
|
int width = getWidth(); // Replace getWidth() with your method to get the width
|
||||||
|
|
||||||
|
for (int y = 0; y < height; y++) {
|
||||||
|
StringBuilder lineBuilder = new StringBuilder();
|
||||||
|
for (int x = 0; x < width; x++) {
|
||||||
|
lineBuilder.append(getCell(x, y));
|
||||||
|
if (x < width - 1) {
|
||||||
|
lineBuilder.append(";");
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
saveState.add(lineBuilder.toString());
|
||||||
|
}
|
||||||
|
return saveState;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param lines of file representing saved world state
|
* @param lines of file representing saved world state
|
||||||
|
|
|
||||||
|
|
@ -354,10 +354,11 @@ public class MyInterface extends JFrame {
|
||||||
String fileName = SelectFile();
|
String fileName = SelectFile();
|
||||||
if (fileName.length() > 0) {
|
if (fileName.length() > 0) {
|
||||||
ArrayList<String> content = mySimu.getSaveState();
|
ArrayList<String> content = mySimu.getSaveState();
|
||||||
writeFile(fileName, (String[]) content.toArray());
|
writeFile(fileName, content.toArray(new String[0]));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void clicSaveAgentsToFileButton() {
|
public void clicSaveAgentsToFileButton() {
|
||||||
String fileName=SelectFile();
|
String fileName=SelectFile();
|
||||||
if (fileName.length()>0) {
|
if (fileName.length()>0) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue