Initial Version of Game
This commit is contained in:
parent
95f33b5f12
commit
e7eb15e430
|
|
@ -0,0 +1,53 @@
|
||||||
|
!SESSION 2024-04-10 15:05:50.176 -----------------------------------------------
|
||||||
|
eclipse.buildId=4.22.0.I20211124-1800
|
||||||
|
java.version=16.0.1
|
||||||
|
java.vendor=Oracle Corporation
|
||||||
|
BootLoader constants: OS=win32, ARCH=x86_64, WS=win32, NL=en_US
|
||||||
|
Framework arguments: -product org.eclipse.epp.package.java.product
|
||||||
|
Command-line arguments: -os win32 -ws win32 -arch x86_64 -product org.eclipse.epp.package.java.product
|
||||||
|
|
||||||
|
!ENTRY org.eclipse.jface 2 0 2024-04-10 15:06:13.933
|
||||||
|
!MESSAGE Keybinding conflicts occurred. They may interfere with normal accelerator operation.
|
||||||
|
!SUBENTRY 1 org.eclipse.jface 2 0 2024-04-10 15:06:13.933
|
||||||
|
!MESSAGE A conflict occurred for CTRL+SHIFT+T:
|
||||||
|
Binding(CTRL+SHIFT+T,
|
||||||
|
ParameterizedCommand(Command(org.eclipse.jdt.ui.navigate.open.type,Open Type,
|
||||||
|
Open a type in a Java editor,
|
||||||
|
Category(org.eclipse.ui.category.navigate,Navigate,null,true),
|
||||||
|
org.eclipse.ui.internal.WorkbenchHandlerServiceHandler@1b7a4930,
|
||||||
|
,,true),null),
|
||||||
|
org.eclipse.ui.defaultAcceleratorConfiguration,
|
||||||
|
org.eclipse.ui.contexts.window,,,system)
|
||||||
|
Binding(CTRL+SHIFT+T,
|
||||||
|
ParameterizedCommand(Command(org.eclipse.lsp4e.symbolinworkspace,Go to Symbol in Workspace,
|
||||||
|
,
|
||||||
|
Category(org.eclipse.lsp4e.category,Language Servers,null,true),
|
||||||
|
org.eclipse.ui.internal.WorkbenchHandlerServiceHandler@591a4d25,
|
||||||
|
,,true),null),
|
||||||
|
org.eclipse.ui.defaultAcceleratorConfiguration,
|
||||||
|
org.eclipse.ui.contexts.window,,,system)
|
||||||
|
!SUBENTRY 1 org.eclipse.jface 2 0 2024-04-10 15:06:13.933
|
||||||
|
!MESSAGE A conflict occurred for ALT+SHIFT+R:
|
||||||
|
Binding(ALT+SHIFT+R,
|
||||||
|
ParameterizedCommand(Command(org.eclipse.jdt.ui.edit.text.java.rename.element,Rename - Refactoring ,
|
||||||
|
Rename the selected element,
|
||||||
|
Category(org.eclipse.jdt.ui.category.refactoring,Refactor - Java,Java Refactoring Actions,true),
|
||||||
|
org.eclipse.ui.internal.WorkbenchHandlerServiceHandler@4bfe83d,
|
||||||
|
,,true),null),
|
||||||
|
org.eclipse.ui.defaultAcceleratorConfiguration,
|
||||||
|
org.eclipse.ui.contexts.window,,,system)
|
||||||
|
Binding(ALT+SHIFT+R,
|
||||||
|
ParameterizedCommand(Command(org.eclipse.ui.edit.rename,Rename,
|
||||||
|
Rename the selected item,
|
||||||
|
Category(org.eclipse.ui.category.file,File,null,true),
|
||||||
|
org.eclipse.ui.internal.WorkbenchHandlerServiceHandler@5906ebfb,
|
||||||
|
,,true),null),
|
||||||
|
org.eclipse.ui.defaultAcceleratorConfiguration,
|
||||||
|
org.eclipse.ui.contexts.window,,,system)
|
||||||
|
|
||||||
|
!ENTRY org.eclipse.egit.ui 2 0 2024-04-10 15:06:19.085
|
||||||
|
!MESSAGE Warning: The environment variable HOME is not set. The following directory will be used to store the Git
|
||||||
|
user global configuration and to define the default location to store repositories: 'C:\Users\LEN'. If this is
|
||||||
|
not correct please set the HOME environment variable and restart Eclipse. Otherwise Git for Windows and
|
||||||
|
EGit might behave differently since they see different configuration options.
|
||||||
|
This warning can be switched off on the Team > Git > Confirmations and Warnings preference page.
|
||||||
Binary file not shown.
|
|
@ -0,0 +1 @@
|
||||||
|
|
||||||
Binary file not shown.
|
|
@ -0,0 +1 @@
|
||||||
|
|
||||||
Binary file not shown.
Binary file not shown.
|
|
@ -0,0 +1,2 @@
|
||||||
|
eclipse.preferences.version=1
|
||||||
|
version=1
|
||||||
|
|
@ -0,0 +1,8 @@
|
||||||
|
content_assist_proposals_background=255,255,255
|
||||||
|
content_assist_proposals_foreground=0,0,0
|
||||||
|
eclipse.preferences.version=1
|
||||||
|
org.eclipse.jdt.ui.formatterprofiles.version=21
|
||||||
|
spelling_locale_initialized=true
|
||||||
|
typefilter_migrated_2=true
|
||||||
|
useAnnotationsPrefPage=true
|
||||||
|
useQuickDiffPrefPage=true
|
||||||
|
|
@ -0,0 +1,2 @@
|
||||||
|
eclipse.preferences.version=1
|
||||||
|
org.eclipse.jsch.core.hasChangedDefaultWin32SshHome=true
|
||||||
|
|
@ -0,0 +1,2 @@
|
||||||
|
eclipse.preferences.version=1
|
||||||
|
org.eclipse.m2e.discovery.pref.projects=
|
||||||
|
|
@ -0,0 +1,4 @@
|
||||||
|
eclipse.preferences.version=1
|
||||||
|
platformState=1643645456896
|
||||||
|
quickStart=false
|
||||||
|
tipsAndTricks=true
|
||||||
|
|
@ -0,0 +1,2 @@
|
||||||
|
eclipse.preferences.version=1
|
||||||
|
showIntro=false
|
||||||
|
|
@ -0,0 +1,9 @@
|
||||||
|
//org.eclipse.ui.commands/state/org.eclipse.ui.navigator.resources.nested.changeProjectPresentation/org.eclipse.ui.commands.radioState=false
|
||||||
|
PLUGINS_NOT_ACTIVATED_ON_STARTUP=;org.eclipse.m2e.discovery;
|
||||||
|
eclipse.preferences.version=1
|
||||||
|
org.eclipse.ui.workbench.ACTIVE_NOFOCUS_TAB_BG_END=255,255,255
|
||||||
|
org.eclipse.ui.workbench.ACTIVE_NOFOCUS_TAB_BG_START=255,255,255
|
||||||
|
org.eclipse.ui.workbench.ACTIVE_NOFOCUS_TAB_TEXT_COLOR=16,16,16
|
||||||
|
org.eclipse.ui.workbench.ACTIVE_TAB_BG_END=255,255,255
|
||||||
|
org.eclipse.ui.workbench.ACTIVE_TAB_BG_START=255,255,255
|
||||||
|
org.eclipse.ui.workbench.INACTIVE_TAB_BG_START=242,242,242
|
||||||
|
|
@ -0,0 +1,2 @@
|
||||||
|
eclipse.preferences.version=1
|
||||||
|
processedSchemes=,eclipse+command,eclipse+mpc
|
||||||
File diff suppressed because it is too large
Load Diff
|
|
@ -0,0 +1,11 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<projectDescription>
|
||||||
|
<name>.org.eclipse.egit.core.cmp</name>
|
||||||
|
<comment></comment>
|
||||||
|
<projects>
|
||||||
|
</projects>
|
||||||
|
<buildSpec>
|
||||||
|
</buildSpec>
|
||||||
|
<natures>
|
||||||
|
</natures>
|
||||||
|
</projectDescription>
|
||||||
Binary file not shown.
Binary file not shown.
|
|
@ -0,0 +1 @@
|
||||||
|
java
|
||||||
Binary file not shown.
Binary file not shown.
|
|
@ -0,0 +1,2 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||||
|
<typeInfoHistroy/>
|
||||||
|
|
@ -0,0 +1,2 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||||
|
<qualifiedTypeNameHistroy/>
|
||||||
|
|
@ -0,0 +1,10 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<section name="Workbench">
|
||||||
|
<section name="org.eclipse.jdt.internal.ui.packageview.PackageExplorerPart">
|
||||||
|
<item key="group_libraries" value="true"/>
|
||||||
|
<item key="layout" value="2"/>
|
||||||
|
<item key="rootMode" value="1"/>
|
||||||
|
<item key="linkWithEditor" value="false"/>
|
||||||
|
<item key="memento" value="<?xml version="1.0" encoding="UTF-8"?>
<packageExplorer group_libraries="1" layout="2" linkWithEditor="0" rootMode="1" workingSetName="Aggregate for window 1712754375951">
<customFilters userDefinedPatternsEnabled="false">
<xmlDefinedFilters>
<child filterId="org.eclipse.jdt.ui.PackageExplorer.StaticsFilter" isEnabled="false"/>
<child filterId="org.eclipse.buildship.ui.packageexplorer.filter.gradle.buildfolder" isEnabled="true"/>
<child filterId="org.eclipse.jdt.ui.PackageExplorer.NonSharedProjectsFilter" isEnabled="false"/>
<child filterId="org.eclipse.m2e.MavenModuleFilter" isEnabled="false"/>
<child filterId="org.eclipse.jdt.internal.ui.PackageExplorer.EmptyInnerPackageFilter" isEnabled="true"/>
<child filterId="org.eclipse.buildship.ui.packageexplorer.filter.gradle.subProject" isEnabled="true"/>
<child filterId="org.eclipse.jdt.ui.PackageExplorer.ClosedProjectsFilter" isEnabled="false"/>
<child filterId="org.eclipse.jdt.ui.PackageExplorer.EmptyLibraryContainerFilter" isEnabled="true"/>
<child filterId="org.eclipse.jdt.ui.PackageExplorer.PackageDeclarationFilter" isEnabled="true"/>
<child filterId="org.eclipse.pde.ui.BinaryProjectFilter1" isEnabled="false"/>
<child filterId="org.eclipse.jdt.ui.PackageExplorer.LocalTypesFilter" isEnabled="false"/>
<child filterId="org.eclipse.pde.ui.ExternalPluginLibrariesFilter1" isEnabled="true"/>
<child filterId="org.eclipse.jdt.ui.PackageExplorer.FieldsFilter" isEnabled="false"/>
<child filterId="org.eclipse.jdt.ui.PackageExplorer.NonJavaProjectsFilter" isEnabled="false"/>
<child filterId="org.eclipse.jdt.ui.PackageExplorer_patternFilterId_.*" isEnabled="true"/>
<child filterId="org.eclipse.jdt.ui.PackageExplorer.SyntheticMembersFilter" isEnabled="true"/>
<child filterId="org.eclipse.jdt.ui.PackageExplorer.ContainedLibraryFilter" isEnabled="false"/>
<child filterId="org.eclipse.jdt.internal.ui.PackageExplorer.HideInnerClassFilesFilter" isEnabled="true"/>
<child filterId="org.eclipse.jdt.ui.PackageExplorer.DeprecatedMembersFilter" isEnabled="false"/>
<child filterId="org.eclipse.jdt.ui.PackageExplorer.ImportDeclarationFilter" isEnabled="true"/>
<child filterId="org.eclipse.jdt.ui.PackageExplorer.NonJavaElementFilter" isEnabled="false"/>
<child filterId="org.eclipse.jdt.ui.PackageExplorer.LibraryFilter" isEnabled="false"/>
<child filterId="org.eclipse.jdt.ui.PackageExplorer.CuAndClassFileFilter" isEnabled="false"/>
<child filterId="org.eclipse.jdt.internal.ui.PackageExplorer.EmptyPackageFilter" isEnabled="false"/>
<child filterId="org.eclipse.jdt.ui.PackageExplorer.NonPublicFilter" isEnabled="false"/>
</xmlDefinedFilters>
</customFilters>
</packageExplorer>"/>
|
||||||
|
</section>
|
||||||
|
</section>
|
||||||
|
|
@ -0,0 +1 @@
|
||||||
|
2024-04-10 15:06:18,970 [Worker-0: Loading available Gradle versions] INFO o.e.b.c.i.u.g.PublishedGradleVersions - Gradle version information cache is out-of-date. Trying to update.
|
||||||
|
|
@ -0,0 +1,41 @@
|
||||||
|
<configuration scan="true">
|
||||||
|
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
|
||||||
|
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
|
||||||
|
<pattern>%date [%thread] %-5level %logger{35} - %msg%n</pattern>
|
||||||
|
</encoder>
|
||||||
|
<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
|
||||||
|
<level>OFF</level> <!-- change to DEBUG to mimic '-consolelog' behaviour -->
|
||||||
|
</filter>
|
||||||
|
</appender>
|
||||||
|
|
||||||
|
<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
|
||||||
|
<File>${org.eclipse.m2e.log.dir}/0.log</File>
|
||||||
|
<rollingPolicy class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy">
|
||||||
|
<FileNamePattern>${org.eclipse.m2e.log.dir}/%i.log</FileNamePattern>
|
||||||
|
<MinIndex>1</MinIndex>
|
||||||
|
<MaxIndex>10</MaxIndex>
|
||||||
|
</rollingPolicy>
|
||||||
|
<triggeringPolicy class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
|
||||||
|
<MaxFileSize>100MB</MaxFileSize>
|
||||||
|
</triggeringPolicy>
|
||||||
|
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
|
||||||
|
<pattern>%date [%thread] %-5level %logger{35} - %msg%n</pattern>
|
||||||
|
</encoder>
|
||||||
|
</appender>
|
||||||
|
|
||||||
|
<appender name="EclipseLog" class="org.eclipse.m2e.logback.appender.EclipseLogAppender">
|
||||||
|
<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
|
||||||
|
<level>WARN</level>
|
||||||
|
</filter>
|
||||||
|
</appender>
|
||||||
|
|
||||||
|
<appender name="MavenConsoleLog" class="org.eclipse.m2e.logback.appender.MavenConsoleAppender">
|
||||||
|
</appender>
|
||||||
|
|
||||||
|
<root level="INFO">
|
||||||
|
<appender-ref ref="FILE" />
|
||||||
|
<appender-ref ref="STDOUT" />
|
||||||
|
<appender-ref ref="EclipseLog" />
|
||||||
|
<appender-ref ref="MavenConsoleLog" />
|
||||||
|
</root>
|
||||||
|
</configuration>
|
||||||
|
|
@ -0,0 +1,6 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<setup:Workspace
|
||||||
|
xmi:version="2.0"
|
||||||
|
xmlns:xmi="http://www.omg.org/XMI"
|
||||||
|
xmlns:setup="http://www.eclipse.org/oomph/setup/1.0"
|
||||||
|
name="workspace"/>
|
||||||
|
|
@ -0,0 +1,2 @@
|
||||||
|
#Cached timestamps
|
||||||
|
#Wed Apr 10 15:06:53 CEST 2024
|
||||||
|
|
@ -0,0 +1,3 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<section name="Workbench">
|
||||||
|
</section>
|
||||||
|
|
@ -0,0 +1,2 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<state reopen="false"/>
|
||||||
|
|
@ -0,0 +1,6 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<workingSetManager>
|
||||||
|
<workingSet editPageId="org.eclipse.jdt.internal.ui.DynamicSourcesWorkingSet" factoryID="org.eclipse.ui.internal.WorkingSetFactory" id="1712754374994_0" label="Java Main Sources" name="Java Main Sources"/>
|
||||||
|
<workingSet editPageId="org.eclipse.jdt.internal.ui.DynamicSourcesWorkingSet" factoryID="org.eclipse.ui.internal.WorkingSetFactory" id="1712754375014_1" label="Java Test Sources" name="Java Test Sources"/>
|
||||||
|
<workingSet aggregate="true" factoryID="org.eclipse.ui.internal.WorkingSetFactory" id="1712754375951_2" label="Window Working Set" name="Aggregate for window 1712754375951"/>
|
||||||
|
</workingSetManager>
|
||||||
|
|
@ -0,0 +1,3 @@
|
||||||
|
#Wed Apr 10 15:06:11 CEST 2024
|
||||||
|
org.eclipse.core.runtime=2
|
||||||
|
org.eclipse.platform=4.22.0.v20211124-1800
|
||||||
|
|
@ -0,0 +1,20 @@
|
||||||
|
package backend;
|
||||||
|
|
||||||
|
public class Grid {
|
||||||
|
int[][] grid;
|
||||||
|
|
||||||
|
public Grid(int xSize,int ySize) {
|
||||||
|
grid = new int[xSize][ySize];
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getValueCell(int x,int y) {
|
||||||
|
return grid[x][y];
|
||||||
|
}
|
||||||
|
public void setValueCell(int x,int y,int a) {
|
||||||
|
grid[x][y]=a;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
package backend;
|
package backend;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import windowInterface.MyInterface;
|
import windowInterface.MyInterface;
|
||||||
|
|
||||||
|
|
@ -12,10 +12,8 @@ public class Simulator extends Thread {
|
||||||
private final int LINE_NUM = 100;
|
private final int LINE_NUM = 100;
|
||||||
private final int LIFE_TYPE_NUM = 4;
|
private final int LIFE_TYPE_NUM = 4;
|
||||||
//Conway Radius : 1
|
//Conway Radius : 1
|
||||||
private final int CONWAY_RADIUS = 1;
|
|
||||||
private final int LIFE_AREA_RADIUS = 1;
|
private final int LIFE_AREA_RADIUS = 1;
|
||||||
//Animal Neighborhood Radius : 5
|
//Animal Neighborhood Radius : 5
|
||||||
private final int ANIMAL_NEIGHBORHOOD_RADIUS = 5 ;
|
|
||||||
private final int ANIMAL_AREA_RADIUS = 2;
|
private final int ANIMAL_AREA_RADIUS = 2;
|
||||||
private ArrayList<Integer> fieldSurviveValues;
|
private ArrayList<Integer> fieldSurviveValues;
|
||||||
private ArrayList<Integer> fieldBirthValues;
|
private ArrayList<Integer> fieldBirthValues;
|
||||||
|
|
@ -25,9 +23,11 @@ public class Simulator extends Thread {
|
||||||
private boolean stopFlag;
|
private boolean stopFlag;
|
||||||
private boolean pauseFlag;
|
private boolean pauseFlag;
|
||||||
private boolean loopingBorder;
|
private boolean loopingBorder;
|
||||||
private boolean clickActionFlag;
|
private String clickActionFlag;
|
||||||
private int loopDelay = 150;
|
private int loopDelay = 150;
|
||||||
|
|
||||||
private Grid grid;
|
private Grid grid;
|
||||||
|
|
||||||
//TODO : add missing attribute(s)
|
//TODO : add missing attribute(s)
|
||||||
|
|
||||||
public Simulator(MyInterface mjfParam) {
|
public Simulator(MyInterface mjfParam) {
|
||||||
|
|
@ -35,32 +35,26 @@ public class Simulator extends Thread {
|
||||||
stopFlag=false;
|
stopFlag=false;
|
||||||
pauseFlag=false;
|
pauseFlag=false;
|
||||||
loopingBorder=false;
|
loopingBorder=false;
|
||||||
clickActionFlag=false;
|
clickActionFlag="CellMode";
|
||||||
|
|
||||||
agents = new ArrayList<Agent>();
|
agents = new ArrayList<Agent>();
|
||||||
fieldBirthValues = new ArrayList<Integer>();
|
fieldSurviveValues = new ArrayList<>();
|
||||||
fieldSurviveValues = new ArrayList<Integer>();
|
fieldSurviveValues.add(2);
|
||||||
grid = new Grid(COL_NUM,LINE_NUM);
|
fieldSurviveValues.add(3);
|
||||||
|
|
||||||
//TODO : add missing attribute initialization
|
fieldBirthValues = new ArrayList<>();
|
||||||
|
fieldBirthValues.add(3);
|
||||||
|
|
||||||
|
grid = new Grid(LINE_NUM, COL_NUM);
|
||||||
//Default rule : Survive always, birth never
|
|
||||||
for(int i =0; i<9; i++) {
|
|
||||||
fieldSurviveValues.add(i);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getWidth() {
|
public int getWidth() {
|
||||||
//TODO : replace with proper return
|
return LINE_NUM;
|
||||||
return COL_NUM;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getHeight() {
|
public int getHeight() {
|
||||||
//TODO : replace with proper return
|
return COL_NUM;
|
||||||
return LINE_NUM;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//Should probably stay as is
|
//Should probably stay as is
|
||||||
|
|
@ -124,11 +118,68 @@ public class Simulator extends Thread {
|
||||||
* then the cell becomes alive
|
* then the cell becomes alive
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
Grid nextGrid = new Grid(LINE_NUM, COL_NUM);
|
||||||
|
|
||||||
|
// Iterate over each cell in the grid
|
||||||
|
for (int i = 0; i < LINE_NUM; i++) {
|
||||||
|
for (int j = 0; j < COL_NUM; j++) {
|
||||||
|
int liveNeighbors = countLiveNeighbors(i, j);
|
||||||
|
|
||||||
|
if (getCell(i, j) == 1) {
|
||||||
|
if (fieldSurviveValues.contains(liveNeighbors)) {
|
||||||
|
nextGrid.setValueCell(i, j, 1);
|
||||||
|
} else {
|
||||||
|
nextGrid.setValueCell(i, j, 0);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (fieldBirthValues.contains(liveNeighbors)) {
|
||||||
|
nextGrid.setValueCell(i, j, 1);
|
||||||
|
} else {
|
||||||
|
nextGrid.setValueCell(i, j, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
grid = nextGrid;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* method called to count living cells around one
|
||||||
|
*/
|
||||||
|
public int countLiveNeighbors(int x, int y) {
|
||||||
|
int liveNeighbors = 0;
|
||||||
|
|
||||||
|
for (int i = -LIFE_AREA_RADIUS; i <= LIFE_AREA_RADIUS; i++) {
|
||||||
|
for (int j = -LIFE_AREA_RADIUS; j <= LIFE_AREA_RADIUS; j++) {
|
||||||
|
if (i == 0 && j == 0) continue; // Skip the current cell
|
||||||
|
|
||||||
|
int neighborX = x + i;
|
||||||
|
int neighborY = y + j;
|
||||||
|
|
||||||
|
if (loopingBorder) {
|
||||||
|
// Wrap around the edges
|
||||||
|
if (neighborX < 0) neighborX = LINE_NUM - 1;
|
||||||
|
else if (neighborX >= LINE_NUM) neighborX = 0;
|
||||||
|
|
||||||
|
if (neighborY < 0) neighborY = COL_NUM - 1;
|
||||||
|
else if (neighborY >= COL_NUM) neighborY = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (neighborX >= 0 && neighborX < LINE_NUM && neighborY >= 0 && neighborY < COL_NUM) {
|
||||||
|
if (getCell(neighborX, neighborY) == 1) {
|
||||||
|
liveNeighbors++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return liveNeighbors;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* leave this as is
|
* leave this as is
|
||||||
*/
|
*/
|
||||||
|
|
@ -140,8 +191,12 @@ public class Simulator extends Thread {
|
||||||
* method called when clicking pause button
|
* method called when clicking pause button
|
||||||
*/
|
*/
|
||||||
public void togglePause() {
|
public void togglePause() {
|
||||||
// TODO : actually toggle the corresponding flag
|
if (pauseFlag == true ) {
|
||||||
pauseFlag = !pauseFlag;
|
pauseFlag=false;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
pauseFlag=true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -149,9 +204,14 @@ public class Simulator extends Thread {
|
||||||
*/
|
*/
|
||||||
public void clickCell(int x, int y) {
|
public void clickCell(int x, int y) {
|
||||||
//TODO : complete method
|
//TODO : complete method
|
||||||
|
if (clickActionFlag=="CellMode") {
|
||||||
getCell(x,y);
|
if (grid.getValueCell(x, y)==1) {
|
||||||
|
this.setCell(x, y, 0);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
this.setCell(x, y, 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -161,9 +221,7 @@ public class Simulator extends Thread {
|
||||||
* @return value of cell
|
* @return value of cell
|
||||||
*/
|
*/
|
||||||
public int getCell(int x, int y) {
|
public int getCell(int x, int y) {
|
||||||
//TODO : complete method with proper return
|
return grid.getValueCell(x, y);
|
||||||
|
|
||||||
return grid.getValueCell(x,y);
|
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
|
@ -197,8 +255,7 @@ public class Simulator extends Thread {
|
||||||
* @param val to set in cell
|
* @param val to set in cell
|
||||||
*/
|
*/
|
||||||
public void setCell(int x, int y, int val) {
|
public void setCell(int x, int y, int val) {
|
||||||
//TODO : complete method
|
grid.setValueCell(x, y, val);
|
||||||
grid.setValueCell(x,y,val);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -207,8 +264,19 @@ 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;
|
|
||||||
|
for (int i = 0; i < LINE_NUM; i++) {
|
||||||
|
StringBuilder line = new StringBuilder();
|
||||||
|
for (int j = 0; j < COL_NUM; j++) {
|
||||||
|
line.append(grid.getValueCell(i, j));
|
||||||
|
if (j < COL_NUM - 1) {
|
||||||
|
line.append(";");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
saveState.add(line.toString());
|
||||||
|
}
|
||||||
|
return saveState;
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
|
@ -251,35 +319,40 @@ public class Simulator extends Thread {
|
||||||
* to be alive in new state
|
* to be alive in new state
|
||||||
*/
|
*/
|
||||||
public void generateRandom(float chanceOfLife) {
|
public void generateRandom(float chanceOfLife) {
|
||||||
//TODO : complete method
|
for (int i = 0; i < LINE_NUM; i++) {
|
||||||
/*
|
for (int j = 0; j < COL_NUM; j++) {
|
||||||
* Advice :
|
float randomValue = (float) Math.random();
|
||||||
* as you should probably have a separate class
|
if (randomValue <= chanceOfLife) {
|
||||||
* representing the field of cells...
|
grid.setValueCell(i, j, 1);
|
||||||
* maybe just make a constructor in there
|
} else {
|
||||||
* and use it here
|
grid.setValueCell(i, j, 0);
|
||||||
*/
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isLoopingBorder() {
|
public boolean isLoopingBorder() {
|
||||||
//TODO : complete method with proper return
|
|
||||||
return loopingBorder;
|
return loopingBorder;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void toggleLoopingBorder() {
|
public void toggleLoopingBorder() {
|
||||||
loopingBorder = !loopingBorder ;
|
if (isLoopingBorder() == true) {
|
||||||
|
loopingBorder=false;
|
||||||
//TODO : complete method
|
}else {
|
||||||
|
loopingBorder=true;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setLoopDelay(int delay) {
|
public void setLoopDelay(int delay) {
|
||||||
loopDelay = delay;
|
loopDelay=delay;
|
||||||
//TODO : complete method
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void toggleClickAction() {
|
public void toggleClickAction() {
|
||||||
//TODO : complete method
|
//TODO : complete method
|
||||||
|
if (clickActionFlag=="CellMode") {
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -292,8 +365,12 @@ public class Simulator extends Thread {
|
||||||
*/
|
*/
|
||||||
public ArrayList<String> getRule() {
|
public ArrayList<String> getRule() {
|
||||||
//TODO : complete method with proper return
|
//TODO : complete method with proper return
|
||||||
|
ArrayList<String> rule = new ArrayList<>();
|
||||||
|
|
||||||
return null;
|
rule.add(String.join(";", fieldSurviveValues.stream().map(Object::toString).toArray(String[]::new)));
|
||||||
|
rule.add(String.join(";", fieldBirthValues.stream().map(Object::toString).toArray(String[]::new)));
|
||||||
|
|
||||||
|
return rule;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void loadRule(ArrayList<String> lines) {
|
public void loadRule(ArrayList<String> lines) {
|
||||||
|
|
@ -301,8 +378,9 @@ public class Simulator extends Thread {
|
||||||
System.out.println("empty rule file");
|
System.out.println("empty rule file");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
//TODO : remove previous rule (=emptying lists)
|
|
||||||
|
fieldSurviveValues.clear();
|
||||||
|
fieldBirthValues.clear();
|
||||||
|
|
||||||
String surviveLine = lines.get(0);
|
String surviveLine = lines.get(0);
|
||||||
String birthLine = lines.get(1);
|
String birthLine = lines.get(1);
|
||||||
|
|
@ -310,14 +388,14 @@ public class Simulator extends Thread {
|
||||||
for(int x=0; x<surviveElements.length;x++) {
|
for(int x=0; x<surviveElements.length;x++) {
|
||||||
String elem = surviveElements[x];
|
String elem = surviveElements[x];
|
||||||
int value = Integer.parseInt(elem);
|
int value = Integer.parseInt(elem);
|
||||||
//TODO : add value to possible survive values
|
fieldSurviveValues.add(value);
|
||||||
|
|
||||||
}
|
}
|
||||||
String[] birthElements = birthLine.split(";");
|
String[] birthElements = birthLine.split(";");
|
||||||
for(int x=0; x<birthElements.length;x++) {
|
for(int x=0; x<birthElements.length;x++) {
|
||||||
String elem = birthElements[x];
|
String elem = birthElements[x];
|
||||||
int value = Integer.parseInt(elem);
|
int value = Integer.parseInt(elem);
|
||||||
//TODO : add value to possible birth values
|
fieldBirthValues.add(value);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -339,7 +417,13 @@ public class Simulator extends Thread {
|
||||||
public String clickActionName() {
|
public String clickActionName() {
|
||||||
// TODO : initially return "sheep" or "cell"
|
// TODO : initially return "sheep" or "cell"
|
||||||
// depending on clickActionFlag
|
// depending on clickActionFlag
|
||||||
return "";
|
String action = "Cell";
|
||||||
|
|
||||||
|
if (clickActionFlag == "CellMode") {
|
||||||
|
action = "Cell";
|
||||||
|
}
|
||||||
|
|
||||||
|
return action;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue