diff --git a/build.gradle b/build.gradle index ca890c5..d62f097 100644 --- a/build.gradle +++ b/build.gradle @@ -1,21 +1,46 @@ +import org.gradle.nativeplatform.platform.internal.DefaultNativePlatform + plugins { id 'java' + id 'application' + id 'com.github.johnrengelman.shadow' version '7.0.0' } group = 'fr.nabil' version = '1.0-SNAPSHOT' +mainClassName = project.properties['main'] ?: 'Main' repositories { mavenCentral() +// maven { +// url "https://s01.oss.sonatype.org/content/repositories/staging/" +// metadataSources { artifact() } +// } } dependencies { - testImplementation platform('org.junit:junit-bom:5.10.0') - testImplementation 'org.junit.jupiter:junit-jupiter' - + testImplementation 'org.junit.jupiter:junit-jupiter-api:5.7.0' + testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.7.0' implementation 'uk.co.electronstudio.jaylib:jaylib:5.0.+' } +application { + if(DefaultNativePlatform.currentOperatingSystem.isMacOsX()) { + applicationDefaultJvmArgs = ['-XstartOnFirstThread'] + } +} + test { useJUnitPlatform() +} + + +distributions { + main { + contents { + into('resources'){ + from 'resources' + } + } + } } \ No newline at end of file diff --git a/src/main/java/Main.java b/src/main/java/Main.java new file mode 100644 index 0000000..8cd5935 --- /dev/null +++ b/src/main/java/Main.java @@ -0,0 +1,33 @@ +import logique.Maze; + +import static com.raylib.Raylib.*; +import static com.raylib.Jaylib.BLACK; +import static com.raylib.Jaylib.RAYWHITE; + +public class Main { + + public static void main(String[] args) { + InitWindow(500, 500, "Labyrinthe"); + + SetTargetFPS(100); + + while (!WindowShouldClose()) { + BeginDrawing(); + ClearBackground(RAYWHITE); + + for (int i = 0; i < Maze.MAZE[0].length; i++) { + for (int j = 0; j < Maze.MAZE.length; j++) { + if (Maze.MAZE[j][i] == 1) { + DrawRectangle(i * 50, j * 50, 50, 50, BLACK); + } + } + } + + DrawFPS(20, 20); + EndDrawing(); + } + + CloseWindow(); + } + +} diff --git a/src/main/java/fr/nabil/algogenetique/Main.java b/src/main/java/fr/nabil/algogenetique/Main.java deleted file mode 100644 index 6f422f0..0000000 --- a/src/main/java/fr/nabil/algogenetique/Main.java +++ /dev/null @@ -1,11 +0,0 @@ -package fr.nabil.algogenetique; - -public class Main { - - public static void main(String[] args) { - - - - } - -} diff --git a/src/main/java/fr/nabil/algogenetique/logique/Population.java b/src/main/java/fr/nabil/algogenetique/logique/Population.java deleted file mode 100644 index 981bd64..0000000 --- a/src/main/java/fr/nabil/algogenetique/logique/Population.java +++ /dev/null @@ -1,24 +0,0 @@ -package fr.nabil.algogenetique.logique; - -import java.util.BitSet; - -public class Population { - - private BitSet chromosome; - - public Population() { - this.chromosome = new BitSet(); - } - - public Population(BitSet chromosome) { - this.chromosome = chromosome; - } - - public BitSet getChromosome() { - return chromosome; - } - - public void setChromosome(BitSet chromosome) { - this.chromosome = chromosome; - } -} diff --git a/src/main/java/fr/nabil/algogenetique/logique/Simulation.java b/src/main/java/fr/nabil/algogenetique/logique/Simulation.java deleted file mode 100644 index 4b7e708..0000000 --- a/src/main/java/fr/nabil/algogenetique/logique/Simulation.java +++ /dev/null @@ -1,7 +0,0 @@ -package fr.nabil.algogenetique.logique; - -public interface Simulation { - - void evaluate(); - -} diff --git a/src/main/java/fr/nabil/algogenetique/logique/Maze.java b/src/main/java/logique/Maze.java similarity index 65% rename from src/main/java/fr/nabil/algogenetique/logique/Maze.java rename to src/main/java/logique/Maze.java index 6f597ed..6f53f54 100644 --- a/src/main/java/fr/nabil/algogenetique/logique/Maze.java +++ b/src/main/java/logique/Maze.java @@ -1,11 +1,21 @@ -package fr.nabil.algogenetique.logique; +package logique; -public class Maze implements Simulation { +import java.util.ArrayList; +import java.util.List; - private int[][] maze = { - {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, - {1, 0, 1, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 1}, +public class Maze { + public static int[][] MAZE = { + {1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, + {1, 0, 0, 0, 1, 0, 1, 0, 0, 0}, + {1, 0, 1, 0, 1, 0, 1, 0, 1, 1}, + {1, 0, 1, 0, 0, 0, 1, 0, 0, 1}, + {0, 0, 1, 1, 1, 0, 1, 1, 0, 1}, + {1, 0, 0, 0, 0, 0, 0, 1, 0, 1}, + {1, 1, 0, 1, 1, 1, 0, 1, 0, 1}, + {1, 0, 0, 0, 0, 1, 0, 1, 0, 1}, + {1, 0, 1, 1, 0, 1, 0, 0, 0, 1}, + {1, 1, 1, 1, 1, 1, 1, 1, 1, 1} }; private int populationSize; @@ -15,12 +25,20 @@ public class Maze implements Simulation { private float crossover; private float elitism; + private List populationList; + public Maze(int populationSize, int iterations, float mutation, float crossover, float elitism) { this.populationSize = populationSize; this.iterations = iterations; this.mutation = mutation; this.crossover = crossover; this.elitism = elitism; + + this.populationList = new ArrayList<>(); + } + + public void init() { + } public void evaluate() { diff --git a/src/main/java/logique/Population.java b/src/main/java/logique/Population.java new file mode 100644 index 0000000..b3c8619 --- /dev/null +++ b/src/main/java/logique/Population.java @@ -0,0 +1,52 @@ +package logique; + +import utils.Pair; + +import java.util.BitSet; + +public class Population { + + private BitSet chromosome; + private int posX; + private int posY; + + public Population() { + this.chromosome = new BitSet(); + } + + public Population(BitSet chromosome) { + this.chromosome = chromosome; + } + + public void move(int type) { + switch (type) { + case 0: // UP + + break; + case 1: // DOWN + break; + case 2: // L + break; + case 3: // R + break; + } + } + + private boolean isCoordinateValid(int x, int y) { + if (x > Maze.MAZE[0].length || x < 0) return false; + if (y > Maze.MAZE.length || y < 0) return false; + return Maze.MAZE[x][y] != 1; + } + + public Pair getCoordinates() { + return new Pair<>(posX, posY); + } + + public BitSet getChromosome() { + return chromosome; + } + + public void setChromosome(BitSet chromosome) { + this.chromosome = chromosome; + } +} diff --git a/src/main/java/utils/Pair.java b/src/main/java/utils/Pair.java new file mode 100644 index 0000000..864a204 --- /dev/null +++ b/src/main/java/utils/Pair.java @@ -0,0 +1,28 @@ +package utils; + +public class Pair { + + private T first; + private S second; + + public Pair(T first, S second) { + this.first = first; + this.second = second; + } + + public void setFirst(T first) { + this.first = first; + } + + public void setSecond(S second) { + this.second = second; + } + + public T getFirst() { + return first; + } + + public S getSecond() { + return second; + } +}