mirror of
https://github.com/Cpt-Adok/SNAKE.git
synced 2026-01-25 06:34:06 +00:00
changement dans la façon qu'il apprend
This commit is contained in:
2
Makefile
2
Makefile
@@ -27,7 +27,7 @@ $(BIN_DIR)/$(MAIN_FILE).class : $(SRC_DIR)/$(MAIN_FILE).java
|
|||||||
$(JAVAC) -d $(BIN_DIR) -sourcepath $(SRC_DIR) -classpath $(JAR) $<
|
$(JAVAC) -d $(BIN_DIR) -sourcepath $(SRC_DIR) -classpath $(JAR) $<
|
||||||
|
|
||||||
run:
|
run:
|
||||||
java -cp $(BIN_DIR) $(MAIN_FILE) $(channel) $(adversaire)
|
java -Xmx16g -cp $(BIN_DIR) $(MAIN_FILE) $(channel) $(adversaire)
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
@rm -rf $(BIN_DIR)
|
@rm -rf $(BIN_DIR)
|
||||||
Binary file not shown.
BIN
res/save/learn1.ser
Normal file
BIN
res/save/learn1.ser
Normal file
Binary file not shown.
BIN
res/save/learn2.ser
Normal file
BIN
res/save/learn2.ser
Normal file
Binary file not shown.
@@ -8,46 +8,44 @@ import tests.IATest;
|
|||||||
|
|
||||||
public class Main {
|
public class Main {
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
// Personnage.n = 4;
|
Personnage.n = 4;
|
||||||
|
|
||||||
// Map map = new Map(12, 22);
|
Map map = new Map(12, 22);
|
||||||
|
|
||||||
// // lancer en local
|
// // lancer en local
|
||||||
// if (args.length < 2) {
|
if (args.length < 2) {
|
||||||
// Grid[][] grid = map.getGrid();
|
Grid[][] grid = map.getGrid();
|
||||||
|
|
||||||
// QTable qTable1 = new QTable();
|
// QTable qTable1 = new QTable();
|
||||||
// qTable1.getValues("path_to_save_qtable1.ser");
|
// qTable1.getValues("res" + File.separator + "save" + File.separator + "learn1.ser");
|
||||||
|
|
||||||
// QTable qTable2 = new QTable();
|
// QTable qTable2 = new QTable();
|
||||||
// qTable2.getValues("path_to_save_qtable2.ser");
|
// qTable2.getValues("res" + File.separator + "save" + File.separator + "learn1.ser");
|
||||||
|
|
||||||
// // Avant de jouer contre l'ia, vous pouvez essayer de l'entrainer avec la fonction tests.IATest.learnIAvsIA()
|
// // Avant de jouer contre l'ia, vous pouvez essayer de l'entrainer avec la fonction tests.IATest.learnIAvsIA()
|
||||||
// // il jouera avec lui meme et mettra les sauvegardes dans le dossier learn.ser,
|
// // il jouera avec lui meme et mettra les sauvegardes dans le dossier learn.ser,
|
||||||
|
|
||||||
// // Attention lors de l'apprentissage, ne pas couper le processus sinon vous allez perdre toute vos donnees
|
// // Attention lors de l'apprentissage, ne pas couper le processus sinon vous allez perdre toute vos donnees
|
||||||
// Personnage[] personnages = new Personnage[] {
|
Personnage[] personnages = new Personnage[] {
|
||||||
// new IAQLearning(new int[] {2, 2}, qTable1),
|
// new IAQLearning(new int[] {2, 2}, qTable1),
|
||||||
// // new Player(new int[] {2, 2}, "Philippe Etchebest"),
|
new Player(new int[] {2, 2}, "Philippe Etchebest"),
|
||||||
// // new Player(new int[] {grid[0].length - 3, grid.length - 3}, "Luke Skywalker"),
|
new Player(new int[] {grid[0].length - 3, grid.length - 3}, "Luke Skywalker"),
|
||||||
// // new Robot("Robot", new int[] {grid[0].length - 3, grid.length - 3}),
|
// new Robot("Robot", new int[] {grid[0].length - 3, grid.length - 3}),
|
||||||
// new IAQLearning(new int[] {grid[0].length - 3, grid.length - 3}, qTable2),
|
// new IAQLearning(new int[] {grid[0].length - 3, grid.length - 3}, qTable2),
|
||||||
// };
|
};
|
||||||
|
|
||||||
// // map.addObjectsRandomize(new Item[] {Item.FRAISE, Item.WALL}, 2);
|
// map.addObjectsRandomize(new Item[] {Item.FRAISE, Item.WALL}, 2);
|
||||||
// // map.addObjects(Item.FRAISE, 2, 2);
|
// map.addObjects(Item.FRAISE, 2, 2);
|
||||||
|
|
||||||
// new Terminal(map, personnages).run();
|
new Terminal(map, personnages).run();
|
||||||
// }
|
}
|
||||||
// // lancer en ligne
|
// // lancer en ligne
|
||||||
// else {
|
else {
|
||||||
// Personnage[] personnages = new Personnage[] {
|
Personnage[] personnages = new Personnage[] {
|
||||||
// new Player(new int[] {0, 0}, "Philippe Etchebest"),
|
new Player(new int[] {0, 0}, "Philippe Etchebest"),
|
||||||
// };
|
};
|
||||||
|
|
||||||
// new Terminal(map, personnages).run(args[0], args[1]);
|
new Terminal(map, personnages).run(args[0], args[1]);
|
||||||
// }
|
}
|
||||||
|
|
||||||
IATest.learnIAvsIA();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,9 +13,13 @@ import personnage.Personnage;
|
|||||||
import types.Mouvement;
|
import types.Mouvement;
|
||||||
|
|
||||||
public class IATest {
|
public class IATest {
|
||||||
private final static String path = "res" + File.separator +
|
private final static String path1 = "res" + File.separator +
|
||||||
"save" + File.separator +
|
"save" + File.separator +
|
||||||
"learn.ser";
|
"learn1.ser";
|
||||||
|
|
||||||
|
private final static String path2 = "res" + File.separator +
|
||||||
|
"save" + File.separator +
|
||||||
|
"learn2.ser";
|
||||||
|
|
||||||
public static void learnIA() {
|
public static void learnIA() {
|
||||||
double alpha = 0.1;
|
double alpha = 0.1;
|
||||||
@@ -33,7 +37,7 @@ public class IATest {
|
|||||||
IAQLearning iaqLearning = new IAQLearning(new int[] {2, 2}, qTable, alpha, gamma, epsilon);
|
IAQLearning iaqLearning = new IAQLearning(new int[] {2, 2}, qTable, alpha, gamma, epsilon);
|
||||||
Map map = new Map(12, 22);
|
Map map = new Map(12, 22);
|
||||||
|
|
||||||
qTable.getValues(path);
|
qTable.getValues(path1);
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
Map mapIA = new Map(map.getGrid()[0].length, map.getGrid().length);
|
Map mapIA = new Map(map.getGrid()[0].length, map.getGrid().length);
|
||||||
@@ -64,31 +68,34 @@ public class IATest {
|
|||||||
map.clearMap();
|
map.clearMap();
|
||||||
}
|
}
|
||||||
|
|
||||||
qTable.save(path);
|
qTable.save(path1);
|
||||||
|
|
||||||
epsilon = Math.max(minEpsilon, epsilon * decay_rate);
|
epsilon = Math.max(minEpsilon, epsilon * decay_rate);
|
||||||
System.out.println("Episode : " + episode + " | Robot 1 States : " + qTable.getqValues().size());
|
System.out.println("Episode : " + episode + " | States : " + qTable.getqValues().size());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void learnIAvsIA() {
|
public static void learnIAvsIA() {
|
||||||
double alpha = 0.1;
|
double alpha = 0.9;
|
||||||
double gamma = 0.9;
|
double gamma = 0.9;
|
||||||
double epsilon = 0.1;
|
double epsilon = 0.1;
|
||||||
|
|
||||||
int maxEpisode = 1000;
|
int maxEpisode = 1000000;
|
||||||
|
|
||||||
Personnage.n = 4;
|
Personnage.n = 4;
|
||||||
|
|
||||||
for (int episode = 0; episode < maxEpisode; episode++) {
|
QTable qTable1 = new QTable();
|
||||||
QTable qTable = new QTable();
|
qTable1.getValues(path1);
|
||||||
qTable.getValues(path);
|
|
||||||
|
|
||||||
|
QTable qTable2 = new QTable();
|
||||||
|
qTable2.getValues(path2);
|
||||||
|
|
||||||
|
for (int episode = 0; episode < maxEpisode; episode++) {
|
||||||
Map map = new Map(12, 22);
|
Map map = new Map(12, 22);
|
||||||
|
|
||||||
IAQLearning[] iaqLearnings = new IAQLearning[] {
|
IAQLearning[] iaqLearnings = new IAQLearning[] {
|
||||||
new IAQLearning(new int[] {2, 2}, qTable, alpha, gamma, epsilon),
|
new IAQLearning(new int[] {2, 2}, qTable1, alpha, gamma, epsilon),
|
||||||
new IAQLearning(new int[] {9, 19}, qTable, alpha, gamma, epsilon),
|
new IAQLearning(new int[] {9, 19}, qTable2, alpha, gamma, epsilon),
|
||||||
};
|
};
|
||||||
|
|
||||||
boolean isGameOver = false;
|
boolean isGameOver = false;
|
||||||
@@ -136,13 +143,14 @@ public class IATest {
|
|||||||
|
|
||||||
mapIA.clearMap();
|
mapIA.clearMap();
|
||||||
map.clearMap();
|
map.clearMap();
|
||||||
|
|
||||||
|
System.out.println("States 1: " + qTable1.getqValues().size() + " States 2: " + qTable2.getqValues().size());
|
||||||
}
|
}
|
||||||
|
|
||||||
if(isGameOver) break;
|
if(isGameOver) break;
|
||||||
qTable.save(path);
|
|
||||||
|
|
||||||
System.out.println("Episode: " + episode + " States: " + qTable.getqValues().size());
|
|
||||||
}
|
}
|
||||||
|
System.out.println(" States 1: " + qTable1.getqValues().size() + " States 2: " + qTable2.getqValues().size() + "Episode: " + episode);
|
||||||
}
|
}
|
||||||
|
qTable1.save(path1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user