Merge branch 'miseEnPlaceBot' pour le mode solo

This commit is contained in:
Haïssous Kayyissa 2023-04-06 21:57:21 +02:00
commit 402db64b6b

View File

@ -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<Integer> pionsAutorisés, Integer[] pionsNotation, Integer pionVide){
this.collectionWin = new Integer[4];
this.pionVide=pionVide;
this.pionsNotation=pionsNotation;
generationCombiWin(pionsAutorisés);
}
protected void generationCombiWin(Collection<Integer> 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<Integer> notation(Integer[] soumission){
Collection<Integer> note=new LinkedList<Integer>();
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;
}
}