|
|
|
@ -5,13 +5,19 @@ namespace CoreLibrary.Joueurs
|
|
|
|
|
{
|
|
|
|
|
public class Robot : Joueur
|
|
|
|
|
{
|
|
|
|
|
private static int nbRobots = 0;
|
|
|
|
|
private static int nbRobots;
|
|
|
|
|
|
|
|
|
|
private List<Code>? codesPossibles;
|
|
|
|
|
|
|
|
|
|
static Robot()
|
|
|
|
|
{
|
|
|
|
|
nbRobots = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Robot() :
|
|
|
|
|
base($"Naps {++nbRobots}")
|
|
|
|
|
base($"Naps {nbRobots + 1}")
|
|
|
|
|
{
|
|
|
|
|
++nbRobots;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Robot(string nom) :
|
|
|
|
@ -25,18 +31,15 @@ namespace CoreLibrary.Joueurs
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (codesPossibles == null)
|
|
|
|
|
{
|
|
|
|
|
codesPossibles = new List<Code>();
|
|
|
|
|
GenererTousCodesPossibles(e.Code.TailleMax);
|
|
|
|
|
}
|
|
|
|
|
codesPossibles = GenererTousCodesPossibles(e.Code.TailleMax);
|
|
|
|
|
|
|
|
|
|
SupprimerCodesImpossibles(e.Plateau);
|
|
|
|
|
SupprimerCodesImpossibles(codesPossibles, e.Plateau);
|
|
|
|
|
|
|
|
|
|
for(int i = 0; i < e.Code.TailleMax; ++i)
|
|
|
|
|
e.Code.AjouterJeton(codesPossibles.ElementAt(0).Jetons[i]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void GenererTousCodesPossibles(int tailleCode)
|
|
|
|
|
private static List<Code> GenererTousCodesPossibles(int tailleCode)
|
|
|
|
|
{
|
|
|
|
|
Couleur[] couleurs = Enum.GetValues<Couleur>();
|
|
|
|
|
int nbLignes = (int)Math.Pow(couleurs.Length, tailleCode);
|
|
|
|
@ -52,6 +55,7 @@ namespace CoreLibrary.Joueurs
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
List<Code> codes = new List<Code>();
|
|
|
|
|
for (int i = 0; i < jetons.GetLength(0); ++i)
|
|
|
|
|
{
|
|
|
|
|
Code code = new Code(tailleCode);
|
|
|
|
@ -59,11 +63,13 @@ namespace CoreLibrary.Joueurs
|
|
|
|
|
{
|
|
|
|
|
code.AjouterJeton(jetons[i, j]!.Value);
|
|
|
|
|
}
|
|
|
|
|
codesPossibles!.Add(code);
|
|
|
|
|
codes!.Add(code);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return codes;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private bool EstCodePossible(Plateau plateau, Code code)
|
|
|
|
|
private static bool EstCodePossible(Plateau plateau, Code code)
|
|
|
|
|
{
|
|
|
|
|
for(int i = 0; i < plateau.Taille; ++i)
|
|
|
|
|
{
|
|
|
|
@ -86,21 +92,21 @@ namespace CoreLibrary.Joueurs
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void SupprimerCodesImpossibles(Plateau plateau)
|
|
|
|
|
private static void SupprimerCodesImpossibles(List<Code> codes, Plateau plateau)
|
|
|
|
|
{
|
|
|
|
|
if (codesPossibles == null)
|
|
|
|
|
if (codes == null)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
List<int> indicesASupprimer = new List<int>();
|
|
|
|
|
|
|
|
|
|
for(int i = codesPossibles.Count - 1; i >= 0; --i)
|
|
|
|
|
for(int i = codes.Count - 1; i >= 0; --i)
|
|
|
|
|
{
|
|
|
|
|
if(!EstCodePossible(plateau, codesPossibles.ElementAt(i)))
|
|
|
|
|
if(!EstCodePossible(plateau, codes.ElementAt(i)))
|
|
|
|
|
indicesASupprimer.Add(i);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach (int indice in indicesASupprimer)
|
|
|
|
|
codesPossibles.RemoveAt(indice);
|
|
|
|
|
codes.RemoveAt(indice);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|