corrections

This commit is contained in:
Dorian VELOSO 2024-05-28 22:52:56 +02:00
parent 27d720dde9
commit b8bb0ad9e7
4 changed files with 86 additions and 16 deletions

0
Readme
View File

71
Readme.md Normal file
View File

@ -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

View File

@ -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<Integer> fieldSurviveValues;
private ArrayList<Integer> fieldBirthValues;
private ArrayList<Agent> agents;
ArrayList<ArrayList<Integer>> rule = new ArrayList<>();
@ -40,8 +38,8 @@ public class Simulator extends Thread {
clickActionFlag=false;
agents = new ArrayList<Agent>();
fieldBirthValues = new ArrayList<Integer>();
fieldSurviveValues = new ArrayList<Integer>();
birthConditions = new ArrayList<Integer>();
survivalConditions = new ArrayList<Integer>();
// 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<String> getAgentsSave() {

View File

@ -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<ArrayList<Integer>> rule;
public World(int sizeX, int sizeY, ArrayList<ArrayList<Integer>> _rule) {
@ -110,6 +110,10 @@ public class World {
grid.getCell(x, y).setState(val);
}
public void setRules(ArrayList<ArrayList<Integer>> _rule) {
rule = _rule;;
}
public void setLoopingBorders(boolean loop) {
loopingBorder = loop;
}