diff --git a/app/src/main/java/com/example/mastermind/game/Bot.java b/app/src/main/java/com/example/mastermind/game/Bot.java new file mode 100644 index 0000000..3ae0945 --- /dev/null +++ b/app/src/main/java/com/example/mastermind/game/Bot.java @@ -0,0 +1,60 @@ +package com.example.mastermind.game; + +import java.util.Collection; +import java.util.Deque; +import java.util.LinkedList; +import java.util.Random; + + +/* TODO: Modifs pour GameView : + - création d'un Bot si le mode de jeu est solo + - création d'une méthode redraw(){invalidate()} + - variable qui : + + interdit le switch de state + + demande de verif si victoire au Bot lors des soumissions + + soumet à grille sa notation + */ +public class Bot { + private Integer[] collectionWin; + private Integer pionVide; + private Integer[] pionsNotation; + + public Bot(Collection pionsAutorisés, Integer[] pionsNotation, Integer pionVide){ + this.collectionWin = new Integer[4]; + this.pionVide=pionVide; + this.pionsNotation=pionsNotation; + generationCombiWin(pionsAutorisés); + } + + protected void generationCombiWin(Collection pions){ + Random rand = new Random(); + int nbPions = pions.size(); + Integer[] tabPions=(Integer[]) pions.toArray(); + for (int i=0;i<4;i++){ + this.collectionWin[i]=tabPions[rand.nextInt(nbPions)]; + } + } + + public Collection notation(Integer[] soumission){ + Collection note=new LinkedList(); + for(int i=0; i<4;i++) { + if (this.collectionWin[i] == soumission[i]) { + note.add(this.pionsNotation[1]); + } + } + //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; + for(int i=0; i<4;i++) { + for (int y=0; y<4;y++) { + if (i!=y){ + if (this.collectionWin[y] == soumission[i]){ + note.add(this.pionsNotation[0]); + this.collectionWin[y]=null; + } + } + } + } + + return note; + } +}