changement de plusieurs fonction

This commit is contained in:
2024-07-13 22:26:35 +02:00
parent 99c814c37f
commit 66bd0eef4d
3 changed files with 44 additions and 60 deletions

View File

@@ -7,45 +7,38 @@ import personnage.*;
import tests.IATest; import tests.IATest;
public class Main { public class Main {
private static Map map = new Map(12, 22);
/**
* Dans ce jeu, il y a 3 types de personnage disponible :
* - Les Joueurs (Player)
* - Le robot (Robot)
* - L'ia (IAQLearning)
*
* La classe Player est la seule classe jouable avec les commande :
* w z
* a s d q s d
*
* Les 2 robots ne sont pas la même chose, l'un utilise des principes
* de base et l'autre utilise l'apprentissage par renforcement (il faut
* lui apprendre avant qu'il puisse faire quoi que ce soit)
*
* Vous pouvez tous les appeler en faisant:
* new Player(new int[] {x, y}, "name")
* new Robot("name", new int[] {x, y})
* new IAQLearning(new int[] {x, y}, classe QTable),
*
*/
private static Personnage[] personnages = new Personnage[] {
new Player(new int[] {2, 2}, "Philippe Etchebest"),
new Player(new int[] {map.getGrid()[0].length - 3, map.getGrid().length - 3}, "Luke Skywalker")
};
public static void main(String[] args) { public static void main(String[] args) {
Personnage.n = 4; Personnage.n = 4;
Map map = new Map(12, 22); if (args.length < 1) { new Terminal(map, personnages).run(); } // lancer en local
else if (args.length == 2) { new Terminal(map, personnages).run(args[0], args[1]); } // lancer en ligne
// // lancer en local else { System.err.println("WARNING: vous avez mis un mauvais nombre d'argument"); } // erreur
if (args.length < 2) {
Grid[][] grid = map.getGrid();
// QTable qTable1 = new QTable();
// qTable1.getValues("res" + File.separator + "save" + File.separator + "learn1.ser");
// QTable qTable2 = new QTable();
// 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()
// // 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
Personnage[] personnages = new Personnage[] {
// new IAQLearning(new int[] {2, 2}, qTable1),
new Player(new int[] {2, 2}, "Philippe Etchebest"),
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 IAQLearning(new int[] {grid[0].length - 3, grid.length - 3}, qTable2),
};
// map.addObjectsRandomize(new Item[] {Item.FRAISE, Item.WALL}, 2);
// map.addObjects(Item.FRAISE, 2, 2);
new Terminal(map, personnages).run();
}
// // lancer en ligne
else {
Personnage[] personnages = new Personnage[] {
new Player(new int[] {0, 0}, "Philippe Etchebest"),
};
new Terminal(map, personnages).run(args[0], args[1]);
}
} }
} }

View File

@@ -5,6 +5,8 @@ import personnage.Personnage;
import types.Item; import types.Item;
public class Display { public class Display {
private static int round = 0;
/** /**
* cette fonction clear le terminal et le remet en * cette fonction clear le terminal et le remet en
* haut a gauche de la ligne. * haut a gauche de la ligne.
@@ -60,7 +62,7 @@ public class Display {
} }
} }
public static void printInformation(int round, Personnage personnage) { public static void printInformation(Personnage personnage) {
int[] coordinate = personnage.getHeadCoordinate(); int[] coordinate = personnage.getHeadCoordinate();
System.out.println( System.out.println(
@@ -68,4 +70,8 @@ public class Display {
" (" + coordinate[0]+", "+ coordinate[1] +") | size : " + personnage.getSize() " (" + coordinate[0]+", "+ coordinate[1] +") | size : " + personnage.getSize()
); );
} }
public static void resetRound() {
round = 0;
}
} }

View File

@@ -54,35 +54,19 @@ public class Terminal {
} }
public void run(String channel, String channelAdversaire) { public void run(String channel, String channelAdversaire) {
int i = 0;
Personnage[] personnageChannel = new Personnage[] { Personnage[] personnageChannel = new Personnage[] {
personnages[0], personnages[0],
new Channel(map, channel, channelAdversaire) new Channel(map, channel, channelAdversaire)
}; };
while(true) { loop(personnageChannel, channel);
for(Personnage personnage : personnageChannel) {
Display.clearTerminal();
map.placeObjects();
placePersonnages(personnageChannel);
Display.printInformation(i++, personnage);
Display.printMap(map.addEdges());
if(personnage.round(map, channel)) {
Display.clearTerminal();
System.out.println(personnage.getName() + " à perdu!");
return;
}
map.clearMap();
}
}
} }
public void run() { public void run() {
int i = 0; loop(personnages, null);
}
private void loop(Personnage[] personnages, String channel) {
while(true) { while(true) {
for(Personnage personnage : personnages) { for(Personnage personnage : personnages) {
Display.clearTerminal(); Display.clearTerminal();
@@ -90,12 +74,13 @@ public class Terminal {
map.placeObjects(); map.placeObjects();
placePersonnages(personnages); placePersonnages(personnages);
Display.printInformation(i++, personnage); Display.printInformation(personnage);
Display.printMap(map.addEdges()); Display.printMap(map.addEdges());
if(personnage.round(map, null)) { if(personnage.round(map, channel)) {
Display.clearTerminal(); Display.clearTerminal();
System.out.println(personnage.getName() + " à perdu!"); System.out.println(personnage.getName() + " à perdu!");
Display.resetRound();
return; return;
} }
map.clearMap(); map.clearMap();