ia fonctionnel et debut ia maui
continuous-integration/drone/push Build is failing Details

master
Céleste BARBOSA 11 months ago
parent f7f4e0c3cb
commit ed108526b2

@ -27,7 +27,6 @@ namespace ConsoleApp
Console.WriteLine();
Joueur joueur = !string.IsNullOrEmpty(nom) ? Program.Manageur.DemanderJoueur(nom) : new Robot();
joueur.JoueurJouer += JoueurJouer;
e.JoueurDemande.SeConnecter(joueur);
}
@ -45,7 +44,7 @@ namespace ConsoleApp
Console.WriteLine("La partie commence, bonne chance à tous !\n");
}
public static void JoueurJouer(object? sender, JoueurJouerEventArgs e)
public static void NouveauTour(object? sender, PartieNouveauTourEventArgs e)
{
Utils.DessinerSeparateur();
@ -76,7 +75,7 @@ namespace ConsoleApp
if (!e.EstJoueur)
{
Task t = Task.Delay(1000);
Task t = Task.Delay(3000);
t.GetAwaiter().GetResult();
}

@ -24,6 +24,7 @@ namespace ConsoleApp
maPartie.PartieDemanderJoueur += Evenements.DemanderNom;
maPartie.PartieDebutPartie += Evenements.CommencerLaPartie;
maPartie.PartieNouveauTour += Evenements.NouveauTour;
maPartie.PartiePasserLaMain += Evenements.AjouterCode;
maPartie.PartiePartieTerminee += Evenements.PartieTerminee;

@ -2,7 +2,7 @@
namespace CoreLibrary.Evenements
{
public class JoueurJouerEventArgs
public class PartieNouveauTourEventArgs : EventArgs
{
public int Tour { get; private init; }
public string Nom { get; private init; }
@ -10,7 +10,7 @@ namespace CoreLibrary.Evenements
public Code Code { get; private init; }
public bool EstJoueur { get; private init; }
public JoueurJouerEventArgs(int tour, string nom, Plateau plateau, Code code, bool estJoueur)
public PartieNouveauTourEventArgs(int tour, string nom, Plateau plateau, Code code, bool estJoueur)
{
Tour = tour;
Nom = nom;

@ -13,10 +13,8 @@ namespace CoreLibrary.Joueurs
public class Joueur : IEstPersistant
{
public event EventHandler<JoueurSeConnecterEventArgs>? JoueurSeConnecter;
public event EventHandler<JoueurJouerEventArgs>? JoueurJouer;
private void QuandJoueurSeConnecter(Joueur joueur) => JoueurSeConnecter?.Invoke(this, new JoueurSeConnecterEventArgs(joueur));
private void QuandJoueurJouer(int tour, string nom, Plateau plateau, Code code, bool estJoueur) => JoueurJouer?.Invoke(this, new JoueurJouerEventArgs(tour, nom, plateau, code, estJoueur));
[DataMember]
private Dictionary<(IRegles, Statistique), int> statistiques = new Dictionary<(IRegles, Statistique), int>();
@ -51,8 +49,6 @@ namespace CoreLibrary.Joueurs
{
if (e.Nom != Nom)
return;
QuandJoueurJouer(e.Tour, e.Nom, e.Plateau, e.Code, e.EstJoueur);
}
public override string ToString() => Nom;

@ -7,6 +7,8 @@ namespace CoreLibrary.Joueurs
{
private static int nbRobots = 0;
private List<Code>? codesPossibles;
public Robot() :
base($"Naps {++nbRobots}")
{
@ -17,10 +19,83 @@ namespace CoreLibrary.Joueurs
if (e.Nom != Nom)
return;
while (!e.Code.Complet)
e.Code.AjouterJeton(new Jeton());
if (codesPossibles == null)
{
codesPossibles = new List<Code>();
GenererTousCodesPossibles(e.Code.TailleMax);
}
SupprimerCodesImpossibles(e.Plateau);
for(int i = 0; i < e.Code.TailleMax; ++i)
e.Code.AjouterJeton(codesPossibles.ElementAt(0).Jetons[i]);
}
private void GenererTousCodesPossibles(int tailleCode)
{
Couleur[] couleurs = Enum.GetValues<Couleur>();
int nbLignes = (int)Math.Pow(couleurs.Length, tailleCode);
Jeton?[,] jetons = new Jeton?[nbLignes, tailleCode];
for(int indiceColonne = 0; indiceColonne < jetons.GetLength(1); ++indiceColonne)
{
int repetition = nbLignes / (int)Math.Pow(couleurs.Length, (indiceColonne + 1));
for (int indiceLigne = 0; indiceLigne < jetons.GetLength(0); ++indiceLigne)
{
jetons[indiceLigne, indiceColonne] = new Jeton(couleurs[(indiceLigne / repetition) % couleurs.Length]);
}
}
for (int i = 0; i < jetons.GetLength(0); ++i)
{
Code code = new Code(tailleCode);
for (int j = 0; j < jetons.GetLength(1); ++j)
{
code.AjouterJeton(jetons[i, j]!.Value);
}
codesPossibles!.Add(code);
}
}
private bool EstCodePossible(Plateau plateau, Code code)
{
for(int i = 0; i < plateau.Taille; ++i)
{
Code sonCode = new Code(code.TailleMax);
for(int j = 0; j < code.TailleMax; ++j)
{
sonCode.AjouterJeton(plateau.Grille.Item1.ElementAt(i).ElementAt(j));
}
IReadOnlyList<Indicateur> indicateurs = sonCode.Comparer(code);
if (
indicateurs.Count(indicateur => indicateur == Indicateur.BonnePlace) != plateau.Grille.Item2.ElementAt(i).Count(indicateur => indicateur == Indicateur.BonnePlace) ||
indicateurs.Count(indicateur => indicateur == Indicateur.BonneCouleur) != plateau.Grille.Item2.ElementAt(i).Count(indicateur => indicateur == Indicateur.BonneCouleur)
)
return false;
}
return true;
}
private void SupprimerCodesImpossibles(Plateau plateau)
{
if (codesPossibles == null)
return;
List<int> indicesASupprimer = new List<int>();
for(int i = codesPossibles.Count - 1; i >= 0; --i)
{
if(!EstCodePossible(plateau, codesPossibles.ElementAt(i)))
indicesASupprimer.Add(i);
}
base.QuandDemanderJoueurJouer(sender, e);
foreach (int indice in indicesASupprimer)
codesPossibles.RemoveAt(indice);
}
}
}

@ -14,12 +14,14 @@ namespace CoreLibrary
public event EventHandler<PartieDemanderJoueurEventArgs>? PartieDemanderJoueur;
public event EventHandler<PartieDebutPartieEventArgs>? PartieDebutPartie;
public event EventHandler<PartieDemanderJoueurJouerEventArgs>? PartieDemanderJoueurJouer;
public event EventHandler<PartieNouveauTourEventArgs>? PartieNouveauTour;
public event EventHandler<PartiePasserLaMainEventArgs>? PartiePasserLaMain;
public event EventHandler<PartiePartieTermineeEventArgs>? PartiePartieTerminee;
private void QuandPartieDemanderJoueur(Joueur joueurDemande) => PartieDemanderJoueur?.Invoke(this, new PartieDemanderJoueurEventArgs(joueurs.Count + 1, joueurDemande));
private void QuandPartieDebutPartie() => PartieDebutPartie?.Invoke(this, new PartieDebutPartieEventArgs());
private void QuandPartieDemanderJoueurJouer() => PartieDemanderJoueurJouer?.Invoke(this, new PartieDemanderJoueurJouerEventArgs(Tour, Joueurs.ElementAt(courant), plateaux.ElementAt(courant), new Code(Regles.TailleCode), joueurs[Joueurs.ElementAt(courant)]));
private void QuandPartieDemanderJoueurJouer(Code code) => PartieDemanderJoueurJouer?.Invoke(this, new PartieDemanderJoueurJouerEventArgs(Tour, Joueurs.ElementAt(courant), plateaux.ElementAt(courant), code, joueurs[Joueurs.ElementAt(courant)]));
private void QuandPartieNouveauTour(Code code) => PartieNouveauTour?.Invoke(this, new PartieNouveauTourEventArgs(Tour, Joueurs.ElementAt(courant), plateaux.ElementAt(courant), code, joueurs[Joueurs.ElementAt(courant)]));
private void QuandPartiePasserLaMain() => PartiePasserLaMain?.Invoke(this, new PartiePasserLaMainEventArgs(Joueurs.ElementAt(courant)));
private void QuandPartiePartieTerminee(IReadOnlyList<string> gagnants, IReadOnlyList<string> perdants) => PartiePartieTerminee?.Invoke(this, new PartiePartieTermineeEventArgs(gagnants, perdants));
@ -55,6 +57,7 @@ namespace CoreLibrary
partie.PartieDemanderJoueur = null;
partie.PartieDebutPartie = null;
partie.PartieDemanderJoueurJouer = null;
partie.PartieNouveauTour = null;
partie.PartiePasserLaMain = null;
partie.PartiePartieTerminee = null;
}
@ -109,7 +112,10 @@ namespace CoreLibrary
private void NouveauTour()
{
QuandPartieDemanderJoueurJouer();
Code code = new Code(Regles.TailleCode);
QuandPartieDemanderJoueurJouer(code);
QuandPartieNouveauTour(code);
}
private void PlateauAjouterCode(object? sender, PlateauAjouterCodeEventArgs e)

@ -6,7 +6,7 @@ namespace CoreLibrary.Regles
public class ReglesClassiques : IRegles
{
public string Nom => "Règles classiques";
public int NbJoueurs => 2;
public int NbJoueurs => 3;
public int NbTour => 12;
public int TailleCode => 4;

@ -1,6 +1,6 @@
[
{
"Nom": "a",
"Nom": "A",
"statistiques": [
{
"Key": {
@ -9,6 +9,15 @@
},
"Item2": 3
},
"Value": 15
},
{
"Key": {
"Item1": {
"__type": "ReglesClassiques:#CoreLibrary.Regles"
},
"Item2": 0
},
"Value": 2
}
]
@ -23,7 +32,7 @@
},
"Item2": 3
},
"Value": 30
"Value": 8
},
{
"Key": {
@ -32,28 +41,59 @@
},
"Item2": 1
},
"Value": 1
}
]
},
{
"Nom": "Pauline",
"statistiques": [
{
"Key": {
"Item1": {
"__type": "ReglesClassiques:#CoreLibrary.Regles"
},
"Item2": 3
},
"Value": 2
}
]
},
{
"Nom": "C",
"statistiques": [ ]
},
"statistiques": [
{
"Nom": "Pauline",
"statistiques": [ ]
"Key": {
"Item1": {
"__type": "ReglesClassiques:#CoreLibrary.Regles"
},
{
"Nom": "b",
"statistiques": [ ]
"Item2": 3
},
"Value": 10
},
{
"Nom": "A",
"statistiques": [ ]
"Key": {
"Item1": {
"__type": "ReglesClassiques:#CoreLibrary.Regles"
},
"Item2": 1
},
"Value": 1
}
]
},
{
"Nom": "B",
"statistiques": [ ]
"Nom": "Camille",
"statistiques": [
{
"Key": {
"Item1": {
"__type": "ReglesClassiques:#CoreLibrary.Regles"
},
"Item2": 3
},
"Value": 1
}
]
}
]

