From 81fe9fad197c3a25193d955979dc62a240c228a7 Mon Sep 17 00:00:00 2001 From: Mysaa Date: Mon, 10 Jan 2022 14:44:04 +0100 Subject: [PATCH] =?UTF-8?q?Calcul=20du=20pli=20effectu=C3=A9=20mais=20non?= =?UTF-8?q?=20teste.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tarotinator/src/Cartes.hs | 14 ++++ tarotinator/src/Tarot.hs | 121 ++++++++++++++++++++++++++++++++-- tarotinator/tarotinator.cabal | 4 +- 3 files changed, 132 insertions(+), 7 deletions(-) diff --git a/tarotinator/src/Cartes.hs b/tarotinator/src/Cartes.hs index 9464d06..b1aee0e 100644 --- a/tarotinator/src/Cartes.hs +++ b/tarotinator/src/Cartes.hs @@ -30,3 +30,17 @@ replaceNth :: [a] -> Int -> a -> [a] replaceNth (e:s) i newElement | i==0 = newElement:s | otherwise = replaceNth s (i-1) newElement + +toPentuple :: [a] -> (a,a,a,a,a) +toPentuple [j1,j2,j3,j4,j5] = (j1,j2,j3,j4,j5) + +fst5 :: (a,b,c,d,e) -> a +fst5 (x,y,z,t,u) = x +snd5 :: (a,b,c,d,e) -> b +snd5 (x,y,z,t,u) = y +thr5 :: (a,b,c,d,e) -> c +thr5 (x,y,z,t,u) = z +frh5 :: (a,b,c,d,e) -> d +frh5 (x,y,z,t,u) = t +fih5 :: (a,b,c,d,e) -> e +fih5 (x,y,z,t,u) = u diff --git a/tarotinator/src/Tarot.hs b/tarotinator/src/Tarot.hs index 9df9974..7b60f96 100644 --- a/tarotinator/src/Tarot.hs +++ b/tarotinator/src/Tarot.hs @@ -3,6 +3,7 @@ module Tarot where import Cartes import Data.List import Data.Maybe +import Data.List.HT (rotate) -- Du point de vue du joueur, la position d'un joueur est le nombre de tours que notre joueur a d'avance. Donc le joueur 1 est celui qui joue après nous, 0 est nous-même et 9 est celui qui joue avant nous. class JoueurIA s where @@ -87,15 +88,125 @@ distribuer l = ([j1,j2,j3,j4,j5],chien) (j4,r4) = splitAt 15 r3 (j5,chien) = splitAt 15 r4 -type EtatPartie = ([[Carte]],[[Carte]]) +newtype EtatPartie j1 j2 j3 j4 j5 = EtatPartie (Int,(j1,j2,j3,j4,j5),[[Carte]],[[Carte]]) + + +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]) +jouerPliAux main etats jeux pli points = (EtatPartie (vraiIndiceGagnant, etats, [delete c jeu | (c,jeu)<-(zip (rotate (5-main) pli) jeux)], replaceNth points vraiIndiceGagnant (pli ++ (points !! vraiIndiceGagnant))), pli) + where + vraiIndiceGagnant = (mod (main+indiceGagnant) 5) + indiceGagnant = fromJust $ elemIndex (fromJust $ gagnantPli pli) (pli) + -- Le premier élément de la liste de joueur (le plus profond) est le premier joueur -- Renvoie le nouvel état de la partie ainsi qu'une copie du pli joué. -jouerPli :: JoueurIA j => [j] -> EtatPartie -> ([j],EtatPartie,[Carte]) -jouerPli joueurs (jeux,points) = (etats, ([delete c jeu | (c,jeu)<-(zip pli jeux)], replaceNth points indiceGagnant (pli ++ (points !! indiceGagnant))), pli) -- TODO l'excuse n'est pas gérée +jouerPli :: (JoueurIA j1, JoueurIA j2, JoueurIA j3, JoueurIA j4, JoueurIA j5) => (EtatPartie j1 j2 j3 j4 j5) -> (EtatPartie j1 j2 j3 j4 j5, [Carte]) +jouerPli (EtatPartie (0,joueurs,jeux,points)) = jouerPliAux 0 etats jeux pli points -- TODO l'excuse n'est pas gérée where - (pli,etats)=foldr (\joueur -> \(pli,etats) -> let (carte,etat) = jouer joueur pli in (carte:pli,etat:etats)) ([],[]) joueurs - indiceGagnant = fromJust $ elemIndex (fromJust $ gagnantPli pli) (pli) + (c1,e1) = jouer (fst5 joueurs) [] + (c2,e2) = jouer (snd5 joueurs) [c1] + (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] + +jouerPli (EtatPartie (1,joueurs,jeux,points)) = jouerPliAux 1 etats jeux pli points -- TODO l'excuse n'est pas gérée + where + (c2,e2) = jouer (snd5 joueurs) [] + (c3,e3) = jouer (thr5 joueurs) [c2] + (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] + +jouerPli (EtatPartie (2,joueurs,jeux,points)) = jouerPliAux 2 etats jeux pli points -- TODO l'excuse n'est pas gérée + where + (c3,e3) = jouer (thr5 joueurs) [] + (c4,e4) = jouer (frh5 joueurs) [c3] + (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] + +jouerPli (EtatPartie (3,joueurs,jeux,points)) = jouerPliAux 3 etats jeux pli points -- TODO l'excuse n'est pas gérée + where + -- (pli,etats)=foldr (\joueur -> \(pli,etats) -> let (carte,etat) = jouer joueur pli in (carte:pli,etat:etats)) ([],[]) joueurs + (c4,e4) = jouer (frh5 joueurs) [] + (c5,e5) = jouer (fih5 joueurs) [c4] + (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] + +jouerPli (EtatPartie (4,joueurs,jeux,points)) = jouerPliAux 4 etats jeux pli points -- TODO l'excuse n'est pas gérée + where + (c5,e5) = jouer (fih5 joueurs) [] + (c1,e1) = jouer (fst5 joueurs) [c5] + (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] + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tarotinator/tarotinator.cabal b/tarotinator/tarotinator.cabal index f4c2eca..7bf138a 100644 --- a/tarotinator/tarotinator.cabal +++ b/tarotinator/tarotinator.cabal @@ -19,7 +19,7 @@ library exposed-modules: Cartes, Tarot other-modules: -- other-extensions: - build-depends: base >=4.11 && <4.12, containers, random-shuffle, random, MonadRandom + build-depends: base >=4.11 && <4.12, containers, random-shuffle, random, MonadRandom, utility-ht hs-source-dirs: src default-language: Haskell2010 @@ -27,6 +27,6 @@ executable tarotinator main-is: Main.hs other-modules: Cartes, Tarot, TarotIAs -- other-extensions: - build-depends: base >=4.11 && <4.12, containers, random-shuffle, random, MonadRandom + build-depends: base >=4.11 && <4.12, containers, random-shuffle, random, MonadRandom, utility-ht hs-source-dirs: src default-language: Haskell2010