static bool[] CreerTasAllumettes(int taille)
bool[] tabbool = new bool[taille];
for (int i = 0; i < taille; i++)
static void AfficherTasAllumettes(bool[] tasAllumettes)
for (int i = 1; i < tasAllumettes.Length + 1; i++)
Console.Write(" " + i + " ");
for (int i = 0; i < tasAllumettes.Length + 9; i++)
for (int i = 0; i < tasAllumettes.Length; i++)
if (tasAllumettes[i] == true)
for (int i = 0; i < tasAllumettes.Length + 9; i++)
bool[] allumettes = CreerTasAllumettes(12);
AfficherTasAllumettes(allumettes);
AfficherTasAllumettes(allumettes);
static bool PositionValide(bool[] tableau, int index)
if (index >= 0 && index < tableau.Length)
static bool RetirerUneAllumette(bool[] tasAllumettes, int index)
bool boul = PositionValide(tasAllumettes, index);
tasAllumettes[index] = false;
static int NombreAllumettesRestantes(bool[] tasAllumettes)
if (tasAllumettes != null || tasAllumettes.Length != 0)
for (int i = 0; i < tasAllumettes.Length; i++)
if (tasAllumettes[i] == true)
static int DemanderNombreAllumettesARetirer(int max)
Console.WriteLine("Veuillez rentrer le nombre d'allumettes a retirer");
int nombre = Convert.ToInt32(Console.ReadLine());
while( nombre<1 && nombre > max )
Console.WriteLine("Veuillez rentrer à nouveau le nombre d'allumettes a retirer");
nombre = Convert.ToInt32(Console.ReadLine());
static bool PartieGagnee(bool[] tasAllumettes)
int nombre = NombreAllumettesRestantes(tasAllumettes);
static bool PartiePerdue(bool[] tasAllumettes)
int nombre = NombreAllumettesRestantes(tasAllumettes);
static bool FinPartie(bool[] tasAllumettes)
bool gagne = PartieGagnee(tasAllumettes);
bool perdue = PartiePerdue(tasAllumettes);
if ( gagne == true || perdue == true)
bool[] allumettes = CreerTasAllumettes( 8 );
AfficherTasAllumettes(allumettes);
while( ! FinPartie(allumettes) )
noJoueur = (noJoueur % 2) + 1;
Console.Write("C’est au tour du joueur ");
Console.WriteLine(noJoueur);
int nombreAllumettes= DemanderNombreAllumettesARetirer(3);
Console.WriteLine("saisir la position ou prendre l'allumettes");
for ( int i=0; i< nombreAllumettes; i++)
int position = Convert.ToInt32(Console.ReadLine());
boul = RetirerUneAllumette(allumettes, position-1);
AfficherTasAllumettes(allumettes);
AfficherTasAllumettes(allumettes);
Console.Write("Le joueur ");
if( PartieGagnee(allumettes) )
Console.WriteLine(" a gagné !");
Console.WriteLine(" a perdu :-(");
public static void Main()