mirror of
https://github.com/Cpt-Adok/SNAKE.git
synced 2026-01-25 09:34:06 +00:00
changement de plusieurs fonction
This commit is contained in:
@@ -7,45 +7,38 @@ import personnage.*;
|
||||
import tests.IATest;
|
||||
|
||||
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) {
|
||||
Personnage.n = 4;
|
||||
|
||||
Map map = new Map(12, 22);
|
||||
|
||||
// // lancer en local
|
||||
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]);
|
||||
}
|
||||
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
|
||||
else { System.err.println("WARNING: vous avez mis un mauvais nombre d'argument"); } // erreur
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,8 @@ import personnage.Personnage;
|
||||
import types.Item;
|
||||
|
||||
public class Display {
|
||||
private static int round = 0;
|
||||
|
||||
/**
|
||||
* cette fonction clear le terminal et le remet en
|
||||
* 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();
|
||||
|
||||
System.out.println(
|
||||
@@ -68,4 +70,8 @@ public class Display {
|
||||
" (" + coordinate[0]+", "+ coordinate[1] +") | size : " + personnage.getSize()
|
||||
);
|
||||
}
|
||||
|
||||
public static void resetRound() {
|
||||
round = 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -54,35 +54,19 @@ public class Terminal {
|
||||
}
|
||||
|
||||
public void run(String channel, String channelAdversaire) {
|
||||
int i = 0;
|
||||
Personnage[] personnageChannel = new Personnage[] {
|
||||
personnages[0],
|
||||
new Channel(map, channel, channelAdversaire)
|
||||
};
|
||||
|
||||
while(true) {
|
||||
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();
|
||||
}
|
||||
}
|
||||
loop(personnageChannel, channel);
|
||||
}
|
||||
|
||||
public void run() {
|
||||
int i = 0;
|
||||
loop(personnages, null);
|
||||
}
|
||||
|
||||
private void loop(Personnage[] personnages, String channel) {
|
||||
while(true) {
|
||||
for(Personnage personnage : personnages) {
|
||||
Display.clearTerminal();
|
||||
@@ -90,12 +74,13 @@ public class Terminal {
|
||||
map.placeObjects();
|
||||
placePersonnages(personnages);
|
||||
|
||||
Display.printInformation(i++, personnage);
|
||||
Display.printInformation(personnage);
|
||||
Display.printMap(map.addEdges());
|
||||
|
||||
if(personnage.round(map, null)) {
|
||||
if(personnage.round(map, channel)) {
|
||||
Display.clearTerminal();
|
||||
System.out.println(personnage.getName() + " à perdu!");
|
||||
Display.resetRound();
|
||||
return;
|
||||
}
|
||||
map.clearMap();
|
||||
|
||||
Reference in New Issue
Block a user