From b9c926f4933a96864d01d8a1d2c45c73752a858d Mon Sep 17 00:00:00 2001 From: James Boutaric Date: Thu, 9 Oct 2025 10:20:53 +0200 Subject: [PATCH] ajout TP3 --- .DS_Store | Bin 0 -> 6148 bytes README.md | 95 --------- TP1&TP2/MIniMax_versionprofondeur.class | Bin 0 -> 800 bytes TP1&TP2/MIniMax_versionprofondeur.java | 42 ++++ TP1&TP2/MiniMax_versionBase.class | Bin 0 -> 737 bytes TP1&TP2/MiniMax_versionBase.java | 35 +++ TP1&TP2/MiniMax_versionMemoisation.class | Bin 0 -> 1487 bytes TP1&TP2/MiniMax_versionMemoisation.java | 59 ++++++ TP1&TP2/MiniMax_version_AlphaBeta.class | Bin 0 -> 833 bytes TP1&TP2/MiniMax_version_AlphaBeta.java | 41 ++++ TP1&TP2/MiniMax_versionarret.class | Bin 0 -> 771 bytes TP1&TP2/MiniMax_versionarret.java | 41 ++++ TP1&TP2/Readme.md | 97 +++++++++ .../MIniMax_versionprofondeur_compteur.class | Bin 0 -> 948 bytes .../MIniMax_versionprofondeur_compteur.java | 47 +++++ .../MiniMax_versionBase_compteur.class | Bin 0 -> 886 bytes .../MiniMax_versionBase_compteur.java | 40 ++++ .../MiniMax_versionMemoisation_compteur.class | Bin 0 -> 1583 bytes .../MiniMax_versionMemoisation_compteur.java | 63 ++++++ .../MiniMax_version_AlphaBeta_compteur.class | Bin 0 -> 982 bytes .../MiniMax_version_AlphaBeta_compteur.java | 46 ++++ .../MiniMax_versionarret_compteur.class | Bin 0 -> 920 bytes .../MiniMax_versionarret_compteur.java | 46 ++++ .../MiniMax_version_AlphaBeta_melange.class | Bin 0 -> 1518 bytes .../MiniMax_version_AlphaBeta_melange.java | 50 +++++ ...x_version_AlphaBeta_melange_compteur.class | Bin 0 -> 1620 bytes ...ax_version_AlphaBeta_melange_compteur.java | 54 +++++ TP1/Minimax.class | Bin 809 -> 0 bytes TP1/MinimaxAlphaBeta.java | 58 ----- TP1/MinimaxMemo.class | Bin 1542 -> 0 bytes TP1/MinimaxMemo.java | 43 ---- TP1/MinimaxProfondeur.class | Bin 1530 -> 0 bytes TP1/MinimaxProfondeur.java | 41 ---- TP1/MinimaxSimple.class | Bin 1283 -> 0 bytes TP1/MinimaxSimple.java | 33 --- TP1/MinimaxStop.class | Bin 1310 -> 0 bytes TP1/MinimaxStop.java | 34 --- TP3/fr/iut_fbleau/GameAPI/AbstractBoard.class | Bin 0 -> 1329 bytes TP3/fr/iut_fbleau/GameAPI/AbstractBoard.java | 99 +++++++++ .../GameAPI/AbstractGamePlayer.class | Bin 0 -> 372 bytes .../GameAPI/AbstractGamePlayer.java | 26 +++ TP3/fr/iut_fbleau/GameAPI/AbstractPly.class | Bin 0 -> 268 bytes TP3/fr/iut_fbleau/GameAPI/AbstractPly.java | 5 + TP3/fr/iut_fbleau/GameAPI/IBoard.class | Bin 0 -> 525 bytes TP3/fr/iut_fbleau/GameAPI/IBoard.java | 69 ++++++ TP3/fr/iut_fbleau/GameAPI/Player.class | Bin 0 -> 998 bytes TP3/fr/iut_fbleau/GameAPI/Player.java | 6 + TP3/fr/iut_fbleau/GameAPI/Result.class | Bin 0 -> 1042 bytes TP3/fr/iut_fbleau/GameAPI/Result.java | 11 + TP3/fr/iut_fbleau/Nim/NimBoard.class | Bin 0 -> 3776 bytes TP3/fr/iut_fbleau/Nim/NimBoard.java | 199 ++++++++++++++++++ TP3/fr/iut_fbleau/Nim/NimBotPlayer.class | Bin 0 -> 3000 bytes TP3/fr/iut_fbleau/Nim/NimBotPlayer.java | 166 +++++++++++++++ TP3/fr/iut_fbleau/Nim/NimGame.class | Bin 0 -> 3030 bytes TP3/fr/iut_fbleau/Nim/NimGame.java | 79 +++++++ TP3/fr/iut_fbleau/Nim/NimPlayer.class | Bin 0 -> 2620 bytes TP3/fr/iut_fbleau/Nim/NimPlayer.java | 66 ++++++ TP3/fr/iut_fbleau/Nim/NimPly.class | Bin 0 -> 1203 bytes TP3/fr/iut_fbleau/Nim/NimPly.java | 38 ++++ test | 0 60 files changed, 1425 insertions(+), 304 deletions(-) create mode 100644 .DS_Store delete mode 100644 README.md create mode 100644 TP1&TP2/MIniMax_versionprofondeur.class create mode 100644 TP1&TP2/MIniMax_versionprofondeur.java create mode 100644 TP1&TP2/MiniMax_versionBase.class create mode 100644 TP1&TP2/MiniMax_versionBase.java create mode 100644 TP1&TP2/MiniMax_versionMemoisation.class create mode 100644 TP1&TP2/MiniMax_versionMemoisation.java create mode 100644 TP1&TP2/MiniMax_version_AlphaBeta.class create mode 100644 TP1&TP2/MiniMax_version_AlphaBeta.java create mode 100644 TP1&TP2/MiniMax_versionarret.class create mode 100644 TP1&TP2/MiniMax_versionarret.java create mode 100644 TP1&TP2/Readme.md create mode 100644 TP1&TP2/compteur/MIniMax_versionprofondeur_compteur.class create mode 100644 TP1&TP2/compteur/MIniMax_versionprofondeur_compteur.java create mode 100644 TP1&TP2/compteur/MiniMax_versionBase_compteur.class create mode 100644 TP1&TP2/compteur/MiniMax_versionBase_compteur.java create mode 100644 TP1&TP2/compteur/MiniMax_versionMemoisation_compteur.class create mode 100644 TP1&TP2/compteur/MiniMax_versionMemoisation_compteur.java create mode 100644 TP1&TP2/compteur/MiniMax_version_AlphaBeta_compteur.class create mode 100644 TP1&TP2/compteur/MiniMax_version_AlphaBeta_compteur.java create mode 100644 TP1&TP2/compteur/MiniMax_versionarret_compteur.class create mode 100644 TP1&TP2/compteur/MiniMax_versionarret_compteur.java create mode 100644 TP1&TP2/version_liste_melange/MiniMax_version_AlphaBeta_melange.class create mode 100644 TP1&TP2/version_liste_melange/MiniMax_version_AlphaBeta_melange.java create mode 100644 TP1&TP2/version_liste_melange/MiniMax_version_AlphaBeta_melange_compteur.class create mode 100644 TP1&TP2/version_liste_melange/MiniMax_version_AlphaBeta_melange_compteur.java delete mode 100644 TP1/Minimax.class delete mode 100644 TP1/MinimaxAlphaBeta.java delete mode 100644 TP1/MinimaxMemo.class delete mode 100644 TP1/MinimaxMemo.java delete mode 100644 TP1/MinimaxProfondeur.class delete mode 100644 TP1/MinimaxProfondeur.java delete mode 100644 TP1/MinimaxSimple.class delete mode 100644 TP1/MinimaxSimple.java delete mode 100644 TP1/MinimaxStop.class delete mode 100644 TP1/MinimaxStop.java create mode 100644 TP3/fr/iut_fbleau/GameAPI/AbstractBoard.class create mode 100644 TP3/fr/iut_fbleau/GameAPI/AbstractBoard.java create mode 100644 TP3/fr/iut_fbleau/GameAPI/AbstractGamePlayer.class create mode 100644 TP3/fr/iut_fbleau/GameAPI/AbstractGamePlayer.java create mode 100644 TP3/fr/iut_fbleau/GameAPI/AbstractPly.class create mode 100644 TP3/fr/iut_fbleau/GameAPI/AbstractPly.java create mode 100644 TP3/fr/iut_fbleau/GameAPI/IBoard.class create mode 100644 TP3/fr/iut_fbleau/GameAPI/IBoard.java create mode 100644 TP3/fr/iut_fbleau/GameAPI/Player.class create mode 100644 TP3/fr/iut_fbleau/GameAPI/Player.java create mode 100644 TP3/fr/iut_fbleau/GameAPI/Result.class create mode 100644 TP3/fr/iut_fbleau/GameAPI/Result.java create mode 100644 TP3/fr/iut_fbleau/Nim/NimBoard.class create mode 100644 TP3/fr/iut_fbleau/Nim/NimBoard.java create mode 100644 TP3/fr/iut_fbleau/Nim/NimBotPlayer.class create mode 100644 TP3/fr/iut_fbleau/Nim/NimBotPlayer.java create mode 100644 TP3/fr/iut_fbleau/Nim/NimGame.class create mode 100644 TP3/fr/iut_fbleau/Nim/NimGame.java create mode 100644 TP3/fr/iut_fbleau/Nim/NimPlayer.class create mode 100644 TP3/fr/iut_fbleau/Nim/NimPlayer.java create mode 100644 TP3/fr/iut_fbleau/Nim/NimPly.class create mode 100644 TP3/fr/iut_fbleau/Nim/NimPly.java delete mode 100644 test diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..e0292d259ec6035f979b289895e86a91f8381400 GIT binary patch literal 6148 zcmZQzU|@7AO)+F(5MW?n;9!8zEL;p&0Z1N%F(jFwA|QQ?ATvC3@{^Nt@{^zjL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oi51;N%wQKS!sjAU1{MY}1~vu>22c{@VUT9vV~}AGWsqf1 zV31=_V~}UiWRPLdXHY_R5i`_9oD2dCg3v%RWngAtW?*0t7}OY;7}Ob988jFK7&I9e8HB)LBn$vn_Kg$( literal 0 HcmV?d00001 diff --git a/TP1&TP2/MIniMax_versionprofondeur.java b/TP1&TP2/MIniMax_versionprofondeur.java new file mode 100644 index 0000000..183fa16 --- /dev/null +++ b/TP1&TP2/MIniMax_versionprofondeur.java @@ -0,0 +1,42 @@ +public class MIniMax_versionprofondeur { + + private static int ExploreMax(int nbr_allumettes, int profondeur){ + if (nbr_allumettes <= 0){ + return 1; + } + if (profondeur == 0){ + return 0; + } + int meilleurres = -2; + for (int coup = 1; coup <= 3; coup++){ + int res = ExploreMin(nbr_allumettes - coup, profondeur - coup); + if (res > meilleurres){ + meilleurres = res; + } + } + return meilleurres; + } + + private static int ExploreMin(int nbr_allumettes, int profondeur){ + if (nbr_allumettes <= 0){ + return -1; + } + if (profondeur == 0){ + return 0; + } + int pire = 2; + for (int coup = 1; coup <= 3; coup++){ + int res = ExploreMax(nbr_allumettes - coup, profondeur - coup); + if (res < pire){ + pire = res; + } + } + return pire; + } + + public static void main(String[] args) { + int nbr_allumettes = 5; + int profondeur = 6; + System.out.println(ExploreMax(nbr_allumettes, profondeur)); + } +} \ No newline at end of file diff --git a/TP1&TP2/MiniMax_versionBase.class b/TP1&TP2/MiniMax_versionBase.class new file mode 100644 index 0000000000000000000000000000000000000000..55774f0e5c154afe58c6123ba2314352f2e6b36f GIT binary patch literal 737 zcmX^0Z`VEs1_pBmWiAGG1`#d>HU?1;A;!rd&LF|XAju%b&LGXsAj8POW|NthSz^b? zz^tJe#>l|poS%})$iVNDnV0HUnwykb6q1;flgh}zB-2z z8(fl@ob8)ffUYJpkCA~THxWdMX+-;EC6*=X=OpH(>j#$-X#>2qDz{$hF&%n#Wz{9}H&LGRfAjcrj&Y-}< zpva)a$RLbGCnJLZNH4@n|D>$c9N`gy@ zQWJBn85xAZW}pf)GO!nb6y<*_n#;h-vPR&a4U4S|+hPWB zDVdZV3`};i(n}avWo=rR7?=NlCB24$fq@BZmKp;m0|NsK0}BHy*b$rz91H>speW{I zkYV6vkYnIrP+{O>;A3E5;9+24`^&(>$SCxSft7&^6rfPs^P#q@f^276!-`@#vz@H; zB0QE0F|aTQgHjg*2ZI;`KZ7`f7=r|ZG=n6AEQ1(>GJ_0~<;+maIT-{P1fiDeGB7bP uF)%Rja@cHQV3FRzz`Tut6%kr|49pA+3 meilleurres){ + meilleurres = res; + } + } + return meilleurres; + } + + private static int ExploreMin(int nbr_allumettes){ + if (nbr_allumettes <= 0){ + return -1; + } + int pire = 2; + for (int coup = 1; coup <= 3; coup++){ + int res = ExploreMax(nbr_allumettes - coup); + if (res < pire){ + pire = res; + } + } + return pire; + } + + public static void main(String[] args) { + int nbr_allumettes = 5; + System.out.println(ExploreMax(nbr_allumettes)); + } +} \ No newline at end of file diff --git a/TP1&TP2/MiniMax_versionMemoisation.class b/TP1&TP2/MiniMax_versionMemoisation.class new file mode 100644 index 0000000000000000000000000000000000000000..465314fb8a3ac935506c45ac1a863c914396a1d3 GIT binary patch literal 1487 zcmX^0Z`VEs1_pBmA1(%A22D-|UIr}?q0Pm>!Jxy%AjqH#;_87|`s@q_AYnr;23`gu zkccseWx~#23Zl(88O#|hxEL%Mtk@Z>LDHJ+3^t4m%(;mbj0~baS&3zd`lThAIr@%8 zMTwO@nZ+g6j0~K?ndy0nC8b5Fj0{@X)Yw1-a}x8?^*!@SQqxn5tnI8p#%AU*GH^KN zXoT(KBIr&AtAg6-#dNMM=gh1A?*94aoW#*+@gY4n3 zNzQ@V%&Y+t;0n$!ElN&x%LG{_@0*#I>6=&)UzS=_oSC2Jo0^-SS)5psnV+Wz3Kbp( zX$CbO21y1f9tIHxQ62_c20I=Gdj?PK@g-;A2}F!7@Qegco>uz6nPk2 z8Qgdn6c`j48KiJq2C_$noxz=l!Gpn*oxzKT!J9#bkwF-2GHT2)G6;Z0!S?wlWu+#U zFfy>0CFYc-`lm56h-r9gB83DjUKkme6H`(c8ALUZBq6%3HKQ0AnA1~BK(Z*Bq4JCj z9GQ6~VIUhA8JIORJsBC8i$TiOH9WDHhAD*N5kdgMnom z18evu1~xdmg^6+b{|6hvcE~X>Fvu~mGcYi4Ft9LiGH@_(G4L~RGe|S=FsL(dG3YYz zF~~D8FbFa*{b%4}U}k6FWn^Sv_{E^azzIqSP$#TpU}j)pU|Q z_5%zY+ZZ?n{>^6)L=jmd@Xv$>3 z4cwVV3_J`B3_=Vn48ja-45ADY3}Osw3=#~Q43Z263{ni{4AKlX3^ELM43Z2k4Dt*C z3<_YU^D?lq$^T_wVPq8g#lXtI2};ROXRm-dI}qe-rZt-w*f5-pB(jDT#nn7^veGE7 zW|P9{YE=dn1~mpY1`V)#)fjXbG#GRl^cnOR%oy|;tQia#Y#DSJoEeN6{25G;UCj)4 zwK9VW)YTRY%nVEn3=9&x8F(WF*$cKa@cC?F;1^`i-@(AMjX?kuvy2R&nB@bf3kwEr z21^EU1}g>*22}<%s40eEGZ+{|cQXh^Zf6kM%)kt1u_27$0xM%--~uN)b#QEG002g` BDx&}Z literal 0 HcmV?d00001 diff --git a/TP1&TP2/MiniMax_versionMemoisation.java b/TP1&TP2/MiniMax_versionMemoisation.java new file mode 100644 index 0000000..660b45b --- /dev/null +++ b/TP1&TP2/MiniMax_versionMemoisation.java @@ -0,0 +1,59 @@ +import java.util.ArrayList; +public class MiniMax_versionMemoisation{ + + private static ArrayList max = new ArrayList(); + private static ArrayList min = new ArrayList(); + private static int Allumete; + + public MiniMax_versionMemoisation(int n){ + Allumete = n; + for(int i=0;iUz`z7HS&xC6fq{XAfrWvUfsKKkfrEjAL6CuyL56{g zL5YEzL6w1rL5qQxL5G2Z!H7YSL6Cugfro*G?JolhBcsAE237_xPy}Fe6Vn z?qFaByJ-=`P11|;xJi_Og+YvgjX{EegF%u(kU@$;hC!M^i9v=zl|hz4i$RV-he49T zh(QU9n>ZPS8APCNGGt(3U}9ik5ah7g#K0mg#3sbPgMoP)0|z2_`52fP7#P$Tm>AR< P1Q;|J7#T#t0VD localAlpha){ + localAlpha = res; + if (localAlpha >= beta){ + return localAlpha; + } + } + } + return localAlpha; + } + + private static int ExploreMin(int nbr_allumettes, int alpha, int beta){ + if (nbr_allumettes <= 0){ + return -1; + } + int localBeta = beta; + for (int coup = 1; coup <= 3; coup++){ + int res = ExploreMax(nbr_allumettes - coup, alpha, localBeta); + if (res < localBeta){ + localBeta = res; + if (localBeta <= alpha){ + return localBeta; + } + } + } + return localBeta; + } + + public static void main(String[] args) { + int nbr_allumettes = 5; + System.out.println(ExploreMax(nbr_allumettes, Integer.MIN_VALUE, Integer.MAX_VALUE)); + } +} \ No newline at end of file diff --git a/TP1&TP2/MiniMax_versionarret.class b/TP1&TP2/MiniMax_versionarret.class new file mode 100644 index 0000000000000000000000000000000000000000..02949c395ee59edd3e28dc17ae1809f9c6393925 GIT binary patch literal 771 zcmX^0Z`VEs1_pBmWiAGG1`#d>HU?1;A;!rd&LF|XAju%b&LGXsAj8POW|NthSz^b? zz^tJe#>l|poS%})$iVNDnV0HUnwykb6q1;flgh}zB-2z z8(fl@ob8)ffUYJpkCA~THxWdMX+-;EC6*=X=OpH(>j#$_>1_lNuu$g*bl7)eVffei+P6iGJ z0R~WHb1}#;a5Km;@GvMd@G__|a4_gF2r}?7Ffi~iu(17QU}0pG`o+M?zy%6nsB7w> zuF(a#hG`8eies4VWTh8@9m9mzF`^7C3}Osy3=#|+43Z4|3{nhY4AKnJ3^EL|46+PL z3~~&r43Z4m3`$6jVTL+}lR meilleurres){ + meilleurres = res; + if (meilleurres == 1){ + break; + } + } + } + return meilleurres; + } + + private static int ExploreMin(int nbr_allumettes){ + if (nbr_allumettes <= 0){ + return -1; + } + int pire = 2; + for (int coup = 1; coup <= 3; coup++){ + int res = ExploreMax(nbr_allumettes - coup); + if (res < pire){ + pire = res; + if (pire == -1){ + break; + } + } + } + return pire; + } + + public static void main(String[] args) { + int nbr_allumettes = 4; + System.out.println(ExploreMax(nbr_allumettes)); + } +} \ No newline at end of file diff --git a/TP1&TP2/Readme.md b/TP1&TP2/Readme.md new file mode 100644 index 0000000..ea6ef96 --- /dev/null +++ b/TP1&TP2/Readme.md @@ -0,0 +1,97 @@ +Ce fichier repertorie et explique les code qui se trouve dans ce fichier. + +## MiniMax_versionBase + +Ce code est la version de base vu en cours du jeu de Nim. +Il fonctionne et donne bien -1 en resultat. + +# Tableau d'Ă©tats visitĂ© + +| n (allumettes) | Nombre de nƓuds explorĂ©s | +|----------------|--------------------------| +| 5 | 46 | +| 7 | 157 | +| 13 | 6 094 | +| 19 | 235 957 | +| 31 | 353 693 521 | + + + +## MiniMax_versionprofondeur + +Ce code est une version optimisĂ© de la version vu en cours du jeu de Nim. +Celui-ci a un autre paramĂštre qui est profoncdeur qui limite les calcul et donne une approximation. +Il fonctionne et donne bien 0 en resultat si la profonceur est infĂ©rieur Ă  6 et si elle est de 6 ou plus elle donne bien -1 car 6 est la profondeur maximal de l'abre du jeu de Nim. + +# Tableau d'Ă©tats visitĂ© + +| Nombre d’allumettes | Profondeur max | Nombre de nƓuds (Ă©tats) | +|---------------------|----------------|-------------------------| +| 5 | 6 | 46 | +| 7 | 8 | 157 | +| 13 | 14 | 6 094 | +| 19 | 20 | 235 957 | +| 31 | 32 | 353 693 521 | + + + +## MiniMax_versionarret + +Ce code est une version optimisĂ© de la version vu en cours du jeu de Nim. +Celui-ci a une autre condition d'arret qui limite les calcul qui est donnĂ© par un chemin oĂč il y a une victiore ou une dĂ©faite. +Il fonctionne et donne bien -1 en resultat si le nombre d'allumettes est de 5 et si elle est de 4, elle donne bien 1. + +# Tableau d'Ă©tats visitĂ© + +| Nombre d’allumettes | NƓuds visitĂ©s | +|---------------------:|-------------:| +| 5 | 36 | +| 7 | 74 | +| 13 | 1 828 | +| 19 | 25 610 | +| 31 | 8 784 458 | + + +## MiniMax_versionMemoisation +Ce code est une version optimisĂ© de la version vu en cours du jeu de Nim. +Celui-ci garde en mĂ©moire avec un tableau pour le min et le max pour Ă©viter de recalculer des sous-arbres dĂ©jĂ  vu prĂ©cĂ©demment. +Il fonctionne avec les tests effectuĂ©. + +# Tableau d'Ă©tats visitĂ© + +| Nombre d’allumettes | NƓuds distincts (Ă©tats) visitĂ©s | +|---------------------:|-------------------------------:| +| 5 | 25 | +| 7 | 37 | +| 13 | 73 | +| 19 | 109 | +| 31 | 181 | + + +## MiniMax_version_AlphaBeta +Ce code est une version optimisĂ© de la version vu en cours du jeu de Nim. +Celui-ci permet de coupĂ© des partie de l'arbre de jeux, donc de visitĂ© moins de noeuds. +Il fonctionne avec les tests effectuĂ©. + +# Tableau d'Ă©tats visitĂ© + +| Nombre d’allumettes | NƓuds visitĂ©s | +|--------------------:|--------------:| +| 5 | 41 | +| 7 | 107 | +| 13 | 2 244 | +| 19 | 31 898 | +| 31 | 9 523 124 | + +## DiffĂ©rence de noeud visitĂ© entre MiniMax_version_AlphaBeta et MiniMax_versionBase +La diffĂ©rence entre le nombre de noeuds visitĂ© car alpha_beta ne regarde pas tous les sous-arbres, contrairement Ă  la version de base, cela se voit surtout avec une grande longueur de l'arbre de jeux. + +## Nombre d'Ă©tats visitĂ©s dans chaque version + +| Version | ParamĂštres initiaux | États explorĂ©s | +|--------------------------------|-----------------------------------|----------------| +| MiniMax_versionBase | `nbr_allumettes = 5` | 46 | +| MiniMax_versionarret | `nbr_allumettes = 5` | 36 | +| MiniMax_versionprofondeur | `nbr_allumettes = 5, profondeur=6`| 46 | +| MiniMax_versionMemoisation | `nbr_allumettes = 5` | 25 | +| MiniMax_version_AlphaBeta | `nbr_allumettes = 5` | 41 | \ No newline at end of file diff --git a/TP1&TP2/compteur/MIniMax_versionprofondeur_compteur.class b/TP1&TP2/compteur/MIniMax_versionprofondeur_compteur.class new file mode 100644 index 0000000000000000000000000000000000000000..247b2412551f9b78b873e31edd8d2b4023ae67be GIT binary patch literal 948 zcmX^0Z`VEs1_pBm4K4-_1_@3Eb_Pi<26hH15FyRUAj2Tb#URHZ&(5I0&Y;N1z?Yn# zTTqf(S`?p`pIVy2$iV2y$iQZknU`5&$H>5}p&7==z~Y>rlFG=y?~|FA>Q|bZlv)&$ zn3R*s$iU@VQIL~gl;pwUA$;iMPT#}fa?VDJDt|&8)k%1*Q5k!e;MEhhV zmL=-vB<7{-2bUCO=A~PMtm3dq&Vky^6`WsMl$`3839?Du*E28EH?bnVEVZaOGe57O zC_gPfF9qaom*a58Z5FbFXS@G$T*2(U9K@h~VesIW7r@-V0|s53Gs z5jKsHK>%bP#DV@vS*gh-C_=%N#U-h^j10{Ar6r6Eq7dI?=IaL(W#*LxmlUNY=2|l{ z2!qW)6=q~$F90dZ0R@MKr)C&~A_F@E2Ll5GBLgSMwk$TBc8 zFoHz2wlgqp1S{lYU|?Va3o6D2vPz1~yR^+ZJZV<^P|^tYKhaU}6B7Z^Xa@ zwuOU%oq>megMp8Mi$REin?ZzumqDC?k3o)spFxvBfI*)@kim$7kHLaLgh7yjfq|ES zm5=o=0}CUg#4iR`uqFYh^Cm!@XNl}QCaCjR(Ot&^cHJU;u9INkV31_sVUS|rV~}AG zVvuDJVUTAKV^Cm_Wl&_$U{GSvV^C%=WKdu*XHY|S9W&H*oD9MYB2d>kF)%YQGcYhn zao7m3*=}NBm6qATz_N{jZ4(3QCI+T$3~Y$N7Xt^g76TK5HUlez4ub%LE`ub49s>u1 gC<71FJW#wbfZ~mLGXoPsD meilleurres){ + meilleurres = res; + } + } + return meilleurres; + } + + private static int ExploreMin(int nbr_allumettes, int profondeur){ + compteur_noeud++; + if (nbr_allumettes <= 0){ + return -1; + } + if (profondeur == 0){ + return 0; + } + int pire = 2; + for (int coup = 1; coup <= 3; coup++){ + int res = ExploreMax(nbr_allumettes - coup, profondeur - coup); + if (res < pire){ + pire = res; + } + } + return pire; + } + + public static void main(String[] args) { + int nbr_allumettes = 5; + int profondeur = 6; + System.out.println(ExploreMax(nbr_allumettes, profondeur)); + System.out.println(compteur_noeud); + } +} \ No newline at end of file diff --git a/TP1&TP2/compteur/MiniMax_versionBase_compteur.class b/TP1&TP2/compteur/MiniMax_versionBase_compteur.class new file mode 100644 index 0000000000000000000000000000000000000000..c0805ee2f482f0681bf51966d3d864e888d24261 GIT binary patch literal 886 zcmX^0Z`VEs1_pBm4K4-_1_@3Eb_Pi<26hH15FyRUAj2Tb#URHZ&(5I0&Y;N1z?Yn# zTTqf(S`?p`pIVy2$iV2y$iQZknU`5&$H>5}p&7==z~Y>rlFG=y?~|FA>Q|bZlv)&$ zn3R*s$iU@VQIL~gl7#$iN$1l9-(Bn^=IZCNqzbfh9K)M2Trc`(!1S zCF21fm+QKoL^d$oa&YdvPjW4GcVIOu_C@KwWv5VKhG(# zI5i&Tay^hyJPh0nJUk4X3|u@6LJR^t4EziN>H@(jETDhzxKY7E>AIt+pgf(#4{JPa&+e;HU98HIi^urhFgLL2ImYN$(ekzK;H zh84vjEOxTei|{x^l!1dmjDd$ioPm!)l0kq$ib0$~nn8|1hC!J@mO+(4ib0z}0m&iE zP=|0b2s4O49b(PE#K6SBz#uLlY_o}hReA>l%QgnKO$@A?7?`#(upz=z2pn=M49pCw r47?0#3}OuG3>*xi3_MVSK+(VeiU#J*3`_`ZkZ53LU}O*j2ctLu16-V4 literal 0 HcmV?d00001 diff --git a/TP1&TP2/compteur/MiniMax_versionBase_compteur.java b/TP1&TP2/compteur/MiniMax_versionBase_compteur.java new file mode 100644 index 0000000..fd0b423 --- /dev/null +++ b/TP1&TP2/compteur/MiniMax_versionBase_compteur.java @@ -0,0 +1,40 @@ +public class MiniMax_versionBase_compteur { + + public static int compteur_noeud = 0; + + private static int ExploreMax(int nbr_allumettes){ + compteur_noeud++; + if (nbr_allumettes <= 0){ + return 1; + } + int meilleurres = -2; + for (int coup = 1; coup <= 3; coup++){ + int res = ExploreMin(nbr_allumettes - coup); + if (res > meilleurres){ + meilleurres = res; + } + } + return meilleurres; + } + + private static int ExploreMin(int nbr_allumettes){ + compteur_noeud++; + if (nbr_allumettes <= 0){ + return -1; + } + int pire = 2; + for (int coup = 1; coup <= 3; coup++){ + int res = ExploreMax(nbr_allumettes - coup); + if (res < pire){ + pire = res; + } + } + return pire; + } + + public static void main(String[] args) { + int nbr_allumettes = 19; + System.out.println(ExploreMax(nbr_allumettes)); + System.out.println(compteur_noeud); + } +} \ No newline at end of file diff --git a/TP1&TP2/compteur/MiniMax_versionMemoisation_compteur.class b/TP1&TP2/compteur/MiniMax_versionMemoisation_compteur.class new file mode 100644 index 0000000000000000000000000000000000000000..e3c0354239620584135047941773c5ae4865d143 GIT binary patch literal 1583 zcmX^0Z`VEs1_pBme=Y_Q25n9TJ_a2Sq07a<$)Lx@AjF^#;u?SmLlD=9oxvC+XTrt6 z$6yK)F$1y8*%>TAv?V8l6@xVwgAIc%JA)laTAQ80o{@n$H?e||LDVNJu`E%)v?Mb} z-?6ADvC=2AxWt-~fipNWJuk7Ov?!I4K?|E28;D>|VqUtwXI@EadTNoioi)hV%sfU0 z4#%9F(%jUNR7M6yPeum5!~!UvGqs{1C%?!STpDc461B_0Mh26r9?6$WJ<1`h^L9tI@_Wkv>NBCH14D#y;?#lzsu;KR<~ z%fsNuAjilc47LI_1{oOyz@lJ_{gbj%lS>#G*vk@gN>lyQ7#YMgJT;L52o`^g49tls zDU1xF8c325-PW2>j10`_sU;v;6wOe1Mh1?|ypk}G4U7!T8k(Mr49vwKxInSQz{nuZz`(%7Ai=-|iY64k6oWJa0|O_6447tRU}TVGkYiwEkY`|EC}m(` zU}j)o(9_z^z$m?$fr;5xMtTv0;wA=Wfqy#~Shg{+hHqkEgR@(h7?=Nlun}yR0s{ks z90NPpY>+!R7`Peu8F(0^8F(4g8MqmA8Tc6#85kG@8JPYva4|5mGw?AoGBEsNP-5T& zr3|POwlXj?urM$%L~UYVXGz%1z%DhHft6*=CI)7yZ44X-7&x~va0&dI&mf2*vPR&a z4U4S|+hPWBDVdZV4BU3ovWpm4Wo^JNd<9Y~4R$|IxbzyhbIlld85kIZ88{e37(mIJ zk3pP4fkA>nk3ovTkU^TkfV+*(FGM1HfoaVq1~v>YAc?GDMezZzovbv957?w|`aqq5gF%CVhe4Bp zk3pM3fkB5sk3pZofWd&loWYR6j=_k*nZcOBmBE0)o574BoWUH~2h4CEs4}QQec;T% z%)rFJz#zYyfiF@(VLJoA&n5-|0r?#ayxTw_FR+P$eH()yDB>9zKoKtljx%cpP~j`e zV9OxKV8_70pw6HHHP8}l90P;oZU&*q?F_=38JOWLHs;L?>;?u7}yyY K88pEWrUd{fhe8_w literal 0 HcmV?d00001 diff --git a/TP1&TP2/compteur/MiniMax_versionMemoisation_compteur.java b/TP1&TP2/compteur/MiniMax_versionMemoisation_compteur.java new file mode 100644 index 0000000..d83ab15 --- /dev/null +++ b/TP1&TP2/compteur/MiniMax_versionMemoisation_compteur.java @@ -0,0 +1,63 @@ +import java.util.ArrayList; +public class MiniMax_versionMemoisation_compteur{ + + private static ArrayList max = new ArrayList(); + private static ArrayList min = new ArrayList(); + private static int Allumete; + public static int compteur_noeud = 0; + + public MiniMax_versionMemoisation_compteur(int n){ + Allumete = n; + for(int i=0;it<7e=Y_k z24!{z6?O(yMh3p*{M>?))Y78(y!_PC6h;O{Peukdo6Nk-5<5l)W)00SMg|t={FGEi z27aH+yi~u^+@#c^ki?{%R7M6a*NTFi{GwFf#0o|RHVsctPfbro2HxP3#N=$>!~%3x znR$#1EV+pwN=zf#Co8cmQ9ma!FI_*lq$o2l-5O*UhfQ)0)N-!i{L-T2RJTl!RqDQ( zd6~Y674c=MMa7xsU?Z=FdyiF4CG6urOnx0z3&Y;P|pv9og$e={n21W(}gaQ6ZS*gh-C_=%N#U-h^ zj10{Ar6r6Eq7WZu=IaL(W#*LxmlUNY=2|l{2!qW)6=q~$F90dZ0R@qUr)C&~A_FKk z85kHDI6=N)U|?WnU<7%NfssLgfq_Amfsug`B&xNYfpH@PNTDDD0|Ogakdc84=FiE zQC2%ynS~6jvTIsc7?=OQBfExyfq{tuWP=d{57-_K26hG>1`Y;31}+8x25tsP1|9|# z23`g&20jK|27U%31_1^W25tr`1`!4k1_lNm1{S`*3@nU{3cnaw8Mr{PgU@|TYh+N} zCoQ{!fd%ZoMG*H%FUI3O2?h?Zi=-I%7-Sd(7-ShF8RQsL7~~nW7!(+E859|e7?c=H z7-Si&7}T)1kCQ=+K^*Endj=K;CI$uuX#shgO$@BkLhM2uI~Z8DF>r2TVBN&Pw2gri z5dlIBEDQ_`S`5q#+6;mWIt)?_x(pl)5)AxM!$9%I0E#!}%?wNkZIF0lW?*EH1c$T~ E0J7$?R{#J2 literal 0 HcmV?d00001 diff --git a/TP1&TP2/compteur/MiniMax_version_AlphaBeta_compteur.java b/TP1&TP2/compteur/MiniMax_version_AlphaBeta_compteur.java new file mode 100644 index 0000000..900f940 --- /dev/null +++ b/TP1&TP2/compteur/MiniMax_version_AlphaBeta_compteur.java @@ -0,0 +1,46 @@ +public class MiniMax_version_AlphaBeta_compteur { + + public static int compteur_noeud = 0; + + private static int ExploreMax(int nbr_allumettes, int alpha, int beta){ + compteur_noeud++; + if (nbr_allumettes <= 0){ + return 1; + } + int localAlpha = alpha; + for (int coup = 1; coup <= 3; coup++){ + int res = ExploreMin(nbr_allumettes - coup, localAlpha, beta); + if (res > localAlpha){ + localAlpha = res; + if (localAlpha >= beta){ + return localAlpha; + } + } + } + return localAlpha; + } + + private static int ExploreMin(int nbr_allumettes, int alpha, int beta){ + compteur_noeud++; + if (nbr_allumettes <= 0){ + return -1; + } + int localBeta = beta; + for (int coup = 1; coup <= 3; coup++){ + int res = ExploreMax(nbr_allumettes - coup, alpha, localBeta); + if (res < localBeta){ + localBeta = res; + if (localBeta <= alpha){ + return localBeta; + } + } + } + return localBeta; + } + + public static void main(String[] args) { + int nbr_allumettes = 31; + System.out.println(ExploreMax(nbr_allumettes, Integer.MIN_VALUE, Integer.MAX_VALUE)); + System.out.println(compteur_noeud); + } +} \ No newline at end of file diff --git a/TP1&TP2/compteur/MiniMax_versionarret_compteur.class b/TP1&TP2/compteur/MiniMax_versionarret_compteur.class new file mode 100644 index 0000000000000000000000000000000000000000..8eb9c86690241f023e87e67b28528fdab0e53a2d GIT binary patch literal 920 zcmX^0Z`VEs1_pBm4K4-_1_@3Eb_Pi<26hH15FyRUAj2Tb#URHZ&(5I0&Y;N1z?Yn# zTTqf(S`?p`pIVy2$iV2y$iQZknU`5&$H>5}p&7==z~Y>rlFG=y?~|FA>Q|bZlv)&$ zn3R*s$iU@VQIL~gl7#$iN$1l9-(Bn^=IZCNqzbfh9K)M2Trc`(!1S zCF21fm+QKoL^d$oa&YdvPj7{GcVIOu_C@KwWv5VKQFPU zD77RW=5#%fSv(Bf3_LsxoD5t%3_=V7JPiB{0_+S*JPgVVD(noZJPc|K>WmDscnxA? z5C9nkah88lR%&tyicoN6aYyf!eBE{ zg&7&x3qXo;K!Kp)sTszg$iU9P!N9=4$iNA5Gy?+zD+43Q4-AY9ybKHsvJ8w2j3801 z?F@_?!3y~p7#P^Vf{YAYApb#?_AoFpurM$%m~CQUVoBJ{z$7)7ft6*Az&{%nTN$>+ z4DwPkDLWXL?PR5wF!0LSNV6*}}xQ{Qo2AH4F?4Obj5ijTm^qHgGVoGw?8Q zFz_*OF$gknGe|J-Fvv6TGN>@{F{m-{GiWmiFz7LGGng=lFbFa*Fz_(2@cm_AVPus0 z#lXtI1qyzs%etX1Geve8(;8M3hq2hnN-qLCj0vy9Bp5gtBpG-Zq!{=ZWEcb(WEsR6 z meilleurres){ + meilleurres = res; + if (meilleurres == 1){ + break; + } + } + } + return meilleurres; + } + + private static int ExploreMin(int nbr_allumettes){ + compteur_noeud++; + if (nbr_allumettes <= 0){ + return -1; + } + int pire = 2; + for (int coup = 1; coup <= 3; coup++){ + int res = ExploreMax(nbr_allumettes - coup); + if (res < pire){ + pire = res; + if (pire == -1){ + break; + } + } + } + return pire; + } + + public static void main(String[] args) { + int nbr_allumettes = 19; + System.out.println(ExploreMax(nbr_allumettes)); + System.out.println(compteur_noeud); + } +} \ No newline at end of file diff --git a/TP1&TP2/version_liste_melange/MiniMax_version_AlphaBeta_melange.class b/TP1&TP2/version_liste_melange/MiniMax_version_AlphaBeta_melange.class new file mode 100644 index 0000000000000000000000000000000000000000..abd250b6659a0371d20b3473a14889183d4e683b GIT binary patch literal 1518 zcmX^0Z`VEs1_pD65H1E$1`SRI5e7{z1|bG5ZU#jLZ4jZu&Y;W1z{a4*#UR3<4{YrC_Qj0^aZ<}os`>w`;* zGV{`{LDq5DB6=&)UzS=_oSB~&@0e4Nk?53Kk{F+x z3i3m$9w;1m7^E1ac^JeP#CaI(80>i%92gvV7@QcK85smY^7`MAP^DE$RG?h2{ptS859Y+ zkdZ+EtP|`8|D>$cLOXn-!~+Bo_5FmN!iFmN)kF>o_*Fz_&_G4L{&Fz_*0G4M0kG6*m@F$glaFo-a?Gl()MFfcIi zF|e@xW#D9FXHYc$#lXbC1xnG_oXWIDhB&86%kE&{1Uq#R#HrGYaXD3zfrUYefsH|i zfrCMoL5)FmmaBgD|L`0qv0|x^G zgBAlfgEoU0gARitgD!(QgC2t>gFb^1g8_pBgCPS4gDQhG)CtO92QV;j?`9B++|D4p SnSlvm7$hZt5{()-y3_# list = new ArrayList(); + + private static int ExploreMax(int nbr_allumettes, int alpha, int beta){ + if (nbr_allumettes <= 0){ + return 1; + } + int localAlpha = alpha; + for (Integer coup : list){ + int res = ExploreMin(nbr_allumettes - coup, localAlpha, beta); + if (res > localAlpha){ + localAlpha = res; + if (localAlpha >= beta){ + return localAlpha; + } + } + } + return localAlpha; + } + + private static int ExploreMin(int nbr_allumettes, int alpha, int beta){ + if (nbr_allumettes <= 0){ + return -1; + } + int localBeta = beta; + for (Integer coup : list){ + int res = ExploreMax(nbr_allumettes - coup, alpha, localBeta); + if (res < localBeta){ + localBeta = res; + if (localBeta <= alpha){ + return localBeta; + } + } + } + return localBeta; + } + + public static void main(String[] args) { + list.add(1); + list.add(2); + list.add(3); + Collections.shuffle(list); + int nbr_allumettes = 5; + System.out.println(list); + System.out.println(ExploreMax(nbr_allumettes, Integer.MIN_VALUE, Integer.MAX_VALUE)); + } +} \ No newline at end of file diff --git a/TP1&TP2/version_liste_melange/MiniMax_version_AlphaBeta_melange_compteur.class b/TP1&TP2/version_liste_melange/MiniMax_version_AlphaBeta_melange_compteur.class new file mode 100644 index 0000000000000000000000000000000000000000..9d417c719353ff90dfb5970ee4f0c141b7e8dd31 GIT binary patch literal 1620 zcmX^0Z`VEs1_pD62rdRO25n9TQ3f3lq07Y}%%I23pu(UJA`I9W47nKC8H~6XL>Y`h zgb9di3Q}dp#bC~0!O39BV8z8?&0xdaz`(%3T>t<7e-PJ}oxu*IN}HX*o}Iygk%1*A zv$%wjLDVNJu`E%)v?Mb}-?6ADvC=2AxWt-~fipNWJuk7Ov?!I4K?|E28;D>|VqUtw zXI@EadTNoioi!r^UvhqKK}l+9QG8y0YH1211EVJ+1Dj1|US^3MBLlOBW*8#_i*tTT zDkB5GPi9`KUukYqYEejHQcfx(1D9(>K~8>As&8TiBLka;r>Cc;CnE!Ia7kivwr^qq zSQR^iBa*_*JVpkV+(Zy1rV)+grr?sI%)E4KkaZk3$vIH_xq|aci;`2_GC{WK`)1~4 z`X*Mym!%dJXXfX{JLVK*Bs!&*B*y2af;^TQ5A%#3D3o{@WEtdm7^E3wco@VPBzPE{ z7@T<+To_z=7~B}#85smYiu6GmVIji9;KAU@!=TEb#KWKnBD@&9c^G^ceAyZNco_T{ z0@xV>c^HBig4r2Dco;$%!azhgBZDy5B-BV@WY8ksy^IV3U?aee@lVQ1O)g<%5CRK< zP4z5EElMoOFJffi$b>V+G&CUrh@!-rk%2uUvDh!Qq68d&QH%^Md0>tROg)k<)*ut} zO2QIzN>jngJsBC;%RoH;G)4w74Ns^QU@fq8!^ps#n3BTCAgTeeA1n!RwY6pxBZDZy z;m-LvIjPAdnfZCej126>8Kr4ypr{mv>IAzSoP8 zP?VWh5?oT0nwV=13wKmuMh5l*kfNMC91a8}Xbn%zFa|{iQ3f#v1_mYuE>QYlU}TU4 z^Q0I!L5YTefq|8Q5tN1)7#ZXl7#L(37#SErqFUP-7&kI7FfcMGFfcH%fdyF@xIjq; zs&pj-GXpyV14G~@1}2t-%?wOZa~W7!)=1lJVqo6Jz+%NB$+DAym62g4g8_)e#>jAh zf!&H#N|JRO14oLi%nk-lGd58+*(D6TqHK1uG7A}4W!EhKe@1o<*o7c#jTm?s7#KJi zI2gDXco?`D_!xK@1Q_@j^ceUVY#0O>oEQWdTp5HIycmQTd>F(S{29a#G?t0Q!N1H?^cfh literal 0 HcmV?d00001 diff --git a/TP1&TP2/version_liste_melange/MiniMax_version_AlphaBeta_melange_compteur.java b/TP1&TP2/version_liste_melange/MiniMax_version_AlphaBeta_melange_compteur.java new file mode 100644 index 0000000..c0e65f0 --- /dev/null +++ b/TP1&TP2/version_liste_melange/MiniMax_version_AlphaBeta_melange_compteur.java @@ -0,0 +1,54 @@ +import java.util.ArrayList; +import java.util.Collections; + +public class MiniMax_version_AlphaBeta_melange_compteur { + private static ArrayList list = new ArrayList(); + public static int compteur_noeud = 0; + + private static int ExploreMax(int nbr_allumettes, int alpha, int beta){ + compteur_noeud++; + if (nbr_allumettes <= 0){ + return 1; + } + int localAlpha = alpha; + for (Integer coup : list){ + int res = ExploreMin(nbr_allumettes - coup, localAlpha, beta); + if (res > localAlpha){ + localAlpha = res; + if (localAlpha >= beta){ + return localAlpha; + } + } + } + return localAlpha; + } + + private static int ExploreMin(int nbr_allumettes, int alpha, int beta){ + compteur_noeud++; + if (nbr_allumettes <= 0){ + return -1; + } + int localBeta = beta; + for (Integer coup : list){ + int res = ExploreMax(nbr_allumettes - coup, alpha, localBeta); + if (res < localBeta){ + localBeta = res; + if (localBeta <= alpha){ + return localBeta; + } + } + } + return localBeta; + } + + public static void main(String[] args) { + list.add(1); + list.add(2); + list.add(3); + Collections.shuffle(list); + int nbr_allumettes = 5; + System.out.println(list); + System.out.println(ExploreMax(nbr_allumettes, Integer.MIN_VALUE, Integer.MAX_VALUE)); + System.out.println(compteur_noeud); + } +} \ No newline at end of file diff --git a/TP1/Minimax.class b/TP1/Minimax.class deleted file mode 100644 index 7c27f83671fed01a8f53ea55e57127804c9a992a..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 809 zcmX^0Z`VEs1_pBmT`mSL25C+P83tJ{22KV!E(Uo91x^M|21O883B*zc5i0Bqs_YDE zj0`LVnMJ9L42+(P49rET#f%Kxxv7~sIjN;ZK_DKRO=ezZi5(*Yvxa6EBLjDkB3+ZenI0BZHVmv`AsxL?ti-xDBCnE!Ia7kivwr^qq)C{a1|CKRcBp1X z1_6+Eh|~O&vQm>vP=taji%U{-85x-KOG_9TL?Qmj%-0Vn%FHVXE-6Y)%(Z4@5C)rp zD$K~hUI0>*lgG#a@>>{#A_FG_7Xt$WGXp2cO$-bSoFEs0X+8!X1_lNe21bxS7#JA@ z85kI385kKD85kH?wYD=bZe(C!U}O+tU|?Va3oK$WU9Fo8w6H!(1=>|kKt z#=wHmz{S7>wu6g-n}HJ)G*C@73`}4dW2w0etW0ZIH#4xZ*hsT2W>A!pPT9f0wwZx_ z69};`V&L4wz`mJ*wS|#!`Tqx-7+BXZFfcHIU8Bap$-uzC$H2nC&%nkY#K6TM!XU^X z${@uc#-Pj~&Y;O4!l2I}%^=Rez`)JG!uE%Ol~Lvw11ke3C`zC%DS^5~AL0^ZS1`j| z!LbDD3J#bnI1sK-V&Gt4V322EVNhUTV^C(`Wl&)dV^C#~XHa8MWl(0&X3#=%0VBi( Lj0}=sZ%6?E2`Gq& diff --git a/TP1/MinimaxAlphaBeta.java b/TP1/MinimaxAlphaBeta.java deleted file mode 100644 index adadc5c..0000000 --- a/TP1/MinimaxAlphaBeta.java +++ /dev/null @@ -1,58 +0,0 @@ -import java.util.*; - -public class MinimaxAlphaBeta { - public static int compteur = 0; // nombre d'Ă©tats visitĂ©s - public static Random random = new Random(); - - public static int exploreMax(int n, int alpha, int beta) { - compteur++; - if (n <= 0) return -1; - - int meilleur = Integer.MIN_VALUE; - - // coups possibles - List coups = Arrays.asList(1, 2, 3); - Collections.shuffle(coups, random); // ordre alĂ©atoire - - for (int c : coups) { - int res = exploreMin(n - c, alpha, beta); - meilleur = Math.max(meilleur, res); - alpha = Math.max(alpha, meilleur); - - // coupure alpha-beta - if (alpha >= beta) break; - } - return meilleur; - } - - public static int exploreMin(int n, int alpha, int beta) { - compteur++; - if (n <= 0) return +1; - - int pire = Integer.MAX_VALUE; - - // coups possibles - List coups = Arrays.asList(1, 2, 3); - Collections.shuffle(coups, random); // ordre alĂ©atoire - - for (int c : coups) { - int res = exploreMax(n - c, alpha, beta); - pire = Math.min(pire, res); - beta = Math.min(beta, pire); - - // coupure alpha-beta - if (alpha >= beta) break; - } - return pire; - } - - public static void main(String[] args) { - int[] tests = {5, 7, 13, 19, 31}; - - for (int n : tests) { - compteur = 0; - int resultat = exploreMax(n, Integer.MIN_VALUE, Integer.MAX_VALUE); - System.out.println("n=" + n + " → " + resultat + " | Ă©tats visitĂ©s=" + compteur); - } - } -} diff --git a/TP1/MinimaxMemo.class b/TP1/MinimaxMemo.class deleted file mode 100644 index 4fccfaa097c002d53096d365feb2e2d330f0ca53..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1542 zcmX^0Z`VEs1_nolAT98VB5Tnu~+{Ok+@JPd*iLW~T87%CVUI5P7}!V+^zQ^B@*GB+?VFmN$&Fo^On zh%tyWGH|6<6y)R=rTS*(F*2}dcxrlbF-S5_Nl|8Ax-}PrIfDf|gC!4x6@xV+gD^NuP%U6&U@rh!my^fHAgTdz0yx&8MrejH zGO#%3r=&76@cU%urTUfTCZ!gIBqrsgGBWT6mn0@<`z97Z`7F7Kp!g8eK#p}JgSdk8 zON)|I-7-O%1(1@A9>`^k3<6I1`6b0AMTrHzsU;ctDa9NNu8a&CL5Eism*$itmMCcC z9$uN7e|UXyVo7Fxo~A-Uerb_Ho-L!oqqa#3jQng2?pzEW44&)^UZ5cJW@JzS84O9r znR#XT*{S*v=RiWyEit(yzo?RtVFt3#p$Z{R@JP%{$w@6%@yXB6E-kRe3?L*C6pbO3 z1*uq+BZmwmV_737I;auOi8(pJnI);#j0`-Ud3mWt&N+$2#i_;Y41SCZsu+I4=2Uiu z07eEm{7M-a*dYF5P-Ng>U}9ikU}E3|WoQNl22N0lXJBApVPFK62n>u2HVh05vJ8w2 zj0_A6tXkU{7&kI7FfcOMGB7Z(fdv^EI6=7qs?~CjXQ_dmr3rVIk`#7li7~J-h%<IlGPp4?GPp4KfQwT`244n$hCl{M0LUU^Y5)KL diff --git a/TP1/MinimaxMemo.java b/TP1/MinimaxMemo.java deleted file mode 100644 index 15300b2..0000000 --- a/TP1/MinimaxMemo.java +++ /dev/null @@ -1,43 +0,0 @@ -public class MinimaxMemo { - - // Minimax avec mĂ©mo (on Ă©vite de recalculer les mĂȘmes positions) - public static Integer[] memoMax; - public static Integer[] memoMin; - - public static int exploreMax(int n) { - if (n <= 0) return -1; - if (memoMax[n] != null) return memoMax[n]; - - int meilleur = Integer.MIN_VALUE; - for (int coups = 1; coups <= 3; coups++) { - int res = exploreMin(n - coups); - meilleur = Math.max(meilleur, res); - } - - memoMax[n] = meilleur; - return meilleur; - } - - public static int exploreMin(int n) { - if (n <= 0) return +1; - if (memoMin[n] != null) return memoMin[n]; - - int pire = Integer.MAX_VALUE; - for (int coups = 1; coups <= 3; coups++) { - int res = exploreMax(n - coups); - pire = Math.min(pire, res); - } - - memoMin[n] = pire; - return pire; - } - - public static void main(String[] args) { - int n = 25; // taille du tas initial - memoMax = new Integer[n + 1]; - memoMin = new Integer[n + 1]; - - int resultat = exploreMax(n); - System.out.println("RĂ©sultat pour n=" + n + " → " + resultat); - } -} diff --git a/TP1/MinimaxProfondeur.class b/TP1/MinimaxProfondeur.class deleted file mode 100644 index c7e77c83850ddc24d0562536a445f2cbfa2ff255..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1530 zcmX^0Z`VEs1_nn4Z!QKV24;2!79Ivx1~x_pfvm)`ME#t^ymWp4q^#8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CWeO zMg}?jN*Nj0ApT-dWZ-6CVgLaa21Za`V_;;^Wnf^CWng4rWME)m)!NR$xRHT@fssLv zfq{VyEXc^f2}+92}QoD6&n{Ok+@JPd*$J7n-FW@KOw z@NtZE4Kf7j66RqL0cnAX8G&3Y#={`aAi>DMo{?Exl3!HG$ROwg_GD>EW{$o~YGG-r zH8+D4gETvX3=e}WgB&9RKbkxv1AAghicey32_u8321GYf5Ls)6fecXKVNhgHVr1Yd zO3lqLONA&G(a^+H&(5I2$biFJp3pGk49-l?ODriZN@Zj)gBXEuunmp?goS%RPNlV- zH6sIybAC!HBLlxrW?rgaX>L+#QAlD^PAVeAPR%ez1`&w&19B?eit=;e`UTQcOVE;mf`%pzGocBAk%23-7?h^` z%RtG7Swl05k%2QkwInFDxHPAPkpZ^}5Ea&p4D6Z3KB?)6IgAX%`5=msfg`gdwJ5P9 zzlf1R3>JOhu=j+DTQf3PW0fE_URYD|19B=E8Q4qnpe(N7{L-T2RJTk}>Mk%5DOiGh(pnSqIc36%L57#Ns9DVu?jK^4qaW8h|B1m$7|Mh0~T1_oIMMg~R( z1_oBG?F@_?85kHC88jFe7}&sqybMeXnqW3asTbI21_l|eEe!0N7*h5ZcPX zzMO$eYZC+SRt9#E2~1!Ugcw*D7#KttxEMqkL>MF(q!}a`v=|r|SQwZ@*cg}?v>9}u zPEZFsmVtp=YYT&@_D%*#CI*l(5Ql(D9tH+E1}+A91||kwxMS3z?gnex$so_j5RR@% zg@KDfm4T5#k3k=56T-7w7}z(Uc~*yok->n$kb!}Pk-><;7)+Zmn1X3D26K1_TCgxO TSTg8<#jP0Fz@}J(!`21>vc)g~ literal 0 HcmV?d00001 diff --git a/TP3/fr/iut_fbleau/GameAPI/AbstractBoard.java b/TP3/fr/iut_fbleau/GameAPI/AbstractBoard.java new file mode 100644 index 0000000..d606ba2 --- /dev/null +++ b/TP3/fr/iut_fbleau/GameAPI/AbstractBoard.java @@ -0,0 +1,99 @@ +package fr.iut_fbleau.GameAPI; + +import java.util.Iterator; +import java.util.Deque; + +/** + * An abstract class implementing the interface IBoard. + * + * used to implement some things to do with the update of the next player + * which is the same for all games and provides also a minimal + * implantation of the history mechanism. + */ +public abstract class AbstractBoard implements IBoard{ + + private Player currentPlayer ; + + private Deque history; + + private void setNextPlayer(){ + if (this.currentPlayer==Player.PLAYER1){ + this.currentPlayer= Player.PLAYER2; + } + else + this.currentPlayer= Player.PLAYER1; + } + + // Beware not checking if move is legal. + // To be used in do(AbstractPly c) + private void addPlyToHistory(AbstractPly c){ + this.history.addLast(c); + } + + // Beware not checking if history is not empty + // To be used in undo() + private void removePlyFromHistory(){ + this.history.removeLast(); + } + + + /** + * @return the current player + */ + public Player getcurrentPlayer(){ + return this.currentPlayer; + } + + /** + * Returns the game status + * + * @return true iff the game is over + */ + public abstract boolean isGameOver(); + + /** + * + * @return the result (null if not over) + */ + public abstract Result getResult(); + + /** + * checker of legal moves from this position + * + * @throws NullPointerException if the game is over + * @return the iterator + */ + public abstract boolean isLegal(AbstractPly c); + + + + /** + * constructor of Iterator over legal moves from this position + * + * @throws NullPointerException if the game is over + * @return the iterator + */ + public abstract Iterator iterator(); + + + + /** + * Plays a given move on the plateau. + * Should update history using + * @throws IllegalArgumentException if the move is always illegal (say from the wrong game) + * @throws IllegalStateException if the move is not legal in this position + * + * @param AbstractPly to be played + * + */ + public abstract void doPly(AbstractPly c); + + /** + * Resets the plateau to the position before the last move. + * + * @throws IllegalStateException if nothing to undo in history + * + */ + public abstract void undoPly(); + +} diff --git a/TP3/fr/iut_fbleau/GameAPI/AbstractGamePlayer.class b/TP3/fr/iut_fbleau/GameAPI/AbstractGamePlayer.class new file mode 100644 index 0000000000000000000000000000000000000000..e914e9ec26e1c182706b3887b6f1ebff988cb37d GIT binary patch literal 372 zcmX^0Z`VEs1_nn4K`sU+24;2!79Ivx1~x_pfvm)`ME#t^ymWp4q^#8B5=I6#o6Nk- z5<5l)W)00Sb_Nbc292~L{mjym__U;))WlMK_r%;(#{f@#$E4ztqQvA95I-O%u`;!Y zk%2kWF_)1+&Ih{=h$?GF1{UZ1lvG9rexJ;|RKL>Pq|~C2#H5^5Mh2er%(B$T{L&)d z{IXO=24@W%CV4vLCl;kxYvPcGIV~Wk(wdQhD>%QjC^^+F6J&!pOb+2}Jy0O9C^E1! zFflMNFfuSPa58W)FfcGNFoHsffsuimfq_Amfsuicfq{WlYdZtuMzBI21_lN;upkEu PBLgo3A6S$htW^L2yEI#= literal 0 HcmV?d00001 diff --git a/TP3/fr/iut_fbleau/GameAPI/AbstractGamePlayer.java b/TP3/fr/iut_fbleau/GameAPI/AbstractGamePlayer.java new file mode 100644 index 0000000..be251ee --- /dev/null +++ b/TP3/fr/iut_fbleau/GameAPI/AbstractGamePlayer.java @@ -0,0 +1,26 @@ +package fr.iut_fbleau.GameAPI; + +import java.util.Iterator; + +/** + * The abstract class for a game Player. + */ +public abstract class AbstractGamePlayer { + + // not a band, but which type of player I am in the game (PLAYER1 or PLAYER2). + private Player iAm; + + // Le joueur rĂ©el pourrait avoir besoin de connaĂźtre un constructeur de coup? + // pas pour l'instant. + + + /** + * + * + * @throws UnsupportedOperationException if the method is not yet implemented + * + * @throws IllegalStateException if the Situation is already in the bookmarks + */ + public abstract AbstractPly giveYourMove(IBoard p); + +} diff --git a/TP3/fr/iut_fbleau/GameAPI/AbstractPly.class b/TP3/fr/iut_fbleau/GameAPI/AbstractPly.class new file mode 100644 index 0000000000000000000000000000000000000000..d7e2a47f1bd1e1a2c6b0d1fcce138ee8e1ebd233 GIT binary patch literal 268 zcmX^0Z`VEs1_nn4el7+k24;2!79Ivx1~x_pfvm)`ME#t^ymWp4q^#8B5=I6#o6Nk- z5<5l)W)00Sb_Nbc2F0`@{mjym__U;))WlMK_r%;(#{f@#$E4ztqQvBqfSgK32DYsH z($vx-Mg}<_?5YED5-U@StQi?tobyvs85#I}GV@aXN^_G^i$W5Ua#9%?xPtRbi;`2_ zGC>>xB-8akj$~0}U}s=rU|?WmU}E58-~zK4LB3#MWZ-6CV31{CWME`qU|`kS&cL`4 YEX~8fz`zC;WM*Jw;ALQ7U}E3{05GyTqyPW_ literal 0 HcmV?d00001 diff --git a/TP3/fr/iut_fbleau/GameAPI/AbstractPly.java b/TP3/fr/iut_fbleau/GameAPI/AbstractPly.java new file mode 100644 index 0000000..f831b22 --- /dev/null +++ b/TP3/fr/iut_fbleau/GameAPI/AbstractPly.java @@ -0,0 +1,5 @@ +package fr.iut_fbleau.GameAPI; + +public abstract class AbstractPly { + private Player joueur; +} diff --git a/TP3/fr/iut_fbleau/GameAPI/IBoard.class b/TP3/fr/iut_fbleau/GameAPI/IBoard.class new file mode 100644 index 0000000000000000000000000000000000000000..5728bcd51976c0ae8432880b3e8677d1d5010dcc GIT binary patch literal 525 zcmX^0Z`VEs1_nn4adrkKMh2O*BK^$LlK8ZwoYcfpefPxNRL1~MeNU(S#G({-1{OvJ zfvm)`ME#t^ymWp4q^#8B5=I7r^wg5%(xRf&ypn*N#LCnnMg|29O&{z=K~z{XGH_)U zgN*kt1F2`$(2Qba;7m^~2}&(4%_+fW0z`#1BLjP8u}^AxVh$sNng$Nr9FvMmiV~Ac z0&*&?K{jw?mZTOXmgE;PGKgtt`hfjXT9TQg?+F#RW@O+D&P>lsEGaEYWn{3%s>p^2 z+w80v8CX;D19B>fbzT@F1AA#6R133)W*8#_S8#r5QF5wVW=<+212-fV^gxbgV`N}t zU}gXTb{0kkRt7c(P~@;PaDZt}1}-qo&A iterator(); + + + + /** + * Plays a given move on the plateau. + * Should update history using + * @throws IllegalArgumentException if the move is always illegal (say from the wrong game) + * @throws IllegalStateException if the move is not legal in this position + * + * @param AbstractPly to be played + * + */ + public void doPly(AbstractPly c); + + /** + * Resets the plateau to the position before the last move. + * + * @throws IllegalStateException if nothing to undo in history + * + */ + public void undoPly(); + + +} diff --git a/TP3/fr/iut_fbleau/GameAPI/Player.class b/TP3/fr/iut_fbleau/GameAPI/Player.class new file mode 100644 index 0000000000000000000000000000000000000000..c659c8b3dfd9f18f69828f989b5b73e4ea30458f GIT binary patch literal 998 zcmX^0Z`VEs1_nn4eRc*WMh2O*BK^$LlK8ZwoYcfpefPxNRL1~M{eYar%G4rG21W)J z9tKthHbw^a03XLl*C0bi200&mdaOa3ICvO1ku({B#JG7Fco=vY8Q4|A9DPDvgBcm* zqw$->#lX)Xz|O$S!yw2Y#K^#!oRgoI%E%z1q3M&ASeB@tlbDyT@1K;Fnp|Sd#UR2U z%FZCh!ywKe!N|aeP~e(Zn#;(*UY3|sn(Cj%$Y830q}w?svAEb8Ng%kSC^IkJ8rcSr z0bui`co?J^WEdIPY%=pQOY9gK#E^}G>h#nM<6vOrVqj#D;$Ywe(TY3_N({;%kAvM% z%*ddqp-I5&j0|ir#VpSGDXEMM{63j^seYxoNvTC4iAg!Bj0{FtY}dpeqKpgzzNsY{ z`6&U3MTxnoC8V!f*sUxKybP=iQVh%tObihB=rHJl H-K7TrLd?jw literal 0 HcmV?d00001 diff --git a/TP3/fr/iut_fbleau/GameAPI/Player.java b/TP3/fr/iut_fbleau/GameAPI/Player.java new file mode 100644 index 0000000..2831093 --- /dev/null +++ b/TP3/fr/iut_fbleau/GameAPI/Player.java @@ -0,0 +1,6 @@ +package fr.iut_fbleau.GameAPI; + +public enum Player { + PLAYER1, + PLAYER2 +} diff --git a/TP3/fr/iut_fbleau/GameAPI/Result.class b/TP3/fr/iut_fbleau/GameAPI/Result.class new file mode 100644 index 0000000000000000000000000000000000000000..4234ba934331213fdbeea51a1ec69d20b4ed21e5 GIT binary patch literal 1042 zcmX^0Z`VEs1_nn4V|E56Mh2O*BK^$LlK8ZwoYcfpefPxNRL1~M{h-w1(wq`b21W)J z9tKthHbw^Ka8Ex*200&m>a9T8waPOv zGcYqSFtBTB%WP+m*@$5eNFOH?1A_nq80#{C^y>+5f#MkITzv)>kZT#l+4eFpMlx?= zU=EIC*~Gve9Lc(gfh!o(EgTH`40=$_K~T+lyBQcGg%p^#GbnCmUpt6~P7vWAJuzn5(UT}zTF{m@JGcYkgoN2&d2zIU!0Nw7+@&Et; literal 0 HcmV?d00001 diff --git a/TP3/fr/iut_fbleau/GameAPI/Result.java b/TP3/fr/iut_fbleau/GameAPI/Result.java new file mode 100644 index 0000000..9417e13 --- /dev/null +++ b/TP3/fr/iut_fbleau/GameAPI/Result.java @@ -0,0 +1,11 @@ +package fr.iut_fbleau.GameAPI; + +/** + * To output the result of a 2 player game that is symmetric. + * from the perspective of the player PLAYER1. + */ +public enum Result { + WIN, + DRAW, + LOSS; +} diff --git a/TP3/fr/iut_fbleau/Nim/NimBoard.class b/TP3/fr/iut_fbleau/Nim/NimBoard.class new file mode 100644 index 0000000000000000000000000000000000000000..d690ef3763d7e625b2988780c6bfb686e5052a45 GIT binary patch literal 3776 zcmX^0Z`VEs1_nolja&>&49x5dEIbUX3~Y=H%4tRVnWZK1X-PS$iKY7PiMgqc0iODf zNyQ~aiOD5S`H4j-j0|ixnR%Hdc8m=IMN?D0ziTXK-dFlF|IXS86i8+o% z>7}`;c_pqD$*Bb;nfZAf3|x#1nm(xtdHK0XMX3rY>WMiyrMamkC8@;h9mzk^YmzfLoq%gvHo_U!inTa{6#f%J$ zo**;Cc^D)>1|X>kN-Zu)%qvMP2FXkDFi3;sxpEUL0uqay^Ggdj8Dtsc*cs$`7!(*3 z85v|yt%e13Ku%(1Y7rv?dw`E)q-&5NBZHg|K9$xW+mv}2R6u6(CYKf!rRJ4D3}I(b zV`LBkhg)e$W{$pNQBh*0OKM?hDi?z)12agYCJ%!agEk`rdq!q)Nq$i!BZD9$purlz zYQYxh@-XNz=rb~Kq$lR4`j>$m$QT7Oz>tT*h{2eVfvqUDxHP8(w`+sI^49DOri=`7 zU^ju&ieG6?PC$NUUP)>ZQaUkbWDxdARme&$RY)x^Q7B0*%FWC>ypoH-gn@^h!HSVV z0yRjW@fMI%$;DvFV8g>;%V5XIz?q&};+0>TT3W=&prE0NKNvw89e5ZV8JrjyB-2w% z{J?3{5uQK;iZY8q(a)@*>B-LE!pI;D_5?Vbzya%%SzN-!;L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cvU`d<+Z>RSfJ5)eM3RbqtaW^$f}kO$-_gtqi6N9Srsi-3)FFJq+Fq zeGH)t{S5I86B*JNrZHqOOb2_An}J18@DGDEJA)-CRj*?Jk)Ryg3iXu>$bmZo@fPA%$p#WP>g`|zy3_J{T7{nOnGbl4GV9;P#%wWo} zjKPv&C4(KqDh6kU)nKPFGcbxVFoD_{(17-0U;<}68BpxPL#KW#gAyckKqUntWQ4#; zXCng_!zKn1hAj-z4BNoQvM?}-fIK;uVII`nl?+VaLN9$cLsR5-h87=fq1J5-?cv%& z-P;)2LD8~}p;u@EL}(I3ND@hC3Peb08^bh+DoAn_(-xWukuiYFXm4Yfjh+g3F>o;K xX5eSo!=S{lm%)@_AA<+O0S14DgA7RwN5D?zU|{^iki^c=#K6d~9$e~e007wLrJMi& literal 0 HcmV?d00001 diff --git a/TP3/fr/iut_fbleau/Nim/NimBoard.java b/TP3/fr/iut_fbleau/Nim/NimBoard.java new file mode 100644 index 0000000..586adf3 --- /dev/null +++ b/TP3/fr/iut_fbleau/Nim/NimBoard.java @@ -0,0 +1,199 @@ +package fr.iut_fbleau.Nim; + +import fr.iut_fbleau.GameAPI.AbstractBoard; +import fr.iut_fbleau.GameAPI.AbstractPly; +import fr.iut_fbleau.GameAPI.Player; +import fr.iut_fbleau.GameAPI.Result; + +import java.util.Iterator; +import java.util.ArrayList; +import java.util.Deque; +import java.util.ArrayDeque; + +/** + * ReprĂ©sente le plateau du jeu de Nim. + * Le jeu de Nim se joue avec un certain nombre d'allumettes. + * Les joueurs retirent Ă  tour de rĂŽle entre 1 et maxParCoup allumettes. + * Le joueur qui retire la derniĂšre allumette perd (variante misĂšre). + */ +public class NimBoard extends AbstractBoard { + + private int allumettesRestantes; + private int maxParCoup; + private int allumettesInitiales; + private Player currentPlayer; + private Deque history; + private boolean gameOver; + private Result result; + + /** + * Constructeur du plateau de Nim + * + * @param allumettesInitiales le nombre d'allumettes au dĂ©but du jeu + * @param maxParCoup le nombre maximum d'allumettes qu'on peut retirer par coup + */ + public NimBoard(int allumettesInitiales, int maxParCoup) { + if (allumettesInitiales <= 0) { + throw new IllegalArgumentException("Le nombre d'allumettes doit ĂȘtre positif"); + } + if (maxParCoup <= 0) { + throw new IllegalArgumentException("Le nombre maximum par coup doit ĂȘtre positif"); + } + + this.allumettesInitiales = allumettesInitiales; + this.allumettesRestantes = allumettesInitiales; + this.maxParCoup = maxParCoup; + this.currentPlayer = Player.PLAYER1; + this.history = new ArrayDeque<>(); + this.gameOver = false; + this.result = null; + } + + /** + * @return le nombre d'allumettes restantes + */ + public int getAllumettesRestantes() { + return this.allumettesRestantes; + } + + /** + * @return le nombre maximum d'allumettes par coup + */ + public int getMaxParCoup() { + return this.maxParCoup; + } + + @Override + public Player getcurrentPlayer() { + return this.currentPlayer; + } + + @Override + public boolean isGameOver() { + return this.gameOver; + } + + @Override + public Result getResult() { + return this.result; + } + + @Override + public boolean isLegal(AbstractPly c) { + if (this.gameOver) { + throw new NullPointerException("Le jeu est terminĂ©"); + } + + if (!(c instanceof NimPly)) { + return false; + } + + NimPly coup = (NimPly) c; + + if (coup.getJoueur() != this.currentPlayer) { + return false; + } + + // VĂ©rifier que le nombre d'allumettes est valide + int nbAllumettes = coup.getNombreAllumettesPrises(); + return nbAllumettes >= 1 && + nbAllumettes <= this.maxParCoup && + nbAllumettes <= this.allumettesRestantes; + } + + @Override + public Iterator iterator() { + if (this.gameOver) { + throw new NullPointerException("Le jeu est terminĂ©"); + } + + ArrayList coups = new ArrayList<>(); + int maxRetirage = Math.min(this.maxParCoup, this.allumettesRestantes); + + for (int i = 1; i <= maxRetirage; i++) { + coups.add(new NimPly(this.currentPlayer, i)); + } + + return coups.iterator(); + } + + @Override + public void doPly(AbstractPly c) { + if (!(c instanceof NimPly)) { + throw new IllegalArgumentException("Le coup doit ĂȘtre un NimPly"); + } + + if (!isLegal(c)) { + throw new IllegalStateException("Ce coup n'est pas lĂ©gal"); + } + + NimPly coup = (NimPly) c; + + // Retirer les allumettes + this.allumettesRestantes -= coup.getNombreAllumettesPrises(); + + // Ajouter le coup Ă  l'historique + this.history.addLast(c); + + // VĂ©rifier si le jeu est terminĂ© + if (this.allumettesRestantes == 0) { + this.gameOver = true; + // Dans la variante misĂšre : celui qui prend la derniĂšre allumette perd + if (this.currentPlayer == Player.PLAYER1) { + this.result = Result.LOSS; + } else { + this.result = Result.WIN; + } + } + + // Changer de joueur + setNextPlayer(); + } + + @Override + public void undoPly() { + if (this.history.isEmpty()) { + throw new IllegalStateException("Rien Ă  annuler dans l'historique"); + } + + AbstractPly dernierCoup = this.history.removeLast(); + NimPly coup = (NimPly) dernierCoup; + + // Remettre les allumettes + this.allumettesRestantes += coup.getNombreAllumettesPrises(); + + // Revenir au joueur prĂ©cĂ©dent + setNextPlayer(); + + // RĂ©initialiser l'Ă©tat du jeu + this.gameOver = false; + this.result = null; + } + + /** + * Change le joueur courant + */ + private void setNextPlayer() { + if (this.currentPlayer == Player.PLAYER1) { + this.currentPlayer = Player.PLAYER2; + } else { + this.currentPlayer = Player.PLAYER1; + } + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("Jeu de Nim\n"); + sb.append("Allumettes restantes : ").append(allumettesRestantes).append("\n"); + sb.append("Maximum par coup : ").append(maxParCoup).append("\n"); + sb.append("Joueur courant : ").append(currentPlayer).append("\n"); + + if (gameOver) { + sb.append("Jeu terminĂ© - RĂ©sultat (du point de vue de PLAYER1) : ").append(result).append("\n"); + } + + return sb.toString(); + } +} + diff --git a/TP3/fr/iut_fbleau/Nim/NimBotPlayer.class b/TP3/fr/iut_fbleau/Nim/NimBotPlayer.class new file mode 100644 index 0000000000000000000000000000000000000000..3eae92328b5a1816e5a27f88ce162354151472b7 GIT binary patch literal 3000 zcmX^0Z`VEs1_nolE-nTp24;2!79Ivx1~x_pjkF^D%+iwhw4|KW#8Q3t#N1TJ08f3# zq~emI#N-kXKOiTuGPQ`2fz2i}FSEpsk%3u5GmMjggMpKsfs2QMn}LUsK@Qazzsy{H zzs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Y3^N%{GRy|Y zj4A`y9|m!DhB(e&42*vn_&`zeo57LkCn$nAVLS##hEj$yNCYv+GB7eQf-*5Em4nh0 vBRJo%fdv;cFf){ceOtj$3C_Pv40Q~Q3{_yVhM@)AFkxh9WoT#UWRL^^Zxr@M literal 0 HcmV?d00001 diff --git a/TP3/fr/iut_fbleau/Nim/NimBotPlayer.java b/TP3/fr/iut_fbleau/Nim/NimBotPlayer.java new file mode 100644 index 0000000..be46efa --- /dev/null +++ b/TP3/fr/iut_fbleau/Nim/NimBotPlayer.java @@ -0,0 +1,166 @@ +package fr.iut_fbleau.Nim; + +import fr.iut_fbleau.GameAPI.AbstractGamePlayer; +import fr.iut_fbleau.GameAPI.AbstractPly; +import fr.iut_fbleau.GameAPI.IBoard; +import fr.iut_fbleau.GameAPI.Player; +import fr.iut_fbleau.GameAPI.Result; + +import java.util.Iterator; + +/** + * ReprĂ©sente un joueur bot pour le jeu de Nim. + * Le bot utilise l'algorithme MiniMax avec Ă©lagage Alpha-Beta pour choisir le meilleur coup. + */ +public class NimBotPlayer extends AbstractGamePlayer { + + private Player joueur; + + /** + * Constructeur d'un bot joueur de Nim + * + * @param joueur le type de joueur (PLAYER1 ou PLAYER2) + */ + public NimBotPlayer(Player joueur) { + this.joueur = joueur; + } + + @Override + public AbstractPly giveYourMove(IBoard p) { + if (!(p instanceof NimBoard)) { + throw new IllegalArgumentException("Le plateau doit ĂȘtre un NimBoard"); + } + + NimBoard plateau = (NimBoard) p; + + System.out.println("\n" + plateau); + System.out.println("Le bot rĂ©flĂ©chit..."); + + AbstractPly meilleurCoup = findBestMove(plateau); + + System.out.println("Le bot joue : " + meilleurCoup); + + return meilleurCoup; + } + + /** + * Trouve le meilleur coup Ă  jouer en utilisant l'algorithme MiniMax avec Alpha-Beta + */ + private AbstractPly findBestMove(NimBoard plateau) { + AbstractPly meilleurCoup = null; + int meilleureValeur; + + if (this.joueur == Player.PLAYER1) { + meilleureValeur = Integer.MIN_VALUE; + + Iterator coups = plateau.iterator(); + while (coups.hasNext()) { + AbstractPly coup = coups.next(); + + plateau.doPly(coup); + int score = minimax(plateau, Integer.MIN_VALUE, Integer.MAX_VALUE, false); + plateau.undoPly(); + + if (score > meilleureValeur) { + meilleureValeur = score; + meilleurCoup = coup; + } + } + } else { + meilleureValeur = Integer.MAX_VALUE; + + Iterator coups = plateau.iterator(); + while (coups.hasNext()) { + AbstractPly coup = coups.next(); + + plateau.doPly(coup); + int score = minimax(plateau, Integer.MIN_VALUE, Integer.MAX_VALUE, true); + plateau.undoPly(); + + if (score < meilleureValeur) { + meilleureValeur = score; + meilleurCoup = coup; + } + } + } + + return meilleurCoup; + } + + /** + * Algorithme MiniMax avec Ă©lagage Alpha-Beta + * + * @param plateau le plateau de jeu + * @param alpha la valeur alpha pour l'Ă©lagage + * @param beta la valeur beta pour l'Ă©lagage + * @param isMaximizing true si on maximise, false si on minimise + * @return l'Ă©valuation de la position + */ + private int minimax(NimBoard plateau, int alpha, int beta, boolean isMaximizing) { + // Condition terminale : jeu fini + if (plateau.isGameOver()) { + Result result = plateau.getResult(); + if (result == Result.WIN) { + return 1; // PLAYER1 gagne + } else if (result == Result.LOSS) { + return -1; // PLAYER1 perd (PLAYER2 gagne) + } else { + return 0; // Match nul + } + } + + if (isMaximizing) { + // Maximiser pour PLAYER1 + int max = Integer.MIN_VALUE; + + Iterator coups = plateau.iterator(); + while (coups.hasNext()) { + AbstractPly coup = coups.next(); + + plateau.doPly(coup); + int eval = minimax(plateau, alpha, beta, false); + plateau.undoPly(); + + max = Math.max(max, eval); + alpha = Math.max(alpha, eval); + + // Élagage Beta + if (beta <= alpha) { + break; + } + } + + return max; + } else { + // Minimiser pour PLAYER2 + int min = Integer.MAX_VALUE; + + Iterator coups = plateau.iterator(); + while (coups.hasNext()) { + AbstractPly coup = coups.next(); + + plateau.doPly(coup); + int eval = minimax(plateau, alpha, beta, true); + plateau.undoPly(); + + min = Math.min(min, eval); + beta = Math.min(beta, eval); + + // Élagage Alpha + if (beta <= alpha) { + break; + } + } + + return min; + } + } + + /** + * @return le type de joueur + */ + public Player getPlayer() { + return this.joueur; + } +} + diff --git a/TP3/fr/iut_fbleau/Nim/NimGame.class b/TP3/fr/iut_fbleau/Nim/NimGame.class new file mode 100644 index 0000000000000000000000000000000000000000..aaa4e53333c9406c40714c99cb47fdabec3cfb64 GIT binary patch literal 3030 zcmX^0Z`VEs1_nolWn2tQ49x5dEIbUX3~Y=H0$GV=iTXK-dFlH8Nm;4MC5#MgHko;u zC3cJq%o>_uoD3Wcoa_u-JPh0nJSfV8D~n4~a~Tt++A4UZmMWyAD)?pQD%jfEa&a*TFbJ|U2=OooGl(!U2xHOA$iQ9z zGAbvJkwH`gVm#QL!6ikRdFj@gVeAZIj0}Qct)(TIIr_oLiFtXcMIa|j@GwX+NHH=n zWrB1=G-u}Pd*&6C!raEiAj%*E3I$n41_`M7Xi7B0I2hy^85|tTQj-;u^K+9jQ}Yy3 z)Dv@ZN^?_7N>Ymz%JNHdQmb^!@=J?B3UX8Pl2eNm>=iU}GxIWYOLG+rH5IHBK)zMv zVNe2jl@;tMkmV{o45|!jj125~sTC!jc_rWg_vB#EU}TWyRY=LtEKxYT zs-!4Yp&-9Fvm`T3L6Mz73l?VJ5OJ+YPAw?O%+KRs&|zfIam_0!I=nJfAv3QmF()%6 zRZk%-wKOv)C$&l;HLs*7wMd~f4{E#~$RT<>4EhWPj0_wghxlaXr7|*zXlOzL4QxI% z#Mv2)7#XC}iu5x}OXAa#a#9mZ_5Ct)LD(rju_%R$!H~fO6r!e#46GWSo}d^qXJnAZ zsv{sLu@V$lmJC+x4AwjhHVn3m3^J%n-4kJ*aLhVBVB_GK>>tMr8O6W z8G}8@B@T=XiW)w6)q-5<#K<6rstE3{5{TuT43-QoJPfWNS3;d(#KqvqV9&we!N?%a z<(!|FmYH5!ln9Cjg_Kf-tkhBkD{RFcyyV1^@XV47=ls0l zlEl1{Vo>V##1h&<42%q391Q-93|6`dL5EkQ=cFoFDfpx+WaXEpmKG@#mS!px6s6{+ zDC8t6q@)(*WgcEpl&SzvoC*Q1K`tB&fs717x(d*MQ?OF-D9ugG%;R7PW@ONUi5n?c zDLCbqC}{X*=4JXORwyKb61-zhK}MpkQ))?~CKo7bLwOj&7{VDDxH5}D5#wK$S_DqA zQ6R}k9)>7}XhsHs^wg5%(xRf&JZQi%GAL+h;*SAPY{l|0#4*G(GVr8lmZe7KmlpZv zm!&c?IOB>uPjHH}#$~c&QgKO9Vsc49PNg*{nqon2OyXfkW=LUVU`@#n$f;yxP{U<7 zvTn^VE`~IQbasXe9)?VYEYut5|&egM&F3ni(0SePC*h6f~UjOEeV_ zIye|w85y{J6HAga6!J=QK*eJ_BZDN?{0vICj0`N!`6;Q44E&(7&aX5#DYYmhF)1gN zk%0x2Hy9bjG@_A05Edt4j10WNC5g$|zKI23_3R9Nj10n9l(I8SU}R84bpXg_P+5kQ zwip?>g7Zs@l2hF>L6-CQW#)oZ>48!ZBZGibetrok6&LuXmSp6o6mu|4Wn_@lRq%sW z49NA6l>#FN!*oUlFS01!N$fEHjl)-l$_LJ z6`%b4?9u{j%)mnuLD3jeS&)iFIdYi75-_F_&WSlW!I>qg){G21o}ilFIVZ8WIJKCa zVG$#PDu$o1IhCDZ2_u6Xex-~IY!H7jC^ED$Ffo7t69Xft{lvh?(80jKAj`nWz{tSB zz^b*KfpH@P0|O&NCj$cm8(5H=fs>(&p&O!3QF!D2guofYeD2FJ)v49?pb+^pC@n%uWB@NZ&Zm)XVO$-n?% z%kEGfZS)U|?dH#4wqGfkA|UnPC@NdPu_D9Qi; literal 0 HcmV?d00001 diff --git a/TP3/fr/iut_fbleau/Nim/NimGame.java b/TP3/fr/iut_fbleau/Nim/NimGame.java new file mode 100644 index 0000000..b2445c7 --- /dev/null +++ b/TP3/fr/iut_fbleau/Nim/NimGame.java @@ -0,0 +1,79 @@ +package fr.iut_fbleau.Nim; + +import fr.iut_fbleau.GameAPI.Player; +import fr.iut_fbleau.GameAPI.AbstractPly; +import java.util.Scanner; + +/** + * Classe principale pour jouer au jeu de Nim. + * Cette classe permet de lancer une partie entre deux joueurs. + */ +public class NimGame { + + public static void main(String[] args) { + System.out.println("=== Jeu de Nim ===\n"); + + Scanner scanner = new Scanner(System.in); + + // Demander le nombre d'allumettes + int allumettesInitiales = 0; + while (allumettesInitiales <= 0) { + System.out.print("Avec combien d'allumettes voulez-vous commencer ? (minimum 1) : "); + try { + allumettesInitiales = scanner.nextInt(); + if (allumettesInitiales <= 0) { + System.out.println("Le nombre doit ĂȘtre positif !"); + } + } catch (Exception e) { + System.out.println("EntrĂ©e invalide. Veuillez entrer un nombre."); + scanner.nextLine(); // vider le buffer + } + } + + // Maximum par coup fixĂ© Ă  3 + int maxParCoup = 3; + + NimBoard plateau = new NimBoard(allumettesInitiales, maxParCoup); + + // CrĂ©er les joueurs + NimPlayer joueur1 = new NimPlayer(Player.PLAYER1); + NimBotPlayer joueur2 = new NimBotPlayer(Player.PLAYER2); + + System.out.println("\nConfiguration du jeu :"); + System.out.println("- Nombre d'allumettes : " + allumettesInitiales); + System.out.println("- Maximum par coup : " + maxParCoup); + System.out.println("- RĂšgle : Le joueur qui prend la derniĂšre allumette PERD"); + System.out.println("- PLAYER1 : Humain"); + System.out.println("- PLAYER2 : Bot (MiniMax avec Alpha-Beta)\n"); + + // Boucle de jeu + while (!plateau.isGameOver()) { + // Obtenir le coup du joueur actif + AbstractPly coup; + if (plateau.getcurrentPlayer() == Player.PLAYER1) { + coup = joueur1.giveYourMove(plateau); + } else { + coup = joueur2.giveYourMove(plateau); + } + + // Jouer le coup + plateau.doPly(coup); + + System.out.println("\n>>> " + coup); + } + + // Afficher le rĂ©sultat + System.out.println("\n=== Fin de la partie ==="); + System.out.println(plateau); + + // DĂ©terminer le gagnant en utilisant l'enum Result + if (plateau.getResult() == fr.iut_fbleau.GameAPI.Result.WIN) { + System.out.println("Le PLAYER1 a gagnĂ© !"); + } else if (plateau.getResult() == fr.iut_fbleau.GameAPI.Result.LOSS) { + System.out.println("Le PLAYER2 (Bot) a gagnĂ© !"); + } else { + System.out.println("Match nul !"); + } + } +} + diff --git a/TP3/fr/iut_fbleau/Nim/NimPlayer.class b/TP3/fr/iut_fbleau/Nim/NimPlayer.class new file mode 100644 index 0000000000000000000000000000000000000000..53071986615a2dd66d69d832eb592e658e75ff03 GIT binary patch literal 2620 zcmX^0Z`VEs1_nolNn8v}49x5dEIbUX3~Y=H8fiuPnWZK1X-PS$iKY7PiMgqc0iODf zNyQ~aiOD4(en3uQWoi*41Dj1|US^3MBLlOBW*8>}2LmTN0~ZeiHvOjVWtb-`DW@q4IWDv|sEKAfcEy>K$4^B?Z%S$cdWDsBw zWM>fKVGw2zVPp^hE67RAOV+hjbdbAFH6iRP4!P>WKcu4$v-J8HMzuE z6A~E6mJ2a3Fc|PK7%~_!GKl9UW~Vym=OrhWglCpyIOpdTmn7zu6r&jib2g@7Tnr`* zrtA!6JPhUxDvS)m;2_M**GKXLBLjN@$VWMOLJW)y1{@4lj0}R#`K1NL3I+Ma#hFPt zsl^IbTnsV{HarZr40enR9GNAlMTsT(MT`t$8c-jAqtg>AZq3c$z~IQv;Kak=%;3Vv zAOyA+MF}GVdq!fhUus1OIORuybhz;_xHEV#GO*-9Ol|pJ>Nl|JMD5vCs15OWQM=lRT9z#AO0|&?spUk{eMh4WF zfd`f+Lm?Y2YuCJT=1@859X90;yqf&QD2YWZ(zc>sOkalv)&$n3R*s$iS1H zS(X}^Us~jwUzW%QjC^^+F z6J#SFyy(>fMI|GHfKz^c38+9X@J%hr$WJNeV5nteVB%urV5nzgkaSj0EiO?g$)I5b0 zb+}xyLRo%kPHL5IS$=7;LJ?H6y@H0JE~BP`l>!GtDQYKa0PKN~|k7efa_Cp$wIC;@geGN^#Orw>j#nR#XT*{S-F7>1NXZi&ey`9+nC z3^S06GpIsHKzJnPrR1a*tN7&SXO|XOW0p!tA}AU|DhpDvD33-`4=o0eGb_{x=fs?x z;LMU#YeohhPf!KtoRe5woLbDz(8tK2is2`0PGx79z{ntnUnwI48^m7>iVPeKObiSR zObkq*>Ke?FVvq*Yj0~&{#SDxLB@7GZ&5My9uC}Svxn8eu4z{0@6z`*cK`yhkN zEC$})404e|3fmc!_G=$tkn!EbpsKTjL30;_J_Exx2IEZ(s#;qZ*uf$eFcBfkZ4Aab z+Ze3-cQV*BGR$O9)7{D7%E)kl!PAO$6N9QKizMqd2Jc-A{$O1#ER4(lU)R~j z5Tvt>A#?{rgc&Q78Jj2@%R&Y&Q8rQ5B@EsmO{}{Z;y~&XwYD%wY-314RU!aYk`7X0 zy!`)REA~wcszO=Y7>pt6bHbPZU$>jVGg4~{1G^~Oc7}ot42%qO84fTUX2@V*0*6l) zgA@Y;gA@ZhgEWI6gB*hxg93vpgCeMIW3XpXWpH6oV{m6sX9!@>V2EbWWXNUEVkltH zW+-ORV`yN|XJ}?HWSGEU#4wk^gkc$jDZ^$4Gll~U)(nRkEEtY5STdYtuwuB%V9juY z!H%JVfq_Aqfm84wsQ#2;XK-ND{>#A6$jGC_kOU|`^4U}WfJ=x3P7APE3IH@oEk literal 0 HcmV?d00001 diff --git a/TP3/fr/iut_fbleau/Nim/NimPlayer.java b/TP3/fr/iut_fbleau/Nim/NimPlayer.java new file mode 100644 index 0000000..e0168c0 --- /dev/null +++ b/TP3/fr/iut_fbleau/Nim/NimPlayer.java @@ -0,0 +1,66 @@ +package fr.iut_fbleau.Nim; + +import fr.iut_fbleau.GameAPI.AbstractGamePlayer; +import fr.iut_fbleau.GameAPI.AbstractPly; +import fr.iut_fbleau.GameAPI.IBoard; +import fr.iut_fbleau.GameAPI.Player; + +import java.util.Scanner; +import java.util.Iterator; + +/** + * ReprĂ©sente un joueur humain pour le jeu de Nim. + */ +public class NimPlayer extends AbstractGamePlayer { + + private Player joueur; + private Scanner scanner; + + public NimPlayer(Player joueur) { + this.joueur = joueur; + this.scanner = new Scanner(System.in); + } + + @Override + public AbstractPly giveYourMove(IBoard p) { + if (!(p instanceof NimBoard)) { + throw new IllegalArgumentException("Le plateau doit ĂȘtre un NimBoard"); + } + + NimBoard plateau = (NimBoard) p; + + System.out.println("\n" + plateau); + System.out.println("C'est ton tour joueur : " + this.joueur); + + // Afficher les coups possibles + System.out.println("Coups possibles :"); + Iterator coups = plateau.iterator(); + int compteur = 1; + while (coups.hasNext()) { + NimPly coup = (NimPly) coups.next(); + System.out.println(" " + compteur + ". Retirer " + coup.getNombreAllumettesPrises() + " allumette(s)"); + compteur++; + } + + // Demander au joueur de choisir + int maxAllumettes = Math.min(plateau.getMaxParCoup(), plateau.getAllumettesRestantes()); + int choix = -1; + + while (choix < 1 || choix > maxAllumettes) { + System.out.print("Combien d'allumettes voulez-vous retirer ? (1-" + maxAllumettes + ") : "); + try { + choix = scanner.nextInt(); + if (choix < 1 || choix > maxAllumettes) { + System.out.println("Choix invalide. Veuillez choisir entre 1 et " + maxAllumettes); + } + } catch (Exception e) { + System.out.println("EntrĂ©e invalide. Veuillez entrer un nombre."); + scanner.nextLine(); // vider le buffer + } + } + + return new NimPly(this.joueur, choix); + } +} + + diff --git a/TP3/fr/iut_fbleau/Nim/NimPly.class b/TP3/fr/iut_fbleau/Nim/NimPly.class new file mode 100644 index 0000000000000000000000000000000000000000..b37ab2013ae386ce6061fb9b7157fafe3cf89b89 GIT binary patch literal 1203 zcmX^0Z`VEs1_nn4Q!WN324;2!79Ivx1~x_p#k3;*%+iwhw4|KW#8Q3t#N1TJ08f3# zq~emI#N?8IoJvLpHk-`6%o00B24)S-Fir*z22OScE*=JM1|CKR2~_=lnYsFYnYj>c zS^1@@rA3Skaz3bvV3q{rBvz&tS%XaE<6+=u5MX2w%gfJADoSZ!WDv+oEKAhSNz6;v4=yRn%u8ovU@uF|DNXfHV`Na% z@IgrXCuOB3mso2e2|;vN3o$S-NboR7GDtBpi039|r#k27B`21IXO?6*=jRodB<7VA zGcu?n8wSCs7?>ECKsgJ{;%5+GU|?WjU}Rur zkY-?HkYQk8Fb3sc1_lOxt?dkqTH0F~*tKM~GVpF>U|?WmkY!+C5Mp2fNi(o82rzIm z2r}?72r)1+$T7%64UlDEWME`qU|`kS!oa=(u8j>WD8azUpunJrMJewZG^HT(lo*tu zN;Mgnzy=6{Ox?i%qIh>Ph%+#t+n~(A%%B4HohpMG0|NsG10#bb10#bvgFXWT0~Z4$ Mg8_pPg9(Eq05l3M)c^nh literal 0 HcmV?d00001 diff --git a/TP3/fr/iut_fbleau/Nim/NimPly.java b/TP3/fr/iut_fbleau/Nim/NimPly.java new file mode 100644 index 0000000..7c6396f --- /dev/null +++ b/TP3/fr/iut_fbleau/Nim/NimPly.java @@ -0,0 +1,38 @@ +package fr.iut_fbleau.Nim; + +import fr.iut_fbleau.GameAPI.AbstractPly; +import fr.iut_fbleau.GameAPI.Player; + +/** + * ReprĂ©sente un coup dans le jeu de Nim. + * Un coup consiste Ă  retirer un certain nombre d'allumettes. + */ +public class NimPly extends AbstractPly { + + private Player joueur; + private int nombreAllumettesPrises; + + public NimPly(Player joueur, int nombreAllumettesPrises) { + this.joueur = joueur; + this.nombreAllumettesPrises = nombreAllumettesPrises; + } + + /** + * @return le joueur qui effectue le coup + */ + public Player getJoueur() { + return this.joueur; + } + + /** + * @return le nombre d'allumettes prises + */ + public int getNombreAllumettesPrises() { + return this.nombreAllumettesPrises; + } + + public String toString() { + return "Joueur " + joueur + " retire " + nombreAllumettesPrises + " allumette(s)"; + } +} + diff --git a/test b/test deleted file mode 100644 index e69de29..0000000