From b8bb0ad9e70ce375cbea67b1c6d5830e061fc5b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9Cdorian=2Eveloso=E2=80=9D?= Date: Tue, 28 May 2024 22:52:56 +0200 Subject: [PATCH] corrections --- Readme | 0 Readme.md | 71 ++++++++++++++++++++++++++++++++++++++ src/backend/Simulator.java | 25 ++++++-------- src/backend/World.java | 6 +++- 4 files changed, 86 insertions(+), 16 deletions(-) delete mode 100644 Readme create mode 100644 Readme.md diff --git a/Readme b/Readme deleted file mode 100644 index e69de29..0000000 diff --git a/Readme.md b/Readme.md new file mode 100644 index 0000000..b16b7bc --- /dev/null +++ b/Readme.md @@ -0,0 +1,71 @@ +# Experimental Game of Life Simulator + +## Overview + +This project explores various extensions of Conway's Game of Life, including custom rules, agent interactions, and mixed populations. The focus is on creating interesting patterns and behaviors through an interactive GUI. + +## Features + +- **Standard and Custom Game of Life Rules**: Supports Conway's original rules and custom rule sets. +- **Mixed Populations**: Includes Sheep and Wolf agents with specific behaviors and interactions. +- **Interactive GUI**: Allows users to start, pause, stop the simulation, and edit the world state in real-time. +- **Speed Control**: Adjust the simulation speed with a slider. +- **Border Toggle**: Switch between looping and closed borders. +- **Random Initialization**: Fill the world with a random state using a probability slider. +- **File Operations**: Save and load world states, agents, and rules from files. + +## Getting Started + +## GUI Instructions + +### Buttons + +- **Start/Pause**: Starts or pauses the simulation. If the world is not loaded, a default world is created. +- **Stop**: Stops the simulation and resets the world to its default state. +- **Toggle Border**: Switches between looping and closed borders. +- **Random**: Fills the world with randomly living or dead cells based on the probability set by the slider. +- **Save File**: Saves the current world state, agents, and rules to a file. +- **Load File**: Loads a world state, agents, and rules from a file. + +### Interacting with the World + +- Click on cells to toggle their state. This allows for creating or editing the starting state of the world. + +## File Format + +### World State + +- Each line represents a row in the grid. +- Cells in a row are separated by semicolons (`;`). + +Example: +``` +0;0;1;0;0 +0;1;1;1;0 +0;0;1;0;0 +0;0;0;0;0 +0;0;0;0;0 +``` + +### Agents and Rules + +- **Agents**: Coordinates and types of agents are saved in a structured format. +- **Rules**: Custom rules are saved as lists of birth and survival conditions. + +## Extending the Project + +### Custom Rules + +- Modify the rules to implement different variations of the Game of Life. +- Examples: HighLife, aging cells, predator-prey models. + +### Agents + +- Implement additional agent types and behaviors. +- Example: A Wolf that hunts Sheep and reproduces. + +## Example Patterns + +- **Glider**: A small pattern that moves across the grid. +- **R-Pentomino**: A pattern that evolves in complex ways. +- **Gosper Glider Gun**: A pattern that produces a stream of gliders diff --git a/src/backend/Simulator.java b/src/backend/Simulator.java index 806e024..2fc6888 100644 --- a/src/backend/Simulator.java +++ b/src/backend/Simulator.java @@ -8,15 +8,13 @@ public class Simulator extends Thread { private MyInterface mjf; - private final int COL_NUM = 50; - private final int LINE_NUM = 50; + 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; //Animal Neighborhood Radius : 5 private final int ANIMAL_AREA_RADIUS = 3; - private ArrayList fieldSurviveValues; - private ArrayList fieldBirthValues; private ArrayList agents; ArrayList> rule = new ArrayList<>(); @@ -40,8 +38,8 @@ public class Simulator extends Thread { clickActionFlag=false; agents = new ArrayList(); - fieldBirthValues = new ArrayList(); - fieldSurviveValues = new ArrayList(); + birthConditions = new ArrayList(); + survivalConditions = new ArrayList(); // Normal Game of Life rules @@ -53,14 +51,6 @@ public class Simulator extends Thread { rule.add(survivalConditions); world = new World(COL_NUM, LINE_NUM, rule); - - - - //Default rule : Survive always, birth never - for(int i =0; i<9; i++) { - fieldSurviveValues.add(i); - } - } public int getWidth() { @@ -336,6 +326,7 @@ public class Simulator extends Thread { public void toggleLoopingBorder() { loopingBorder = !loopingBorder; + world.setLoopingBorders(loopingBorder); } public void setLoopDelay(int delay) { @@ -367,7 +358,9 @@ public class Simulator extends Thread { System.out.println("empty rule file"); return; } - rule.clear(); + rule.get(0).clear(); + rule.get(1).clear(); + String surviveLine = lines.get(0); String birthLine = lines.get(1); @@ -385,6 +378,8 @@ public class Simulator extends Thread { //TODO : add value to possible birth values rule.get(1).add(value); } + + world.setRules(rule); } public ArrayList getAgentsSave() { diff --git a/src/backend/World.java b/src/backend/World.java index 4fa0161..f622e81 100644 --- a/src/backend/World.java +++ b/src/backend/World.java @@ -7,7 +7,7 @@ public class World { private Grid grid; private int width; private int height; - private boolean loopingBorder; + private boolean loopingBorder = false; private ArrayList> rule; public World(int sizeX, int sizeY, ArrayList> _rule) { @@ -110,6 +110,10 @@ public class World { grid.getCell(x, y).setState(val); } + public void setRules(ArrayList> _rule) { + rule = _rule;; + } + public void setLoopingBorders(boolean loop) { loopingBorder = loop; }