From 064e0aba80982876472e367ccf8dbfae464e4dcf Mon Sep 17 00:00:00 2001 From: Lukian Date: Sat, 18 Jan 2025 15:31:50 +0100 Subject: [PATCH] added constraints and comments --- projet.use | 81 +++-- projet_default.clt | 736 ++++++++++++++++++++++++++------------------- 2 files changed, 483 insertions(+), 334 deletions(-) diff --git a/projet.use b/projet.use index b2292dd..35c1cfc 100644 --- a/projet.use +++ b/projet.use @@ -29,11 +29,52 @@ class Jeu operations init(nom1: String,nom2: String) debut() +constraints + -- Contraintes qui vérifient qu'il y a bien un bateau à un endroit coulé + inv coule1: joueur1.plateau.cases.forAll( + c1: Case | + c1.type = TypeCase::Touche + implies joueur2.plateau.cases->select( + c2: Case | + c2.x = c1.x and c2.y = c1.y)->forAll( + c3: Case | c3.type = TypeCase::Bateau + ) + ) + inv coule2: joueur2.plateau.cases.forAll( + c1: Case | + c1.type = TypeCase::Touche + implies joueur1.plateau.cases->select( + c2: Case | + c2.x = c1.x and c2.y = c1.y)->forAll( + c3: Case | c3.type = TypeCase::Bateau + ) + ) + -- Contraintes qui vérifient qu'il n'y a pas de bateau à un endroit raté + inv rate1: joueur1.plateau.cases.forAll( + c1: Case | + c1.type = TypeCase::Rate + implies joueur2.plateau.cases->select( + c2: Case | + c2.x = c1.x and c2.y = c1.y)->forAll( + c3: Case | c3.type = TypeCase::Vide + ) + ) + inv rate2: joueur2.plateau.cases.forAll( + c1: Case | + c1.type = TypeCase::Rate + implies joueur1.plateau.cases->select( + c2: Case | + c2.x = c1.x and c2.y = c1.y)->forAll( + c3: Case | c3.type = TypeCase::Vide + ) + ) + -- Contrainte qui vérifie que les joueurs ont des noms différents + inv noms: not(joueur1.nom = joueur2.nom) end class Joueur attributes - Nom: String + nom: String operations tirer(case: String): TypeCoup tirerRobot(): TypeCoup @@ -43,10 +84,11 @@ class Flotte operations ajouterBateau(bateau: Bateau) constraints - inv: bateaux->select(b: Bateau | b.type = TypeBateau::Torpilleur)->size() = 1 - inv: bateaux->select(b: Bateau | b.type = TypeBateau::Contre_Torpilleur)->size() = 2 - inv: bateaux->select(b: Bateau | b.type = TypeBateau::Croiseur)->size() = 1 - inv: bateaux->select(b: Bateau | b.type = TypeBateau::Porte_Avions)->size() = 1 + -- Contraintes qui vérifient que les bateaux sont de la bonne taille + inv torpilleur: bateaux->select(b: Bateau | b.type = TypeBateau::Torpilleur)->size() = 1 + inv contre_torpilleur: bateaux->select(b: Bateau | b.type = TypeBateau::Contre_Torpilleur)->size() = 2 + inv croiseur: bateaux->select(b: Bateau | b.type = TypeBateau::Croiseur)->size() = 1 + inv porte_avions: bateaux->select(b: Bateau | b.type = TypeBateau::Porte_Avions)->size() = 1 end class Coup @@ -68,20 +110,25 @@ operations changerEtat(nouveauEtat: TypeCase) getEtat(): TypeCase constraints - inv: plateau.cases->select(c: Case | c.x = x and c.y = y)->size() = 1 - inv: x <= 10 and x > 0 and y > 0 and y <= 10 + -- Contrainte qui vérifie qu'il n'y a pas deux cases au même endroit + inv unicite: plateau.cases->select(c: Case | c.x = x and c.y = y)->size() = 1 + -- Contrainte qui vérifie que le plateau est de bonne dimensions + inv dimensions: x <= 10 and x > 0 and y > 0 and y <= 10 end class Bateau attributes type: TypeBateau longueur: Integer - Etat: EtatBateau + etat: EtatBateau constraints - inv: type = TypeBateau::Torpilleur implies longueur = 2 - inv: type = TypeBateau::Contre_Torpilleur implies longueur = 3 - inv: type = TypeBateau::Croiseur implies longueur = 4 - inv: type = TypeBateau::Porte_Avions implies longueur = 5 + -- Contraintes qui vérifient que les bateaux sont de la bonne taille + inv torpilleur: type = TypeBateau::Torpilleur implies longueur = 2 + inv contre_torpilleur: type = TypeBateau::Contre_Torpilleur implies longueur = 3 + inv croiseur: type = TypeBateau::Croiseur implies longueur = 4 + inv porte_avions: type = TypeBateau::Porte_Avions implies longueur = 5 + -- Contrainte qui dit que si toutes les cases d'un bateau sont touchées alors le bateau est coulé + inv coule: cases->forAll(c: Case | c.type = TypeCase::Touche) implies etat = EtatBateau::Coule end association Utilise between @@ -91,12 +138,12 @@ end composition Joue1 between Joueur[1] role joueur1 -Jeu[1] role jeu2 +Jeu[1] role jeu1 end composition Joue2 between Joueur[1] role joueur2 -Jeu[1] role jeu1 +Jeu[1] role jeu2 end association Tire between @@ -111,7 +158,7 @@ end composition Appartient2 between Flotte[1] role flotte -Bateau[*] role bateaux +Bateau[5] role bateaux end composition Compose between @@ -125,7 +172,7 @@ Coup[1] role coup end association Repartit between -Case[0..1] role cases -Bateau[2..5] role bateau +Case[2..5] role cases +Bateau[0..1] role bateau end diff --git a/projet_default.clt b/projet_default.clt index 6065b11..d4b9b25 100644 --- a/projet_default.clt +++ b/projet_default.clt @@ -1,10 +1,11 @@ - + + false false false true - false + true false true false @@ -12,8 +13,8 @@ Plateau - 300.0 - 285.0 + 303.0 + 283.0 false @@ -28,8 +29,8 @@ Coup - 211.0 - 48.0 + 234.0 + 72.0 false @@ -102,7 +103,36 @@ Bateau Repartit - + + bateau + + -4.0 + -6.0 + Repartit::WayPoint::1 + 8 + 8 + TOP + + false + + + 0..1 + + 48.0 + 5.0 + Repartit::WayPoint::1 + 8 + 8 + BOTTOM + + false + + Repartit 0.0 @@ -116,35 +146,13 @@ false - - bateau - - 0.0 - 0.0 - Repartit::WayPoint::1 - 8 - 8 - TOP - - false - - + 2..5 - 0.0 - 0.0 - Repartit::WayPoint::1 - 8 - 8 - BOTTOM - - false - - - 0..1 - - 0.0 - 0.0 + 43.0 + 15.0 Repartit::WayPoint::0 8 8 @@ -152,11 +160,12 @@ false - + cases - 0.0 - 0.0 + 8.0 + 6.0 Repartit::WayPoint::0 8 8 @@ -166,7 +175,9 @@ - + 0 0.0 @@ -176,7 +187,9 @@ 1 false - + 1 0.0 @@ -194,7 +207,36 @@ Plateau Compose - + + plateau + + -17.0 + -5.0 + Compose::WayPoint::1 + 8 + 8 + TOP + + false + + + 1 + + 0.0 + 0.0 + Compose::WayPoint::1 + 8 + 8 + BOTTOM + + false + + Compose 0.0 @@ -208,35 +250,12 @@ false - - plateau - - 0.0 - 0.0 - Compose::WayPoint::1 - 8 - 8 - TOP - - false - - - 1 - - 0.0 - 0.0 - Compose::WayPoint::1 - 8 - 8 - BOTTOM - - false - - + cases - 0.0 - 0.0 + -6.0 + -17.0 Compose::WayPoint::0 8 8 @@ -244,11 +263,13 @@ false - + 100 - 0.0 - 0.0 + 2.0 + 27.0 Compose::WayPoint::0 8 8 @@ -258,7 +279,9 @@ - + 0 0.0 @@ -268,7 +291,9 @@ 1 false - + 1 0.0 @@ -286,7 +311,36 @@ Coup Etat - + + coup + + 46.0 + -14.0 + Etat::WayPoint::1 + 8 + 8 + TOP + + false + + + 1 + + 0.0 + 0.0 + Etat::WayPoint::1 + 8 + 8 + BOTTOM + + false + + Etat 0.0 @@ -300,57 +354,37 @@ false - - 1 - - 0.0 - 0.0 - Etat::WayPoint::1 - 8 - 8 - BOTTOM - - false - - - coup - - 0.0 - 0.0 - Etat::WayPoint::1 - 8 - 8 - TOP - - false - - - 1 - - 0.0 - 0.0 - Etat::WayPoint::0 - 8 - 8 - BOTTOM - - false - - + case + + 20.0 + -26.0 + Etat::WayPoint::0 + 8 + 8 + TOP + + false + + + 1 0.0 0.0 Etat::WayPoint::0 8 8 - TOP + BOTTOM false - + 0 0.0 @@ -360,7 +394,8 @@ 1 false - + 1 0.0 @@ -378,7 +413,36 @@ Flotte Appartient - + + flotte + + -3.0 + 15.0 + Appartient::WayPoint::1 + 8 + 8 + TOP + + false + + + 1 + + 30.0 + -6.0 + Appartient::WayPoint::1 + 8 + 8 + BOTTOM + + false + + Appartient 0.0 @@ -392,35 +456,13 @@ false - + 1 - 0.0 - 0.0 - Appartient::WayPoint::1 - 8 - 8 - BOTTOM - - false - - - flotte - - 0.0 - 0.0 - Appartient::WayPoint::1 - 8 - 8 - TOP - - false - - - 1 - - 0.0 - 0.0 + 23.0 + 4.0 Appartient::WayPoint::0 8 8 @@ -428,11 +470,12 @@ false - + joueur - 0.0 - 0.0 + 8.0 + 7.0 Appartient::WayPoint::0 8 8 @@ -442,7 +485,9 @@ - + 0 0.0 @@ -452,7 +497,9 @@ 1 false - + 1 0.0 @@ -470,7 +517,37 @@ Plateau Utilise - + + 1 + + 0.0 + 0.0 + Utilise::WayPoint::1 + 8 + 8 + BOTTOM + + false + + + plateau + + 0.0 + 0.0 + Utilise::WayPoint::1 + 8 + 8 + TOP + + false + + Utilise 0.0 @@ -484,35 +561,12 @@ false - - plateau - - 0.0 - 0.0 - Utilise::WayPoint::1 - 8 - 8 - TOP - - false - - - 1 - - 0.0 - 0.0 - Utilise::WayPoint::1 - 8 - 8 - BOTTOM - - false - - + joueur - 0.0 - 0.0 + -1.0 + 7.0 Utilise::WayPoint::0 8 8 @@ -520,11 +574,13 @@ false - + 1 - 0.0 - 0.0 + 14.0 + -16.0 Utilise::WayPoint::0 8 8 @@ -534,7 +590,9 @@ - + 0 0.0 @@ -544,7 +602,9 @@ 1 false - + 1 0.0 @@ -562,7 +622,36 @@ Jeu Joue2 - + + jeu2 + + -10.0 + 7.0 + Joue2::WayPoint::1 + 8 + 8 + TOP + + false + + + 1 + + 0.0 + 0.0 + Joue2::WayPoint::1 + 8 + 8 + BOTTOM + + false + + Joue2 0.0 @@ -576,35 +665,26 @@ false - - jeu1 - - 0.0 - 0.0 - Joue2::WayPoint::1 - 8 - 8 - TOP - - false - - + 1 - 0.0 - 0.0 - Joue2::WayPoint::1 + -7.0 + 4.0 + Joue2::WayPoint::0 8 8 BOTTOM false - + joueur2 - 0.0 - 0.0 + -16.0 + 34.0 Joue2::WayPoint::0 8 8 @@ -612,21 +692,10 @@ false - - 1 - - 0.0 - 0.0 - Joue2::WayPoint::0 - 8 - 8 - BOTTOM - - false - - + 0 0.0 @@ -636,7 +705,8 @@ 1 false - + 1 0.0 @@ -654,7 +724,36 @@ Bateau Appartient2 - + + 5 + + -7.0 + -17.0 + Appartient2::WayPoint::1 + 8 + 8 + BOTTOM + + false + + + bateaux + + 1.0 + 22.0 + Appartient2::WayPoint::1 + 8 + 8 + TOP + + false + + Appartient2 0.0 @@ -668,43 +767,9 @@ false - - bateaux - - 0.0 - 0.0 - Appartient2::WayPoint::1 - 8 - 8 - TOP - - false - - - * - - 0.0 - 0.0 - Appartient2::WayPoint::1 - 8 - 8 - BOTTOM - - false - - - flotte - - 0.0 - 0.0 - Appartient2::WayPoint::0 - 8 - 8 - TOP - - false - - + 1 0.0 @@ -716,9 +781,24 @@ false + + flotte + + 9.0 + 30.0 + Appartient2::WayPoint::0 + 8 + 8 + TOP + + false + - + 0 0.0 @@ -728,7 +808,9 @@ 1 false - + 1 0.0 @@ -746,7 +828,36 @@ Jeu Joue1 - + + jeu1 + + 35.0 + -17.0 + Joue1::WayPoint::1 + 8 + 8 + TOP + + false + + + 1 + + 20.0 + -35.0 + Joue1::WayPoint::1 + 8 + 8 + BOTTOM + + false + + Joue1 0.0 @@ -760,35 +871,12 @@ false - - 1 - - 0.0 - 0.0 - Joue1::WayPoint::1 - 8 - 8 - BOTTOM - - false - - - jeu2 - - 0.0 - 0.0 - Joue1::WayPoint::1 - 8 - 8 - TOP - - false - - + joueur1 - 0.0 - 0.0 + 62.0 + -25.0 Joue1::WayPoint::0 8 8 @@ -796,11 +884,13 @@ false - + 1 - 0.0 - 0.0 + 14.0 + -20.0 Joue1::WayPoint::0 8 8 @@ -810,7 +900,8 @@ - + 0 0.0 @@ -820,7 +911,8 @@ 1 false - + 1 0.0 @@ -838,7 +930,36 @@ Coup Tire - + + coups + + -19.0 + -6.0 + Tire::WayPoint::1 + 8 + 8 + TOP + + false + + + 1 + + 0.0 + 0.0 + Tire::WayPoint::1 + 8 + 8 + BOTTOM + + false + + Tire 0.0 @@ -852,35 +973,12 @@ false - - 1 - - 0.0 - 0.0 - Tire::WayPoint::1 - 8 - 8 - BOTTOM - - false - - - coups - - 0.0 - 0.0 - Tire::WayPoint::1 - 8 - 8 - TOP - - false - - + joueur - 0.0 - 0.0 + 47.0 + 9.0 Tire::WayPoint::0 8 8 @@ -888,7 +986,9 @@ false - + * 0.0 @@ -902,7 +1002,8 @@ - + 0 0.0 @@ -912,7 +1013,8 @@ 1 false - + 1 0.0