From 015ce30b42c0884d996de1b6071f7ff02d6c2c2e Mon Sep 17 00:00:00 2001 From: Cpt-Adok Date: Sat, 25 May 2024 13:37:57 +0200 Subject: [PATCH] =?UTF-8?q?Robot=20teub=C3=A9=20mais=20marche=20bien,=20ma?= =?UTF-8?q?rche=20tr=C3=A8s=20bien=20en=20local=20mais=20probl=C3=A8me=20e?= =?UTF-8?q?n=20r=C3=A9seau?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Personnages/Robot.java | 73 ++++++++++++-------------------------- 1 file changed, 22 insertions(+), 51 deletions(-) diff --git a/src/Personnages/Robot.java b/src/Personnages/Robot.java index f6caf4f..acbbcf3 100644 --- a/src/Personnages/Robot.java +++ b/src/Personnages/Robot.java @@ -17,15 +17,16 @@ public class Robot extends Personnage { super(coordinate); this.name = name; this.m=m; - move=this.compare(this.getHeadCoordinate(), this.choix().get(0)); } @Override public boolean round(Map map, String channel){ - System.out.println("Est-ce que ça passe par là au moins ?"); + System.out.println(this.choix().size()+ " move : "+this.compare(this.getHeadCoordinate(), this.choix().get(0))); + this.move=this.compare(this.getHeadCoordinate(), this.choix().get(0)); + int[] coordinate = this.getHeadCoordinate(); - if (channel != null) Channel.envoyerMessage(this.getMove()); + if (channel != null) Channel.envoyerMessage(this.move); if(map.isGameOver(coordinate) || this.applyEffects(map.getEffect(coordinate))) return true; @@ -43,13 +44,15 @@ public class Robot extends Personnage { public boolean estPossible(int x,int y){ Object [][] grille=this.m.getGrid(); - //System.out.println(x+" <= x , length grille : "+(grille.length-1)+" "+y+"<= y , length grille [0] : "+(grille[0].length-1)); - if (x>grille.length-1 || y>grille[0].length-1){ - return false; - } else if (grille[x][y]==Effect.IMPASSABLE){ - return false; + if (x>=0 && x=0 && y casesAutour(){ - ArrayList t =this.coupsPossibles(this.getCoordinate().get(0)); - ArrayList t2 = new ArrayList<> (); - for (int i=0;i fusion(ArrayList t, ArrayList t2){ for (int [] e :t2){ t.add(e); @@ -97,27 +82,21 @@ public class Robot extends Personnage { } public ArrayList choix(){ - ArrayList cases=casesAutour(); - ArrayList > w=new ArrayList<>(); - for (int i=0;i max=w.get(0); - for (ArrayList e :w){ - if (e.size()>max.size()){ - max=e; - } - } - if (w.size()==0){ + Random r=new Random(); + ArrayList cases=coupsPossibles(this.getHeadCoordinate()); + if (cases.size()==0){ return this.suicide(cases); } - return max; + int [] choix=cases.get(r.nextInt(cases.size())); + ArrayList choisi =new ArrayList(); + choisi.add(choix); + return choisi; } public ArrayList suicide(ArrayList murs){ Random r=new Random(); ArrayList a=new ArrayList<> (); - a.add(murs.get(r.nextInt(murs.size()))); + a.add(murs.get(r.nextInt(4))); return a; } @@ -130,9 +109,8 @@ public class Robot extends Personnage { return Mouvement.GAUCHE; }else if (t[1]>t2[1]){ return Mouvement.DROITE; - }else if (t[0]==t2[0] || t[1]==t2[1]){ - return moveRandom(); } + System.out.println("Problème Robot.compare"); return null; } @@ -141,18 +119,11 @@ public class Robot extends Personnage { for (int j=i;j