From 1e7dcf27259740bf958a6036bffe4be8861f8ded Mon Sep 17 00:00:00 2001 From: Delfred353 <94049120+Delfred353@users.noreply.github.com> Date: Mon, 29 Apr 2024 18:12:59 +0200 Subject: [PATCH 01/17] err labyrinthe MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit L'idée est là, mais elle est seule --- src/main/scala/labyrinthe/Labyrinthe.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/scala/labyrinthe/Labyrinthe.scala b/src/main/scala/labyrinthe/Labyrinthe.scala index 5519a09..1728c5d 100755 --- a/src/main/scala/labyrinthe/Labyrinthe.scala +++ b/src/main/scala/labyrinthe/Labyrinthe.scala @@ -91,7 +91,7 @@ object Labyrinthe { * La solution tient en une courte ligne. */ - val agencementPlein: Agencement = ??? // test TODO + val agencementPlein: Agencement = for (x in range (Position._0)){for (y in range (Position._1)){Cellule(Ferme, Ferme)}}) /** Agencement avec des murs nulle part */ From 507da24594534487a4a853a97fc15d5ef20ae811 Mon Sep 17 00:00:00 2001 From: Delfred353 <94049120+Delfred353@users.noreply.github.com> Date: Thu, 2 May 2024 20:57:44 +0200 Subject: [PATCH 02/17] Update Labyrinthe.scala Suppression de certains commentaires --- src/main/scala/labyrinthe/Labyrinthe.scala | 24 +++++++++++----------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/main/scala/labyrinthe/Labyrinthe.scala b/src/main/scala/labyrinthe/Labyrinthe.scala index 1728c5d..4ab7f64 100755 --- a/src/main/scala/labyrinthe/Labyrinthe.scala +++ b/src/main/scala/labyrinthe/Labyrinthe.scala @@ -32,20 +32,20 @@ object Labyrinthe { val authors = List( /* Identification de l'étudiant n°1 */ Map( - "nom" -> "Videcoq", // TODO compléter (garder les guillemets) - "prénom" -> "Lucas", // TODO compléter (garder les guillemets) - "numéro" -> "23111447", // TODO compléter (garder les guillemets) - "email" -> "lucas.videcoq@etudiant.univ-rennes1.fr", // TODO compléter (garder les guillemets) - "emailEnseignant" -> "leo.cosseron@ens-rennes.fr" // TODO compléter (garder les guillemets) + "nom" -> "Videcoq", + "prénom" -> "Lucas", + "numéro" -> "23111447", + "email" -> "lucas.videcoq@etudiant.univ-rennes1.fr", + "emailEnseignant" -> "leo.cosseron@ens-rennes.fr" ), /* Identification de l'étudiant n°2 */ Map( - "nom" -> "Merrer", // TODO compléter (garder les guillemets) - "prénom" -> "Nicolas", // TODO compléter (garder les guillemets) - "numéro" -> "22102431", // TODO compléter (garder les guillemets) - "email" -> "nicolas.merrer@etudiant.univ-rennes1.fr", // TODO compléter (garder les guillemets) - "emailEnseignant" -> "leo.cosseron@ens-rennes.fr" // TODO compléter (garder les guillemets) + "nom" -> "Merrer", + "prénom" -> "Nicolas", + "numéro" -> "22102431", + "email" -> "nicolas.merrer@etudiant.univ-rennes1.fr", + "emailEnseignant" -> "leo.cosseron@ens-rennes.fr" ) ) @@ -91,8 +91,8 @@ object Labyrinthe { * La solution tient en une courte ligne. */ - val agencementPlein: Agencement = for (x in range (Position._0)){for (y in range (Position._1)){Cellule(Ferme, Ferme)}}) - + val agencementPlein: Agencement = Position => Cellule(Ferme,Ferme) // ( Position => for (x in range (Position._0)){for (y in range (Position._1)){Cellule(Ferme, Ferme)}}) + print(agencementPlein) /** Agencement avec des murs nulle part */ val agencementVide: Agencement = ??? // TODO From 51603b8bdd775ec82ae38fa365e22662e8c5fb9a Mon Sep 17 00:00:00 2001 From: Delfred353 <94049120+Delfred353@users.noreply.github.com> Date: Thu, 2 May 2024 23:00:49 +0200 Subject: [PATCH 03/17] test test --- src/main/scala/labyrinthe/Labyrinthe.scala | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/scala/labyrinthe/Labyrinthe.scala b/src/main/scala/labyrinthe/Labyrinthe.scala index 4ab7f64..0c421dd 100755 --- a/src/main/scala/labyrinthe/Labyrinthe.scala +++ b/src/main/scala/labyrinthe/Labyrinthe.scala @@ -95,8 +95,8 @@ object Labyrinthe { print(agencementPlein) /** Agencement avec des murs nulle part */ - val agencementVide: Agencement = ??? // TODO - + val agencementVide: Agencement = Position => Cellule(Ouvert,Ouvert) + print(agencementVide) /** Type des labyrinthes * * @constructor crée un nouveau labyrinthe. From 2463d214673f8d277f7ba64be0f491bde660d2ed Mon Sep 17 00:00:00 2001 From: Delfred353 <94049120+Delfred353@users.noreply.github.com> Date: Fri, 3 May 2024 15:23:45 +0200 Subject: [PATCH 04/17] 3 --- src/main/scala/labyrinthe/Labyrinthe.scala | 38 +++++++++++++--------- src/main/scala/labyrinthe/Main.scala | 10 ++---- 2 files changed, 24 insertions(+), 24 deletions(-) diff --git a/src/main/scala/labyrinthe/Labyrinthe.scala b/src/main/scala/labyrinthe/Labyrinthe.scala index 0c421dd..c219f43 100755 --- a/src/main/scala/labyrinthe/Labyrinthe.scala +++ b/src/main/scala/labyrinthe/Labyrinthe.scala @@ -32,20 +32,20 @@ object Labyrinthe { val authors = List( /* Identification de l'étudiant n°1 */ Map( - "nom" -> "Videcoq", - "prénom" -> "Lucas", - "numéro" -> "23111447", - "email" -> "lucas.videcoq@etudiant.univ-rennes1.fr", - "emailEnseignant" -> "leo.cosseron@ens-rennes.fr" + "nom" -> "Videcoq", + "prénom" -> "Lucas", + "numéro" -> "23111447", + "email" -> "lucas.videcoq@etudiant.univ-rennes1.fr", + "emailEnseignant" -> "leo.cosseron@ens-rennes.fr" ), /* Identification de l'étudiant n°2 */ Map( - "nom" -> "Merrer", - "prénom" -> "Nicolas", - "numéro" -> "22102431", - "email" -> "nicolas.merrer@etudiant.univ-rennes1.fr", - "emailEnseignant" -> "leo.cosseron@ens-rennes.fr" + "nom" -> "Merrer", + "prénom" -> "Nicolas", + "numéro" -> "22102431", + "email" -> "nicolas.merrer@etudiant.univ-rennes1.fr", + "emailEnseignant" -> "leo.cosseron@ens-rennes.fr" ) ) @@ -91,12 +91,17 @@ object Labyrinthe { * La solution tient en une courte ligne. */ - val agencementPlein: Agencement = Position => Cellule(Ferme,Ferme) // ( Position => for (x in range (Position._0)){for (y in range (Position._1)){Cellule(Ferme, Ferme)}}) - print(agencementPlein) + val agencementPlein: Agencement = + Position => + Cellule( + Ferme, + Ferme + ) // ( Position => for (x in range (Position._0)){for (y in range (Position._1)){Cellule(Ferme, Ferme)}}) + /** Agencement avec des murs nulle part */ - val agencementVide: Agencement = Position => Cellule(Ouvert,Ouvert) - print(agencementVide) + val agencementVide: Agencement = Position => Cellule(Ouvert, Ouvert) + /** Type des labyrinthes * * @constructor crée un nouveau labyrinthe. @@ -126,8 +131,9 @@ object Labyrinthe { * @note utile pour créer des agencements par manipulations de * booléens. */ - def booleanToPassage(b: Boolean): Passage = - ??? // TODO + def booleanToPassage(b: Boolean): Passage = { + if b then Ouvert else Ferme + } // TODO /** @param hauteur hauteur d'un labyrinthe * @param largeur largeur d'une labyrinthe diff --git a/src/main/scala/labyrinthe/Main.scala b/src/main/scala/labyrinthe/Main.scala index 70c85fa..b4124e0 100755 --- a/src/main/scala/labyrinthe/Main.scala +++ b/src/main/scala/labyrinthe/Main.scala @@ -1,6 +1,5 @@ package labyrinthe - import fr.istic.scribble.* import Labyrinthe.* import Cellule.* @@ -13,9 +12,6 @@ object Main extends App { val laby: Labyrinthe = labyrintheFourni println(show(laby)) // Affiche le labyrinthe dans le terminal - - - /* Décommentez la ligne suivante une fois que les fonctions labToImage et etatLabyrinthe sont définies : */ @@ -25,8 +21,6 @@ object Main extends App { décommentez la ligne ci-dessous qui attend que l'utilisateur appuie sur la touche « entrée » afin que le jeu ne s'arrête pas immédiatement. */ - // val _ = scala.io.StdIn.readLine() - - + val _ = scala.io.StdIn.readLine() -} \ No newline at end of file +} From 60f1f127e133e5f999f52f59d2c84d39aaee98f0 Mon Sep 17 00:00:00 2001 From: Delfred353 <94049120+Delfred353@users.noreply.github.com> Date: Fri, 3 May 2024 15:56:58 +0200 Subject: [PATCH 05/17] Laby 4 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Avancement sur les fonctions de sortie et d'entrée labyrinthe ainsi que sur le constructeur labyrinthe --- src/main/scala/labyrinthe/Labyrinthe.scala | 14 +++++++------- src/main/scala/labyrinthe/Main.scala | 1 - 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/src/main/scala/labyrinthe/Labyrinthe.scala b/src/main/scala/labyrinthe/Labyrinthe.scala index c219f43..857a639 100755 --- a/src/main/scala/labyrinthe/Labyrinthe.scala +++ b/src/main/scala/labyrinthe/Labyrinthe.scala @@ -185,7 +185,7 @@ object Labyrinthe { hauteur: Int, largeur: Int, g: (Int, Int) => Agencement - ): Labyrinthe = ??? // TODO + ): Labyrinthe = Labyrinthe(hauteur, largeur, g(hauteur, largeur)) /* Affichage graphique d'un labyrinthe */ @@ -195,14 +195,14 @@ object Labyrinthe { * « sud-ouest. » */ def entreeLabyrinthe(laby: Labyrinthe): Position = - ??? // TODO + (laby.hauteur, 0) - /** @param laby un labyrinthe - * @return la position de la sortie du labyrinthe laby, - * qui par convention est « au nord-est. » - */ + /** @param laby un labyrinthe + * @return la position de la sortie du labyrinthe laby, + * qui par convention est « au nord-est. » + */ def sortieLabyrinthe(laby: Labyrinthe): Position = - ??? // TODO + (0, 0) /** EtatLabyrinthe * diff --git a/src/main/scala/labyrinthe/Main.scala b/src/main/scala/labyrinthe/Main.scala index b4124e0..a80e3f5 100755 --- a/src/main/scala/labyrinthe/Main.scala +++ b/src/main/scala/labyrinthe/Main.scala @@ -22,5 +22,4 @@ object Main extends App { touche « entrée » afin que le jeu ne s'arrête pas immédiatement. */ val _ = scala.io.StdIn.readLine() - } From 2814be805c4291004cf939b9789fc000bb8940e5 Mon Sep 17 00:00:00 2001 From: Delfred353 <94049120+Delfred353@users.noreply.github.com> Date: Fri, 3 May 2024 16:27:37 +0200 Subject: [PATCH 06/17] Update Labyrinthe.scala etatinitial de ces morts --- src/main/scala/labyrinthe/Labyrinthe.scala | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/scala/labyrinthe/Labyrinthe.scala b/src/main/scala/labyrinthe/Labyrinthe.scala index 857a639..c97d236 100755 --- a/src/main/scala/labyrinthe/Labyrinthe.scala +++ b/src/main/scala/labyrinthe/Labyrinthe.scala @@ -1,6 +1,7 @@ package labyrinthe import Cellule.* import fr.istic.scribble.* +import labyrinthe.Labyrinthe.EtatLabyrinthe object Labyrinthe { @@ -217,7 +218,8 @@ object Labyrinthe { * la cellule d'entrée est la cellule courante * et toutes les autres sont non visitées. */ - def etatInitial(laby: Labyrinthe): EtatLabyrinthe = ??? // TODO + def etatInitial(laby: Labyrinthe): EtatLabyrinthe = EtatLabyrinthe(0, 0) = + Courante(Nil) // TODO /** @param laby Un labyrinthe * @param etat Une fonction décrivant l'état de chaque cellule From e821043554c3f2eed7fde867942275db0ac1385c Mon Sep 17 00:00:00 2001 From: Delfred353 <94049120+Delfred353@users.noreply.github.com> Date: Fri, 3 May 2024 19:34:49 +0200 Subject: [PATCH 07/17] Update Labyrinthe.scala --- src/main/scala/labyrinthe/Labyrinthe.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/scala/labyrinthe/Labyrinthe.scala b/src/main/scala/labyrinthe/Labyrinthe.scala index c97d236..ea694f2 100755 --- a/src/main/scala/labyrinthe/Labyrinthe.scala +++ b/src/main/scala/labyrinthe/Labyrinthe.scala @@ -134,7 +134,7 @@ object Labyrinthe { */ def booleanToPassage(b: Boolean): Passage = { if b then Ouvert else Ferme - } // TODO + } /** @param hauteur hauteur d'un labyrinthe * @param largeur largeur d'une labyrinthe From 256327d508fcc721387254b732bea95b62ac6961 Mon Sep 17 00:00:00 2001 From: Delfred353 <94049120+Delfred353@users.noreply.github.com> Date: Mon, 6 May 2024 09:28:23 +0200 Subject: [PATCH 08/17] labToImage de ces morts --- src/main/scala/labyrinthe/Labyrinthe.scala | 98 +++++++++++++--------- 1 file changed, 60 insertions(+), 38 deletions(-) diff --git a/src/main/scala/labyrinthe/Labyrinthe.scala b/src/main/scala/labyrinthe/Labyrinthe.scala index ea694f2..7c8c837 100755 --- a/src/main/scala/labyrinthe/Labyrinthe.scala +++ b/src/main/scala/labyrinthe/Labyrinthe.scala @@ -2,6 +2,7 @@ package labyrinthe import Cellule.* import fr.istic.scribble.* import labyrinthe.Labyrinthe.EtatLabyrinthe +import labyrinthe.Main.laby object Labyrinthe { @@ -218,8 +219,12 @@ object Labyrinthe { * la cellule d'entrée est la cellule courante * et toutes les autres sont non visitées. */ - def etatInitial(laby: Labyrinthe): EtatLabyrinthe = EtatLabyrinthe(0, 0) = - Courante(Nil) // TODO + def etatInitial(laby: Labyrinthe): EtatLabyrinthe = { p => + p match { + case (laby.hauteur, 0) => Courante(Nil) + case _ => NonVisitee + } + } /** @param laby Un labyrinthe * @param etat Une fonction décrivant l'état de chaque cellule @@ -231,48 +236,65 @@ object Labyrinthe { * Indication de longueur : une vingtaine de lignes au total, * décomposées en fonctions ou expressions auxiliaires courtes. */ - def labToImage(laby: Labyrinthe, etat: EtatLabyrinthe): Image = + def labToImage(laby: Labyrinthe, etat: EtatLabyrinthe): Image = { + val y = laby.hauteur + val x = laby.largeur + p: Tuple => + (x, y) match { + case (0, 0) => + celluleToImage(laby.f((0, 0)), Some(marqueurSortie), etat((0, 0))) + case (laby.hauteur, 0) => + celluleToImage( + laby.f((laby.hauteur, 0)), + Some(marqueurEntree), + etat((laby.hauteur, 0)) + ) + case _ => celluleToImage(laby.f((x, y)), None, etat((x, y))) + } + } - /** @param p une position dans le labyrinthe laby - * @return optionnellement, le marqueur à placer dans la cellule de position - * p du labyrinthe laby. - */ - def marqueur(p: Position): Option[Image] = ??? // TODO + // TODO - /** @param p une position dans le labyrinthe laby - * @return l'image de la cellule de laby à cette position - */ - def imageCellule(p: Position): Image = ??? // TODO + /** @param p une position dans le labyrinthe laby + * @return optionnellement, le marqueur à placer dans la cellule de position + * p du labyrinthe laby. + */ + def marqueur(p: Position): Option[Image] = ??? // TODO - /** @param i un numéro de ligne du labyrinthe laby - * @return l'image de cette ligne - * - * @note une solution courte est de la forme - * (0 until laby.largeur).foldRight ... - * - * (0 until n) étant la liste des nombres de 0 à n-1. - */ - def ligneToImage(i: Int): Image = ??? // TODO + /** @param p une position dans le labyrinthe laby + * @return l'image de la cellule de laby à cette position + */ + def imageCellule(p: Position): Image = ??? // TODO + + /** @param i un numéro de ligne du labyrinthe laby + * @return l'image de cette ligne + * + * @note une solution courte est de la forme + * (0 until laby.largeur).foldRight ... + * + * (0 until n) étant la liste des nombres de 0 à n-1. + */ + def ligneToImage(i: Int): Image = ??? // TODO - /** image du labyrinthe sans les enceintes extérieures */ - val raw: Image = ??? // TODO + /** image du labyrinthe sans les enceintes extérieures */ + val raw: Image = ??? // TODO - /* Ajout des enceintes entourant le labyrinthe + /* Ajout des enceintes entourant le labyrinthe Vous n'avez rien à compléter ci-dessous. - */ - val enceinteH: Image = black( - Rectangle(laby.largeur * taille_cellule, epaisseur_mur) - ) - val enceinteV: Image = black( - Rectangle(epaisseur_mur, laby.hauteur * taille_cellule) - ) + */ + val enceinteH: Image = black( + Rectangle(laby.largeur * taille_cellule, epaisseur_mur) + ) + val enceinteV: Image = black( + Rectangle(epaisseur_mur, laby.hauteur * taille_cellule) + ) - Below( - Beside( - enceinteV, - onAlign(Right, enceinteV, onAlign(Top, enceinteH, raw)) - ), - Beside(jointure, enceinteH) - ) + Below( + Beside( + enceinteV, + onAlign(Right, enceinteV, onAlign(Top, enceinteH, raw)) + ), + Beside(jointure, enceinteH) + ) } From 8c250f4150dd87acc17c59ba1bc2b37a0ad4a889 Mon Sep 17 00:00:00 2001 From: Delfred353 <94049120+Delfred353@users.noreply.github.com> Date: Mon, 6 May 2024 13:43:24 +0200 Subject: [PATCH 09/17] Update Labyrinthe.scala --- src/main/scala/labyrinthe/Labyrinthe.scala | 86 ++++++++++++---------- 1 file changed, 48 insertions(+), 38 deletions(-) diff --git a/src/main/scala/labyrinthe/Labyrinthe.scala b/src/main/scala/labyrinthe/Labyrinthe.scala index 7c8c837..591c410 100755 --- a/src/main/scala/labyrinthe/Labyrinthe.scala +++ b/src/main/scala/labyrinthe/Labyrinthe.scala @@ -251,50 +251,60 @@ object Labyrinthe { ) case _ => celluleToImage(laby.f((x, y)), None, etat((x, y))) } - } - // TODO + // TODO - /** @param p une position dans le labyrinthe laby - * @return optionnellement, le marqueur à placer dans la cellule de position - * p du labyrinthe laby. - */ - def marqueur(p: Position): Option[Image] = ??? // TODO + /** @param p une position dans le labyrinthe laby + * @return optionnellement, le marqueur à placer dans la cellule de position + * p du labyrinthe laby. + */ + def marqueur(p: Position): Option[Image] = {} // TODO - /** @param p une position dans le labyrinthe laby - * @return l'image de la cellule de laby à cette position - */ - def imageCellule(p: Position): Image = ??? // TODO + /** @param p une position dans le labyrinthe laby + * @return l'image de la cellule de laby à cette position + */ + def imageCellule(p: Position): Image = p match { + case (0, 0) => + celluleToImage(laby.f((0, 0)), Some(marqueurSortie), etat((0, 0))) + case (laby.hauteur, 0) => + celluleToImage( + laby.f((laby.hauteur, 0)), + Some(marqueurEntree), + etat((laby.hauteur, 0)) + ) + case _ => + celluleToImage(laby.f(p), None, etat(p)) - /** @param i un numéro de ligne du labyrinthe laby - * @return l'image de cette ligne - * - * @note une solution courte est de la forme - * (0 until laby.largeur).foldRight ... - * - * (0 until n) étant la liste des nombres de 0 à n-1. - */ - def ligneToImage(i: Int): Image = ??? // TODO + /** @param i un numéro de ligne du labyrinthe laby + * @return l'image de cette ligne + * + * @note une solution courte est de la forme + * (0 until laby.largeur).foldRight ... + * + * (0 until n) étant la liste des nombres de 0 à n-1. + */ + def ligneToImage(i: Int): Image = ??? // TODO - /** image du labyrinthe sans les enceintes extérieures */ - val raw: Image = ??? // TODO + /** image du labyrinthe sans les enceintes extérieures */ + val raw: Image = ??? // TODO - /* Ajout des enceintes entourant le labyrinthe + /* Ajout des enceintes entourant le labyrinthe Vous n'avez rien à compléter ci-dessous. - */ - val enceinteH: Image = black( - Rectangle(laby.largeur * taille_cellule, epaisseur_mur) - ) - val enceinteV: Image = black( - Rectangle(epaisseur_mur, laby.hauteur * taille_cellule) - ) - - Below( - Beside( - enceinteV, - onAlign(Right, enceinteV, onAlign(Top, enceinteH, raw)) - ), - Beside(jointure, enceinteH) - ) + */ + val enceinteH: Image = black( + Rectangle(laby.largeur * taille_cellule, epaisseur_mur) + ) + val enceinteV: Image = black( + Rectangle(epaisseur_mur, laby.hauteur * taille_cellule) + ) + Below( + Beside( + enceinteV, + onAlign(Right, enceinteV, onAlign(Top, enceinteH, raw)) + ), + Beside(jointure, enceinteH) + ) + } + } } From 5cdcfb69b8b33150822c2f64aa3bca9d3f0f542f Mon Sep 17 00:00:00 2001 From: Delfred353 <94049120+Delfred353@users.noreply.github.com> Date: Mon, 6 May 2024 15:35:51 +0200 Subject: [PATCH 10/17] Update Labyrinthe.scala --- src/main/scala/labyrinthe/Labyrinthe.scala | 88 +++++++++------------- 1 file changed, 35 insertions(+), 53 deletions(-) diff --git a/src/main/scala/labyrinthe/Labyrinthe.scala b/src/main/scala/labyrinthe/Labyrinthe.scala index 591c410..247bd9b 100755 --- a/src/main/scala/labyrinthe/Labyrinthe.scala +++ b/src/main/scala/labyrinthe/Labyrinthe.scala @@ -237,20 +237,6 @@ object Labyrinthe { * décomposées en fonctions ou expressions auxiliaires courtes. */ def labToImage(laby: Labyrinthe, etat: EtatLabyrinthe): Image = { - val y = laby.hauteur - val x = laby.largeur - p: Tuple => - (x, y) match { - case (0, 0) => - celluleToImage(laby.f((0, 0)), Some(marqueurSortie), etat((0, 0))) - case (laby.hauteur, 0) => - celluleToImage( - laby.f((laby.hauteur, 0)), - Some(marqueurEntree), - etat((laby.hauteur, 0)) - ) - case _ => celluleToImage(laby.f((x, y)), None, etat((x, y))) - } // TODO @@ -258,53 +244,49 @@ object Labyrinthe { * @return optionnellement, le marqueur à placer dans la cellule de position * p du labyrinthe laby. */ - def marqueur(p: Position): Option[Image] = {} // TODO + def marqueur(p: Position): Option[Image] = { + p match { + case (0, 0) => Some(marqueurSortie) + case (laby.hauteur, 0) => Some(marqueurEntree) + case _ => None + } + } /** @param p une position dans le labyrinthe laby * @return l'image de la cellule de laby à cette position */ - def imageCellule(p: Position): Image = p match { - case (0, 0) => - celluleToImage(laby.f((0, 0)), Some(marqueurSortie), etat((0, 0))) - case (laby.hauteur, 0) => - celluleToImage( - laby.f((laby.hauteur, 0)), - Some(marqueurEntree), - etat((laby.hauteur, 0)) - ) - case _ => - celluleToImage(laby.f(p), None, etat(p)) + def imageCellule(p: Position): Image = + celluleToImage(laby.f(p), marqueur(p), etat(p)) - /** @param i un numéro de ligne du labyrinthe laby - * @return l'image de cette ligne - * - * @note une solution courte est de la forme - * (0 until laby.largeur).foldRight ... - * - * (0 until n) étant la liste des nombres de 0 à n-1. - */ - def ligneToImage(i: Int): Image = ??? // TODO + /** @param i un numéro de ligne du labyrinthe laby + * @return l'image de cette ligne + * + * @note une solution courte est de la forme + * (0 until laby.largeur).foldRight ... + * + * (0 until n) étant la liste des nombres de 0 à n-1. + */ + def ligneToImage(i: Int): Image = (0 until laby.largeur) // TODO - /** image du labyrinthe sans les enceintes extérieures */ - val raw: Image = ??? // TODO + /** image du labyrinthe sans les enceintes extérieures */ + val raw: Image = ??? // TODO - /* Ajout des enceintes entourant le labyrinthe + /* Ajout des enceintes entourant le labyrinthe Vous n'avez rien à compléter ci-dessous. - */ - val enceinteH: Image = black( - Rectangle(laby.largeur * taille_cellule, epaisseur_mur) - ) - val enceinteV: Image = black( - Rectangle(epaisseur_mur, laby.hauteur * taille_cellule) - ) + */ + val enceinteH: Image = black( + Rectangle(laby.largeur * taille_cellule, epaisseur_mur) + ) + val enceinteV: Image = black( + Rectangle(epaisseur_mur, laby.hauteur * taille_cellule) + ) - Below( - Beside( - enceinteV, - onAlign(Right, enceinteV, onAlign(Top, enceinteH, raw)) - ), - Beside(jointure, enceinteH) - ) - } + Below( + Beside( + enceinteV, + onAlign(Right, enceinteV, onAlign(Top, enceinteH, raw)) + ), + Beside(jointure, enceinteH) + ) } } From d65f31cec45d95f2f8a314c8f9fd53b1ea873db9 Mon Sep 17 00:00:00 2001 From: Delfred353 <94049120+Delfred353@users.noreply.github.com> Date: Mon, 6 May 2024 15:56:27 +0200 Subject: [PATCH 11/17] LABTOIMAGE DONE --- src/main/scala/labyrinthe/Labyrinthe.scala | 13 +++++++++---- src/main/scala/labyrinthe/Main.scala | 2 +- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/main/scala/labyrinthe/Labyrinthe.scala b/src/main/scala/labyrinthe/Labyrinthe.scala index 247bd9b..9ea5a61 100755 --- a/src/main/scala/labyrinthe/Labyrinthe.scala +++ b/src/main/scala/labyrinthe/Labyrinthe.scala @@ -238,8 +238,6 @@ object Labyrinthe { */ def labToImage(laby: Labyrinthe, etat: EtatLabyrinthe): Image = { - // TODO - /** @param p une position dans le labyrinthe laby * @return optionnellement, le marqueur à placer dans la cellule de position * p du labyrinthe laby. @@ -266,10 +264,17 @@ object Labyrinthe { * * (0 until n) étant la liste des nombres de 0 à n-1. */ - def ligneToImage(i: Int): Image = (0 until laby.largeur) // TODO + def ligneToImage(i: Int): Image = { + (0 until laby.largeur).foldRight(Empty)((y: Int, acc: Image) => + Beside(imageCellule((i, y)), acc) + ) + } /** image du labyrinthe sans les enceintes extérieures */ - val raw: Image = ??? // TODO + val raw: Image = + (0 until laby.hauteur).foldRight(Empty)((i: Int, acc: Image) => + Below(ligneToImage(i), acc) + ) /* Ajout des enceintes entourant le labyrinthe Vous n'avez rien à compléter ci-dessous. diff --git a/src/main/scala/labyrinthe/Main.scala b/src/main/scala/labyrinthe/Main.scala index a80e3f5..c73483f 100755 --- a/src/main/scala/labyrinthe/Main.scala +++ b/src/main/scala/labyrinthe/Main.scala @@ -15,7 +15,7 @@ object Main extends App { /* Décommentez la ligne suivante une fois que les fonctions labToImage et etatLabyrinthe sont définies : */ - // bigbang(new GameUniverse(laby)) + bigbang(new GameUniverse(laby)) /* Si vous lancez cette application avec `sbt run` depuis un terminal, décommentez la ligne ci-dessous qui attend que l'utilisateur appuie sur la From b2936664a64f33c7c8efdd562b975341a563f3be Mon Sep 17 00:00:00 2001 From: Delfred353 <94049120+Delfred353@users.noreply.github.com> Date: Mon, 6 May 2024 16:04:33 +0200 Subject: [PATCH 12/17] Update Jeu.scala --- src/main/scala/labyrinthe/Jeu.scala | 47 ++++++++++++++++------------- 1 file changed, 26 insertions(+), 21 deletions(-) diff --git a/src/main/scala/labyrinthe/Jeu.scala b/src/main/scala/labyrinthe/Jeu.scala index 0ff49d7..45fda85 100755 --- a/src/main/scala/labyrinthe/Jeu.scala +++ b/src/main/scala/labyrinthe/Jeu.scala @@ -27,31 +27,36 @@ object Jeu { /** @param chemin un chemin de labyrinthe * @return la position du joueur dans le labyrinthe selon le chemin donné */ - def positionCourante(chemin: Chemin): Position = ??? // TODO + def positionCourante(chemin: Chemin): Position = chemin match + case x :: _ => x /** @param p une position dans un labyrinthe * @param chemin un chemin d'un labyrinthe * @return true ssi la position p est la position courante du joueur selon le * chemin donné. */ - def estPositionCourante(p: Position, chemin: Chemin): Boolean = ??? // TODO + def estPositionCourante(p: Position, chemin: Chemin): Boolean = + p == positionCourante(chemin) /** @param laby un labyrinthe * @param chemin un chemin dans laby * @return vrai ssi le chemin mène à la sortie de laby. */ - def estResolu(laby: Labyrinthe, chemin: Chemin): Boolean = ??? // TODO + def estResolu(laby: Labyrinthe, chemin: Chemin): Boolean = chemin match + case x :: _ => x == sortieLabyrinthe(laby) /** @param laby un labyrinthe * @return le chemin initial, c'est-à-dire celui avec lequel on commence à jouer. */ - def cheminInitial(laby: Labyrinthe): Chemin = ??? // TODO + def cheminInitial(laby: Labyrinthe): Chemin = entreeLabyrinthe(laby) :: Nil /** @param chemin un chemin * @return le chemin correspondant à l'annulation du dernier déplacement dans chemin, * si des déplacements ont déjà été effectués. */ - def annulerBouger(chemin: Chemin): Chemin = ??? // TODO + def annulerBouger(chemin: Chemin): Chemin = chemin match + case x :: Nil => chemin + case x :: y => y /** Directions des déplacements dans un labyrinthe */ sealed trait Direction @@ -67,7 +72,7 @@ object Jeu { * @param d une direction * @return la position voisine de pos, suivant direction */ - def voisine(p: Position, d: Direction): Position = ??? // TODO + def voisine(p: Position, d: Direction): Position = ??? // TODO /** @param laby un labyrinthe * @param p une position @@ -88,7 +93,7 @@ object Jeu { laby: Labyrinthe, p: Position, d: Direction - ): Boolean = ??? // TODO + ): Boolean = ??? // TODO /** @param laby un labyrinthe * @param p une position dans laby @@ -96,7 +101,7 @@ object Jeu { * * @note utiliser directions, filter et map */ - def voisines(laby: Labyrinthe, p: Position): List[Position] = ??? // TODO + def voisines(laby: Labyrinthe, p: Position): List[Position] = ??? // TODO /** @param laby un labyrinthe * @param chemin un chemin dans le labyrinthe laby @@ -108,7 +113,7 @@ object Jeu { laby: Labyrinthe, chemin: Chemin, direction: Direction - ): Chemin = ??? // TODO + ): Chemin = ??? // TODO /** @param p0 une position dans un labyrinthe * @param p1 une position dans un labyrinthe @@ -116,7 +121,7 @@ object Jeu { * * @note indication de longueur : moins de 10 lignes */ - def directionDeplacement(p0: Position, p1: Position): Direction = ??? // TODO + def directionDeplacement(p0: Position, p1: Position): Direction = ??? // TODO /** @param chemin un chemin * @return la direction dans laquelle se déplace le joueur ayant suivi ce chemin, @@ -127,7 +132,7 @@ object Jeu { * @note indication de longueur : moins de 5 lignes * @note utiliser la fonction directionDeplacement */ - def sensDeplacement(chemin: Chemin): Direction = ??? // TODO + def sensDeplacement(chemin: Chemin): Direction = ??? // TODO /** @param laby un labyrinthe * @param chemin un chemin dans le labyrinthe laby @@ -156,7 +161,7 @@ object Jeu { def etatLabyrinthe( laby: Labyrinthe, chemin: Chemin - ): EtatLabyrinthe = ??? // TODO + ): EtatLabyrinthe = ??? // TODO /* ======================================*/ /* RÉSOLUTION : recherche d'une solution */ @@ -193,7 +198,7 @@ object Jeu { def bougeStrategieMainDroite( laby: Labyrinthe, chemin: Chemin - ): Chemin = ??? // TODO + ): Chemin = ??? // TODO /** @param laby un labyrinthe parfait * @param chemin un chemin dans le labyrinthe laby @@ -206,7 +211,7 @@ object Jeu { def resoudreParStrategieMainDroite( laby: Labyrinthe, chemin: Chemin - ): Chemin = ??? // TODO + ): Chemin = ??? // TODO /** @param chemin un chemin d'un labyrinthe * @return le chemin obetenu en enlevant les détours éventuels du chemin @@ -221,7 +226,7 @@ object Jeu { * @note Notre solution utilise la méthode span * Cf. https://www.scala-lang.org/api/2.13.3/scala/collection/immutable/List.html#span(p:A=%3EBoolean):(List[A],List[A]) */ - def simplifie(chemin: Chemin): Chemin = ??? // TODO + def simplifie(chemin: Chemin): Chemin = ??? // TODO /** @param laby un labyrinthe parfait * @param chemin un chemin dans le labyrinthe laby @@ -236,7 +241,7 @@ object Jeu { * * @note utiliser les fonctions simplifie et resoudreParStrategieMainDroite */ - def resoudre(laby: Labyrinthe, chemin: Chemin): Chemin = ??? // TODO + def resoudre(laby: Labyrinthe, chemin: Chemin): Chemin = ??? // TODO /** @param laby un labyrinthe parfait * @param chemin un chemin valide dans le labyrinthe laby @@ -249,7 +254,7 @@ object Jeu { * peut être utile. xs.takeRight(n) renvoie les n derniers * éléments de la liste xs. */ - def indice(laby: Labyrinthe, chemin: Chemin): Chemin = ??? // TODO + def indice(laby: Labyrinthe, chemin: Chemin): Chemin = ??? // TODO /* RÉSOLUTION PAR FORCE BRUTE (Très difficile) =========================================== @@ -285,7 +290,7 @@ object Jeu { def etendreCheminJusquaArrivee( laby: Labyrinthe, chemin: Chemin - ): Chemin = ??? // TODO + ): Chemin = ??? // TODO /** @param laby un labyrinthe parfait * @param chemin un chemin dans le labyrinthe laby @@ -303,7 +308,7 @@ object Jeu { def resoudreForceBrute( laby: Labyrinthe, chemin: Chemin - ): Chemin = ??? // TODO + ): Chemin = ??? // TODO /** @param laby un labyrinthe parfait * @param chemin un chemin valide dans le labyrinthe laby @@ -314,6 +319,6 @@ object Jeu { * * @note Utiliser la fonction resoudreForceBrute */ - def indiceForceBrute(laby: Labyrinthe, chemin: Chemin): Chemin = ??? // TODO + def indiceForceBrute(laby: Labyrinthe, chemin: Chemin): Chemin = ??? // TODO -} \ No newline at end of file +} From 471629e5ffb277e254d78f462d669066bc3f7706 Mon Sep 17 00:00:00 2001 From: Delfred353 <94049120+Delfred353@users.noreply.github.com> Date: Mon, 6 May 2024 16:12:19 +0200 Subject: [PATCH 13/17] Update Jeu.scala --- src/main/scala/labyrinthe/Jeu.scala | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/main/scala/labyrinthe/Jeu.scala b/src/main/scala/labyrinthe/Jeu.scala index 45fda85..f32b5a0 100755 --- a/src/main/scala/labyrinthe/Jeu.scala +++ b/src/main/scala/labyrinthe/Jeu.scala @@ -72,7 +72,11 @@ object Jeu { * @param d une direction * @return la position voisine de pos, suivant direction */ - def voisine(p: Position, d: Direction): Position = ??? // TODO + def voisine(p: Position, d: Direction): Position = (d, p) match + case (Nord, (x, y)) => (x - 1, y) + case (Sud, (x, y)) => (x + 1, y) + case (Est, (x, y)) => (x, y + 1) + case (Ouest, (x, y)) => (x, y - 1) /** @param laby un labyrinthe * @param p une position From 21a0bbe0496ef087d8227eec247e58940bd52d26 Mon Sep 17 00:00:00 2001 From: Delfred353 <94049120+Delfred353@users.noreply.github.com> Date: Tue, 7 May 2024 15:46:54 +0200 Subject: [PATCH 14/17] Update Jeu.scala --- src/main/scala/labyrinthe/Jeu.scala | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/main/scala/labyrinthe/Jeu.scala b/src/main/scala/labyrinthe/Jeu.scala index f32b5a0..6c0342f 100755 --- a/src/main/scala/labyrinthe/Jeu.scala +++ b/src/main/scala/labyrinthe/Jeu.scala @@ -97,7 +97,15 @@ object Jeu { laby: Labyrinthe, p: Position, d: Direction - ): Boolean = ??? // TODO + ): Boolean = { + d match + case Nord => laby.f(p) match { case Cellule(e, _) => e == Ouvert } + case Est => laby.f(p) match { case Cellule(_, e) => e == Ouvert } + case Sud => + laby.f(voisine(p, d)) match { case Cellule(e, _) => e == Ouvert } + case Ouest => + laby.f(voisine(p, d)) match { case Cellule(_, e) => e == Ouvert } + } /** @param laby un labyrinthe * @param p une position dans laby From b88c7dc03b4b9162e153411e5760301b951eb4cb Mon Sep 17 00:00:00 2001 From: Delfred353 <94049120+Delfred353@users.noreply.github.com> Date: Tue, 7 May 2024 15:55:44 +0200 Subject: [PATCH 15/17] Update Jeu.scala --- src/main/scala/labyrinthe/Jeu.scala | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/src/main/scala/labyrinthe/Jeu.scala b/src/main/scala/labyrinthe/Jeu.scala index 6c0342f..99ecf0f 100755 --- a/src/main/scala/labyrinthe/Jeu.scala +++ b/src/main/scala/labyrinthe/Jeu.scala @@ -27,8 +27,10 @@ object Jeu { /** @param chemin un chemin de labyrinthe * @return la position du joueur dans le labyrinthe selon le chemin donné */ - def positionCourante(chemin: Chemin): Position = chemin match - case x :: _ => x + def positionCourante(chemin: Chemin): Position = { + chemin match + case x :: _ => x + } /** @param p une position dans un labyrinthe * @param chemin un chemin d'un labyrinthe @@ -42,8 +44,10 @@ object Jeu { * @param chemin un chemin dans laby * @return vrai ssi le chemin mène à la sortie de laby. */ - def estResolu(laby: Labyrinthe, chemin: Chemin): Boolean = chemin match - case x :: _ => x == sortieLabyrinthe(laby) + def estResolu(laby: Labyrinthe, chemin: Chemin): Boolean = { + chemin match + case x :: _ => x == sortieLabyrinthe(laby) + } /** @param laby un labyrinthe * @return le chemin initial, c'est-à-dire celui avec lequel on commence à jouer. @@ -54,9 +58,11 @@ object Jeu { * @return le chemin correspondant à l'annulation du dernier déplacement dans chemin, * si des déplacements ont déjà été effectués. */ - def annulerBouger(chemin: Chemin): Chemin = chemin match - case x :: Nil => chemin - case x :: y => y + def annulerBouger(chemin: Chemin): Chemin = { + chemin match + case x :: Nil => chemin + case x :: y => y + } /** Directions des déplacements dans un labyrinthe */ sealed trait Direction @@ -98,13 +104,14 @@ object Jeu { p: Position, d: Direction ): Boolean = { - d match + d match { case Nord => laby.f(p) match { case Cellule(e, _) => e == Ouvert } case Est => laby.f(p) match { case Cellule(_, e) => e == Ouvert } case Sud => laby.f(voisine(p, d)) match { case Cellule(e, _) => e == Ouvert } case Ouest => laby.f(voisine(p, d)) match { case Cellule(_, e) => e == Ouvert } + } } /** @param laby un labyrinthe From 2a977ceee22304843425b8d6060d306031b06ce8 Mon Sep 17 00:00:00 2001 From: Delfred353 <94049120+Delfred353@users.noreply.github.com> Date: Wed, 8 May 2024 15:09:03 +0200 Subject: [PATCH 16/17] Presque fini --- src/main/scala/labyrinthe/Jeu.scala | 23 +++++++++++++++++----- src/main/scala/labyrinthe/Labyrinthe.scala | 14 ++++++++++--- 2 files changed, 29 insertions(+), 8 deletions(-) diff --git a/src/main/scala/labyrinthe/Jeu.scala b/src/main/scala/labyrinthe/Jeu.scala index 99ecf0f..cadc99c 100755 --- a/src/main/scala/labyrinthe/Jeu.scala +++ b/src/main/scala/labyrinthe/Jeu.scala @@ -120,7 +120,8 @@ object Jeu { * * @note utiliser directions, filter et map */ - def voisines(laby: Labyrinthe, p: Position): List[Position] = ??? // TODO + def voisines(laby: Labyrinthe, p: Position): List[Position] = + directions.filter(y => passageOuvert(laby, p, y)).map(y => voisine(p, y)) /** @param laby un labyrinthe * @param chemin un chemin dans le labyrinthe laby @@ -132,7 +133,9 @@ object Jeu { laby: Labyrinthe, chemin: Chemin, direction: Direction - ): Chemin = ??? // TODO + ): Chemin = if passageOuvert(laby, chemin.head, direction) + then (voisine(chemin.head, direction) :: chemin) + else (chemin) /** @param p0 une position dans un labyrinthe * @param p1 une position dans un labyrinthe @@ -140,7 +143,12 @@ object Jeu { * * @note indication de longueur : moins de 10 lignes */ - def directionDeplacement(p0: Position, p1: Position): Direction = ??? // TODO + def directionDeplacement(p0: Position, p1: Position): Direction = + (p0._1 - p1._1, p0._2 - p1._2) match + case (-1, 0) => Nord + case (1, 0) => Sud + case (0, -1) => Ouest + case (0, 1) => Est /** @param chemin un chemin * @return la direction dans laquelle se déplace le joueur ayant suivi ce chemin, @@ -151,7 +159,9 @@ object Jeu { * @note indication de longueur : moins de 5 lignes * @note utiliser la fonction directionDeplacement */ - def sensDeplacement(chemin: Chemin): Direction = ??? // TODO + def sensDeplacement(chemin: Chemin): Direction = chemin match + case x :: y :: _ => directionDeplacement(x, y) + case _ => Est /** @param laby un labyrinthe * @param chemin un chemin dans le labyrinthe laby @@ -180,7 +190,10 @@ object Jeu { def etatLabyrinthe( laby: Labyrinthe, chemin: Chemin - ): EtatLabyrinthe = ??? // TODO + ): EtatLabyrinthe = p => + if p == positionCourante(chemin) then Courante(Nil) + else if chemin.contains(p) then Visitee(Nil) + else NonVisitee /* ======================================*/ /* RÉSOLUTION : recherche d'une solution */ diff --git a/src/main/scala/labyrinthe/Labyrinthe.scala b/src/main/scala/labyrinthe/Labyrinthe.scala index 9ea5a61..63fb7c2 100755 --- a/src/main/scala/labyrinthe/Labyrinthe.scala +++ b/src/main/scala/labyrinthe/Labyrinthe.scala @@ -149,14 +149,19 @@ object Labyrinthe { * ┣━┻━┻━┻━┛ ┃ * ┗━━━━━━━━━┛ */ - def couloirSudEst(hauteur: Int, largeur: Int): Agencement = ??? // TODO + def couloirSudEst(hauteur: Int, largeur: Int): Agencement = (i, j) => + (i == hauteur - 1, j == largeur - 1) match + case (_, true) => Cellule(Ouvert, Ferme) + case (true, _) => Cellule(Ferme, Ouvert) + case _ => Cellule(Ferme, Ferme) /** @param nord un booléen * @param est un booléen * @return la cellule dont les passages Nord et Est sont spécifiés par les * booléens donnés (true indiquant un passage ouvert) */ - def booleansToCellule(nord: Boolean, est: Boolean): Cellule = ??? // TODO + def booleansToCellule(nord: Boolean, est: Boolean): Cellule = + ??? // TODO // Je n'ai pas compris /** @param hauteur nombre de lignes d'un labyrinthe * @param largeur nombre de colonnes d'un labyrinthe @@ -174,7 +179,10 @@ object Labyrinthe { * ┗━━━━━━━━━┛ ┣━━━━━━━╸ ┃ * ┗━━━━━━━━━┛ */ - def serpentinH(hauteur: Int, largeur: Int): Agencement = ??? // TODO + def serpentinH(hauteur: Int, largeur: Int): Agencement = (i, j) => + (i % 2, j == 0, j == largeur - 1) match + case (0, true, _) | (1, _, true) => Cellule(Ouvert, Ouvert) + case _ => Cellule(Ferme, Ouvert) /** @param hauteur nombre de lignes d'un labyrinthe * @param largeur nombre de colonnes d'un labyrinthe From cf9500208124c1b5717e5578997e73dd6e8cf6e3 Mon Sep 17 00:00:00 2001 From: Delfred353 <94049120+Delfred353@users.noreply.github.com> Date: Wed, 8 May 2024 18:55:33 +0200 Subject: [PATCH 17/17] Update Jeu.scala --- src/main/scala/labyrinthe/Jeu.scala | 80 +++++++++++++++++++++++++++-- 1 file changed, 75 insertions(+), 5 deletions(-) diff --git a/src/main/scala/labyrinthe/Jeu.scala b/src/main/scala/labyrinthe/Jeu.scala index cadc99c..c6526e6 100755 --- a/src/main/scala/labyrinthe/Jeu.scala +++ b/src/main/scala/labyrinthe/Jeu.scala @@ -230,7 +230,57 @@ object Jeu { def bougeStrategieMainDroite( laby: Labyrinthe, chemin: Chemin - ): Chemin = ??? // TODO + ): Chemin = { + sensDeplacement(chemin) match + case Est => + ( + passageOuvert(laby, chemin.head, Sud), + passageOuvert(laby, chemin.head, Est), + passageOuvert(laby, chemin.head, Nord), + passageOuvert(laby, chemin.head, Ouest) + ) match { + case (true, _, _, _) => bouge(laby, chemin, Sud) + case (_, true, _, _) => bouge(laby, chemin, Est) + case (_, _, true, _) => bouge(laby, chemin, Nord) + case _ => bouge(laby, chemin, Ouest) + } + case Nord => + ( + passageOuvert(laby, chemin.head, Est), + passageOuvert(laby, chemin.head, Nord), + passageOuvert(laby, chemin.head, Ouest), + passageOuvert(laby, chemin.head, Sud) + ) match { + case (true, _, _, _) => bouge(laby, chemin, Est) + case (_, true, _, _) => bouge(laby, chemin, Nord) + case (_, _, true, _) => bouge(laby, chemin, Ouest) + case _ => bouge(laby, chemin, Sud) + } + case Ouest => + ( + passageOuvert(laby, chemin.head, Nord), + passageOuvert(laby, chemin.head, Ouest), + passageOuvert(laby, chemin.head, Sud), + passageOuvert(laby, chemin.head, Est) + ) match { + case (true, _, _, _) => bouge(laby, chemin, Nord) + case (_, true, _, _) => bouge(laby, chemin, Ouest) + case (_, _, true, _) => bouge(laby, chemin, Sud) + case _ => bouge(laby, chemin, Est) + } + case Sud => + ( + passageOuvert(laby, chemin.head, Ouest), + passageOuvert(laby, chemin.head, Sud), + passageOuvert(laby, chemin.head, Est), + passageOuvert(laby, chemin.head, Nord) + ) match { + case (true, _, _, _) => bouge(laby, chemin, Ouest) + case (_, true, _, _) => bouge(laby, chemin, Sud) + case (_, _, true, _) => bouge(laby, chemin, Est) + case _ => bouge(laby, chemin, Nord) + } + } /** @param laby un labyrinthe parfait * @param chemin un chemin dans le labyrinthe laby @@ -243,7 +293,17 @@ object Jeu { def resoudreParStrategieMainDroite( laby: Labyrinthe, chemin: Chemin - ): Chemin = ??? // TODO + ): Chemin = { + chemin match + case x :: _ => + if (x == sortieLabyrinthe(laby)) then { chemin } + else { + resoudreParStrategieMainDroite( + laby, + bougeStrategieMainDroite(laby, chemin) + ) + } + } /** @param chemin un chemin d'un labyrinthe * @return le chemin obetenu en enlevant les détours éventuels du chemin @@ -258,7 +318,13 @@ object Jeu { * @note Notre solution utilise la méthode span * Cf. https://www.scala-lang.org/api/2.13.3/scala/collection/immutable/List.html#span(p:A=%3EBoolean):(List[A],List[A]) */ - def simplifie(chemin: Chemin): Chemin = ??? // TODO + def simplifie(chemin: Chemin): Chemin = chemin match + case x :: Nil => x :: Nil + case x1 :: x2 :: xs => + val (pVrai, pFaux) = xs.span(_ != x1) + if (pFaux.isEmpty) then x1 :: simplifie(x2 :: xs) + else simplifie(pFaux) + case Nil => Nil /** @param laby un labyrinthe parfait * @param chemin un chemin dans le labyrinthe laby @@ -273,7 +339,9 @@ object Jeu { * * @note utiliser les fonctions simplifie et resoudreParStrategieMainDroite */ - def resoudre(laby: Labyrinthe, chemin: Chemin): Chemin = ??? // TODO + def resoudre(laby: Labyrinthe, chemin: Chemin): Chemin = simplifie( + resoudreParStrategieMainDroite(laby, chemin) + ) ++ chemin /** @param laby un labyrinthe parfait * @param chemin un chemin valide dans le labyrinthe laby @@ -286,7 +354,9 @@ object Jeu { * peut être utile. xs.takeRight(n) renvoie les n derniers * éléments de la liste xs. */ - def indice(laby: Labyrinthe, chemin: Chemin): Chemin = ??? // TODO + def indice(laby: Labyrinthe, chemin: Chemin): Chemin = simplifie( + resoudre(laby, chemin).takeRight(chemin.length + 1) + ) /* RÉSOLUTION PAR FORCE BRUTE (Très difficile) ===========================================