This commit is contained in:
Guillaume BONABAU 2024-05-29 20:49:02 +02:00
commit dee5805c28
3 changed files with 28 additions and 7 deletions

View File

@ -37,7 +37,7 @@ public class Sheep extends Agent {
} else {
hunger++;
}
this.moveRandom(world);
this.moveRandom();
return hunger<10; //condition to be alive
//if the sheep can reproduce it creates a new sheep in agents
//if(canReproduce(neighbors, world)) {

View File

@ -70,7 +70,8 @@ public class Simulator extends Thread {
//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
*/
public ArrayList<String> getSaveState() {
//TODO : complete method with proper return
return null;
ArrayList<String> saveState = new ArrayList<>();
// 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

View File

@ -351,12 +351,13 @@ public class MyInterface extends JFrame {
public void clicSaveToFileButton() {
String fileName=SelectFile();
if (fileName.length()>0) {
String fileName = SelectFile();
if (fileName.length() > 0) {
ArrayList<String> content = mySimu.getSaveState();
writeFile(fileName, (String[]) content.toArray());
writeFile(fileName, content.toArray(new String[0]));
}
}
public void clicSaveAgentsToFileButton() {
String fileName=SelectFile();