From a638dd8c3f073b4a74131542ecac7b6546d5794e Mon Sep 17 00:00:00 2001 From: Mysaa Date: Tue, 11 Jan 2022 00:15:46 +0100 Subject: [PATCH] =?UTF-8?q?Fin=20des=20fonctions.=20On=20devrait=20avoir?= =?UTF-8?q?=20un=20truc=20fonctionnel,=20=C3=A0=20peu=20pr=C3=A8s.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tarotinator/src/Main.hs | 36 +++++++++++++++++++++++++++--------- tarotinator/src/Tarot.hs | 14 +++++++------- tarotinator/src/TarotIAs.hs | 1 + 3 files changed, 35 insertions(+), 16 deletions(-) diff --git a/tarotinator/src/Main.hs b/tarotinator/src/Main.hs index 5536db8..09519b0 100644 --- a/tarotinator/src/Main.hs +++ b/tarotinator/src/Main.hs @@ -1,17 +1,35 @@ import Cartes +import Tarot +import TarotIAs import System.Random.Shuffle import Data.Set +import Data.Foldable main :: IO () main = do - donne <- shuffleM $ toList deck + donne <- shuffleM $ Data.Set.toList deck let - taz = distribuer randomizedGame - infiniteSteps = iterate singleStep taz - steps = takeWhile (not . isDone) infiniteSteps - for_ steps $ \(x,y) -> do - print (length x, length y) - putStrLn $ prettyDeck x - putStrLn $ prettyDeck y - putStrLn "" + ([cartes1,cartes2,cartes3,cartes4,cartes5],chien) = distribuer donne + (s0,s1,s2,s3,s4) = (distrib cartes1 0, distrib cartes2 1, distrib cartes3 2, distrib cartes4 3, distrib cartes5 4) :: (RandomIA,RandomIA,RandomIA,RandomIA,RandomIA) + -- C'est le premier qui prends, parce que ..... j'ai décidé. + (s0',s1',s2',s3',s4') = (debutPartie s0 0, debutPartie s1 0, debutPartie s2 0, debutPartie s3 0,debutPartie s4 0) + + etat0 = EtatPartie (0,(s0',s1',s2',s3',s4'),[cartes1,cartes2,cartes3,cartes4,cartes5],[chien,[],[],[],[]]) + + cartesJouees = iterate (jouerPli . fst) (etat0,[]) + + steps = Prelude.take 15 $ Prelude.drop 1 cartesJouees + putStr "Joueur 1 :" + putStrLn (show cartes1) + putStr "Joueur 2 :" + putStrLn (show cartes2) + putStr "Joueur 3 :" + putStrLn (show cartes3) + putStr "Joueur 4 :" + putStrLn (show cartes4) + putStr "Joueur 5 :" + putStrLn (show cartes5) + putStrLn "" + for_ steps $ \(state,pli) -> do + putStrLn $ show pli diff --git a/tarotinator/src/Tarot.hs b/tarotinator/src/Tarot.hs index 7b60f96..83193dc 100644 --- a/tarotinator/src/Tarot.hs +++ b/tarotinator/src/Tarot.hs @@ -36,7 +36,7 @@ couleurPli (e:s) -- Renvoie la carte qui a fait le pli gagnantPli :: [Carte] -> Maybe Carte gagnantPli [] = Nothing -pli (e:s) = case (e, w) of { +gagnantPli (e:s) = case (e, w) of { (_, Nothing) -> Just e; -- La seule carte d'un pli le gagne (_, Just Excuse) -> Just e; -- Si juste une excuse a été jouée, la nouvelle carte gagne le pli. (Atout n, Just (Atout m)) -> Just (Atout (max n m)); -- L'atout le plus haut gagne @@ -88,7 +88,7 @@ distribuer l = ([j1,j2,j3,j4,j5],chien) (j4,r4) = splitAt 15 r3 (j5,chien) = splitAt 15 r4 -newtype EtatPartie j1 j2 j3 j4 j5 = EtatPartie (Int,(j1,j2,j3,j4,j5),[[Carte]],[[Carte]]) +newtype EtatPartie j1 j2 j3 j4 j5 = EtatPartie (Int,(j1,j2,j3,j4,j5),[[Carte]],[[Carte]]) deriving Show jouerPliAux :: (JoueurIA j1, JoueurIA j2, JoueurIA j3, JoueurIA j4, JoueurIA j5) => Int -> (j1,j2,j3,j4,j5) -> [[Carte]] -> [Carte] -> [[Carte]] -> (EtatPartie j1 j2 j3 j4 j5, [Carte]) @@ -108,8 +108,8 @@ jouerPli (EtatPartie (0,joueurs,jeux,points)) = jouerPliAux 0 etats jeux pli poi (c3,e3) = jouer (thr5 joueurs) [c1,c2] (c4,e4) = jouer (frh5 joueurs) [c1,c2,c3] (c5,e5) = jouer (fih5 joueurs) [c1,c2,c3,c4] - etats = (e1,e2,e3,e4,e5) pli = [c1,c2,c3,c4,c5] + etats = (finTour e1 pli, finTour e2 pli, finTour e3 pli, finTour e4 pli, finTour e5 pli) jouerPli (EtatPartie (1,joueurs,jeux,points)) = jouerPliAux 1 etats jeux pli points -- TODO l'excuse n'est pas gérée where @@ -118,8 +118,8 @@ jouerPli (EtatPartie (1,joueurs,jeux,points)) = jouerPliAux 1 etats jeux pli poi (c4,e4) = jouer (frh5 joueurs) [c2,c3] (c5,e5) = jouer (fih5 joueurs) [c2,c3,c4] (c1,e1) = jouer (fst5 joueurs) [c2,c3,c4,c5] - etats = (e1,e2,e3,e4,e5) pli = [c2,c3,c4,c5,c1] + etats = (finTour e1 pli, finTour e2 pli, finTour e3 pli, finTour e4 pli, finTour e5 pli) jouerPli (EtatPartie (2,joueurs,jeux,points)) = jouerPliAux 2 etats jeux pli points -- TODO l'excuse n'est pas gérée where @@ -128,8 +128,8 @@ jouerPli (EtatPartie (2,joueurs,jeux,points)) = jouerPliAux 2 etats jeux pli poi (c5,e5) = jouer (fih5 joueurs) [c3,c4] (c1,e1) = jouer (fst5 joueurs) [c3,c4,c5] (c2,e2) = jouer (snd5 joueurs) [c3,c4,c5,c1] - etats = (e1,e2,e3,e4,e5) pli = [c3,c4,c5,c1,c2] + etats = (finTour e1 pli, finTour e2 pli, finTour e3 pli, finTour e4 pli, finTour e5 pli) jouerPli (EtatPartie (3,joueurs,jeux,points)) = jouerPliAux 3 etats jeux pli points -- TODO l'excuse n'est pas gérée where @@ -139,8 +139,8 @@ jouerPli (EtatPartie (3,joueurs,jeux,points)) = jouerPliAux 3 etats jeux pli poi (c1,e1) = jouer (fst5 joueurs) [c4,c5] (c2,e2) = jouer (snd5 joueurs) [c4,c5,c1] (c3,e3) = jouer (thr5 joueurs) [c4,c5,c1,c2] - etats = (e1,e2,e3,e4,e5) pli = [c4,c5,c1,c2,c3] + etats = (finTour e1 pli, finTour e2 pli, finTour e3 pli, finTour e4 pli, finTour e5 pli) jouerPli (EtatPartie (4,joueurs,jeux,points)) = jouerPliAux 4 etats jeux pli points -- TODO l'excuse n'est pas gérée where @@ -149,8 +149,8 @@ jouerPli (EtatPartie (4,joueurs,jeux,points)) = jouerPliAux 4 etats jeux pli poi (c2,e2) = jouer (snd5 joueurs) [c5,c1] (c3,e3) = jouer (thr5 joueurs) [c5,c1,c2] (c4,e4) = jouer (frh5 joueurs) [c5,c1,c2,c3] - etats = (e1,e2,e3,e4,e5) pli = [c5,c1,c2,c3,c4] + etats = (finTour e1 pli, finTour e2 pli, finTour e3 pli, finTour e4 pli, finTour e5 pli) diff --git a/tarotinator/src/TarotIAs.hs b/tarotinator/src/TarotIAs.hs index 14b9aa0..e10ef1d 100644 --- a/tarotinator/src/TarotIAs.hs +++ b/tarotinator/src/TarotIAs.hs @@ -13,3 +13,4 @@ instance JoueurIA RandomIA where jouer (MonJeu cartes) pli = (joué, MonJeu (delete joué cartes)) where joué = minimum [carte | carte<-cartes, peutJouer carte cartes pli] finTour cartes pli = cartes +