From db5dfdb21b36e6b98ab898b18f83170f5a61da5b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kayyissa=20HA=C3=8FSSOUS?= Date: Sat, 8 Apr 2023 10:12:57 +0200 Subject: [PATCH] algo de notation du bot ok (normalement(j'espere)) --- .../java/com/example/mastermind/game/Bot.java | 43 +++++++++++++++---- 1 file changed, 34 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/com/example/mastermind/game/Bot.java b/app/src/main/java/com/example/mastermind/game/Bot.java index f9bb822..9352c10 100644 --- a/app/src/main/java/com/example/mastermind/game/Bot.java +++ b/app/src/main/java/com/example/mastermind/game/Bot.java @@ -36,25 +36,50 @@ public class Bot { public Integer[] notation(Integer[] soumission){ LinkedList note=new LinkedList<>(); + Integer[] copyCombi = new Integer[4]; + System.arraycopy(this.collectionWin, 0, copyCombi, 0,4); + + //noirs for(int i=0; i<4;i++) { - if (this.collectionWin[i]==soumission[i]) { + if (copyCombi[i]==soumission[i]) { note.add(this.pionsNotation[1]); - System.out.println(note.getLast()+" good"); + copyCombi[i]=-1; + System.out.println(note.getLast()+" good "+i); } } - //On crée une copie de la combinaison gagnante pour la modifier et éviter la fausse répétition de pions blancs - Integer[] copyCombi = this.collectionWin; + + //blancs for(int i=0; i<4;i++) { - for (int y=0; y<4;y++) { - if (i!=y){ - if (copyCombi[y] == soumission[i]){ + if(copyCombi[i]!=-1){ + for (int y=0;y<4;y++){ + if (soumission[y]==copyCombi[i]) { note.add(this.pionsNotation[0]); - System.out.println(note.getLast()+" almost"); - copyCombi[y]=null; + System.out.println(note.getLast() + " almost "+i); + copyCombi[i] = -1; } } } } + + + /* Integer[] copyCombi = new Integer[4]; + System.arraycopy(this.collectionWin, 0, copyCombi, 0,4); + for(int i=0; i<4;i++) { + for(int y=0;y<4;y++){ + if(i==y&&soumission[i]==copyCombi[y]){ + note.add(this.pionsNotation[1]); + System.out.println(note.getLast()+" good"); + copyCombi[y]=-1; + break; + } else if (soumission[i]==copyCombi[y]){ + note.add(this.pionsNotation[0]); + System.out.println(note.getLast()+" almost"); + copyCombi[y]=-1; + break; + } + } + }*/ + // On complête avec des cases vides while (note.size()<4){ note.addLast(this.pionVide);