-------------------------------------------------------------- -- Puissance 4 / Connect4 -- -- Jessy GAUTRAND, Pascal MIETLICKI, Romain SCHMITT -- INSA, Departement Genie Informatique -- -- mailto:kalumail@yahoo.fr -- -- This is free software; you can redistribute it and/or -- modify without restriction. This software is under LGPL licence -- -- This software is distributed in the hope that it will be useful, -- but WITHOUT ANY WARRANTY; without even the implied warranty -- of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. -- -- console program to test the whole program (with no graphic interface) -------------------------------------------------------------- With Ada.Text_Io, Ada.Integer_Text_Io, Ada.strings, Puissance4, calculia; use Ada.Text_Io, Ada.Integer_Text_Io, Ada.strings, Puissance4, calculia; --IA mise en place avec difficulte de 1 2 ou 3 procedure ppal is Plateau: Type_Tableau_Plateau; subtype type_difficulte is integer range 1..3; difficulte:type_difficulte:=1; profondeur:natural:=0; val:natural:=1; subtype type_menu is integer range 1..3; choix_menu:type_menu:=1; note_col:natural:=0; ligne:natural:=0; gagne:boolean:=false; subtype type_choix_aide is integer range 0..1; choix_aide : type_choix_aide:=0; Match_Nul: boolean:=false; -- D�lai d'attente pour rendre le programme plus interactif attente: duration:=1.0; --diff : Type_Profondeur; colonne : integer; begin loop declare begin Put("----------------Bienvenue sur le jeu Puissance4---------------"); new_line; Put("1. Jeu Joueur contre l'ordinateur"); new_line; Put("2. Jeu Joueur contre Joueur"); new_line; Put("3. Quitter"); new_line; Get(choix_menu); if choix_menu = 3 then put_line("Vous quittez"); return; end if; exit when choix_menu=1 or choix_menu=2; exception -- Si l'utilisateur ne rentre pas un bon chiffre, on recommence la saisie when DATA_ERROR => skip_line; Put_Line("Un entier S.V.P! "); when Exc_Colonne_Pleine => skip_line; Put_Line("Colonne pleine! recommencez..."); when CONSTRAINT_ERROR => skip_line; Put_Line("Entrez une valeur correcte!..."); when OTHERS => skip_line; Put_Line("Autre erreur! "); end; end loop; loop declare begin exit when choix_menu=2; if choix_menu = 1 then put("Choisissez la difficulte : "); new_line; put("Facile : 1"); new_line; put("Moyen : 2"); new_line; put("Difficile : 3"); new_line; Get(difficulte); case difficulte is when 1 => profondeur:=3; when 2 => profondeur:=4; when 3 => profondeur:=5; when others => null;--?.?????????????????????????????? end case; exit when difficulte=1 or difficulte=2 or difficulte=3; end if; exception when -- Si l'utilisateur ne rentre pas un bon chiffre, on recommence la saisie DATA_ERROR => skip_line; Put_Line("Un entier S.V.P! "); when Exc_Colonne_Pleine => skip_line; Put_Line("Colonne pleine! recommencez..."); when CONSTRAINT_ERROR => skip_line; Put_Line("Entrez une valeur correcte!..."); when OTHERS => skip_line; Put_Line("Autre erreur! "); end; end loop; Initialiser_Plateau(Plateau); Dessiner_Plateau(Plateau); new_line; --put("quelle difficulte?"); --get(diff); -- Si difficulte = 1 => si le joueur suit l'aide � la lettre, il gagne -- Si difficulte = 2 => si le joueur suit l'aide � la lettre, il gagne aussi... while val/=0 and not gagne and not Match_Nul loop for Joueur in 1..2 loop loop declare -- pour traiter l'exception sur le champ c'est � dire tout de suite -- et non en fin de proc�dure, il faut utiliser un bloc qui poss�de un end begin --Put(Joueur,1); if Joueur = 1 then Put("Joueur "); Put(" | Voulez-vous de l'aide? (0 pour Non, 1 pour Oui)"); Get(choix_aide); if choix_aide=1 then Affichage_Coups_Trouves(Utilisateur,Plateau); end if; Put(": Sur quelle colonne voulez-vous jouer? (0 pr sortir) "); Get(val); exit when val=0; Placer_Jeton(Plateau, val, ligne, Utilisateur); else --**********************Jeu contre l'ordinateur********************-- if choix_menu = 1 then --***************MISE EN PLACE DE L'IA*******************-- --3 : facile 4: moyen 7:difficile (profondeur de l'arbre) Tour_Ordinateur(Plateau,colonne,profondeur); Placer_Jeton(Plateau, Colonne, ligne, Ordinateur); else Put("Joueur "); Put(" | Voulez-vous de l'aide? (0 pour Non, 1 pour Oui)"); Get(choix_aide); if choix_aide=1 then Affichage_Coups_Trouves(Utilisateur,Plateau); end if; Put(": Sur quelle colonne voulez-vous jouer? (0 pr sortir) "); Get(val); exit when val=0; Placer_Jeton(Plateau, val, ligne, Ordinateur); end if; end if; if ligne=0 then raise Exc_Colonne_Pleine; end if; exit; exception when -- Si l'utilisateur ne rentre pas un bon chiffre, on recommence la saisie DATA_ERROR => skip_line; Put_Line("Un entier S.V.P! "); when Exc_Colonne_Pleine => skip_line; Put_Line("Colonne pleine! recommencez..."); when CONSTRAINT_ERROR => skip_line; Put_Line("Entrez une valeur correcte!..."); when OTHERS => skip_line; Put_Line("Autre erreur! "); end; end loop; exit when val=0; Verifier_Gagnant(Plateau, Utilisateur, Gagne); if Gagne then Put_Line("-----------------"); Put_line("Joueur 1 a gagne! :"); Put_Line("-----------------"); delay(attente); Dessiner_Plateau(Plateau); exit; end if; Verifier_Gagnant(Plateau, Ordinateur, Gagne); if Gagne then Put_Line("-----------------"); Put_line("Joueur 2 a gagne! :"); Put_Line("-----------------"); delay(attente); Dessiner_Plateau(Plateau); exit; end if; Verifier_Nul(Plateau, Match_Nul); if Match_Nul then Put_Line("-----------------"); Put_line("Match Nul! :"); Put_Line("-----------------"); delay(attente); Dessiner_Plateau(Plateau); exit; end if; Dessiner_Plateau(Plateau); new_line; end loop; end loop; end ppal;