File diff suppressed because it is too large Load Diff

@ -36,10 +36,17 @@
</Grid>
</VerticalStackLayout>
<Grid Grid.Row="2" VerticalOptions="Center" RowDefinitions="*" ColumnDefinitions="*, *">
<Button
VerticalOptions="Center"
Grid.Row="2"
Text="Se connecter"
Clicked="QuandSeConnecterPresse"/>
<Button
Grid.Column="1"
VerticalOptions="Center"
Text="Robot"
Clicked="QuandRobotPresse"/>
</Grid>
</Grid>
</ContentPage>

@ -32,13 +32,26 @@ public partial class ConnexionPage : ContentPage
if (joueurDemande == null || indice == null)
return;
Joueur joueur;
if (string.IsNullOrEmpty(Nom.Text))
{
joueurDemande.SeConnecter(new Joueur($"Joueur {indice.Value}"));
joueur = new Joueur($"Joueur {indice.Value}");
}
else
{
joueurDemande.SeConnecter(MauiProgram.Manageur.DemanderJoueur(Nom.Text));
joueur = MauiProgram.Manageur.DemanderJoueur(Nom.Text);
}
joueurDemande.SeConnecter(joueur);
}
private void QuandRobotPresse(object sender, EventArgs e)
{
if (joueurDemande == null || indice == null)
return;
Robot robot = new Robot();
joueurDemande.SeConnecter(robot);
}
}

