This commit is contained in:
Nabil Ould Hamou 2024-10-11 21:46:06 +02:00
parent db7919be94
commit 4d879f83a6
8 changed files with 164 additions and 50 deletions

View file

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

33
src/main/java/Main.java Normal file
View file

@ -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();
}
}

View file

@ -1,11 +0,0 @@
package fr.nabil.algogenetique;
public class Main {
public static void main(String[] args) {
}
}

View file

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

View file

@ -1,7 +0,0 @@
package fr.nabil.algogenetique.logique;
public interface Simulation {
void evaluate();
}

View file

@ -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<Population> 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() {

View file

@ -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<Integer, Integer> getCoordinates() {
return new Pair<>(posX, posY);
}
public BitSet getChromosome() {
return chromosome;
}
public void setChromosome(BitSet chromosome) {
this.chromosome = chromosome;
}
}

View file

@ -0,0 +1,28 @@
package utils;
public class Pair<T, S> {
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;
}
}