@ -22,8 +22,8 @@ public partial class ModePage : ContentPage
return;
partie.PartieDemanderJoueur += new ConnexionPage().QuandDemanderNom;
partie.PartieNouveauTour += new PlateauPage().QuandNouveauTour;
partie.PartiePartieTerminee += new VictoirePage().QuandPartieTerminee;
partie.PartieNouveauTour += new PlateauPage().QuandNouveauTour;
partie.Jouer();
}

@ -1,7 +1,6 @@
using CoreLibrary.Core;
using CoreLibrary.Evenements;
using CoreLibrary.Exceptions;
using CoreLibrary.Joueurs;
namespace MauiSpark.Pages;
@ -15,7 +14,7 @@ internal class Tour
public Tour(PartieNouveauTourEventArgs e)
{
Numero = $"Tour {e.Tour}";
Joueur = e.Joueur;
Joueur = e.Nom;
Code = e.Code;
(IReadOnlyList<IReadOnlyList<Jeton>> jetons, IReadOnlyList < IReadOnlyList < Indicateur >> indicateurs) = e.Plateau.Grille;

@ -47,8 +47,8 @@ public partial class PartieCommenceeVue : ContentView, INotifyPropertyChanged
Partie partie = MauiProgram.Manageur.ChargerPartie(Partie);
partie.PartieDemanderJoueur += new ConnexionPage().QuandDemanderNom;
partie.PartieNouveauTour += new PlateauPage().QuandNouveauTour;
partie.PartiePartieTerminee += new VictoirePage().QuandPartieTerminee;
partie.PartieNouveauTour += new PlateauPage().QuandNouveauTour;
partie.Jouer();
}

Loading…
Cancel
Save