projet-genie-logiciel-systeme/runtime-workspace/fr.n7.game2petrinet/Game2PetriNet.atl

486 lines
11 KiB
Plaintext
Raw Normal View History

2021-12-04 08:47:10 +00:00
module Game2PetriNet;
create OUT: petrinet from IN: game;
2021-12-09 15:39:41 +00:00
helper context game!Explorateur
def: getJeu() : game!Jeu =
game!Jeu.allInstances()
->asSequence()
->first();
helper context game!Objet
def: getJeu() : game!Jeu =
game!Jeu.allInstances()
->asSequence()
->first();
helper context game!Connaissance
def: getJeu() : game!Jeu =
game!Jeu.allInstances()
->asSequence()
->first();
helper context game!Action
def: getJeu() : game!Jeu =
game!Jeu.allInstances()
->asSequence()
->first();
helper context game!Personne
def: getJeu() : game!Jeu =
game!Jeu.allInstances()
->asSequence()
->first();
helper context game!Chemin
def: getJeu() : game!Jeu =
game!Jeu.allInstances()
->asSequence()
->first();
helper context game!Lieu
def: getJeu() : game!Jeu =
game!Jeu.allInstances()
->asSequence()
->first();
helper context game!Interaction
def: getJeu() : game!Jeu =
game!Jeu.allInstances()
->asSequence()
->first();
2022-01-16 13:05:58 +00:00
helper context String
def: getTaille() : Integer =
game!Objet.allInstances()
->asSequence()
->select(o | o.nom.nom = self)
->first().taille;
2021-12-09 15:39:41 +00:00
helper context game!Lieu
def : estDepart() : Integer =
self.depart.condition
->select(ce | ce.conditionTest
->select(ct | ct.oclIsTypeOf(game!ConditionBoolean))
->select(ct | ct.valeur = 'true')
->size() > 0)
->size();
-- Obtenir le network
2021-12-04 11:27:00 +00:00
helper def: getNetwork() : petrinet!Network =
2021-12-04 08:47:10 +00:00
petrinet!Network.allInstances()
->select(n | n.name = 'jeu')
->asSequence()->first();
2021-12-09 15:39:41 +00:00
-- Obtenir la taille de l'explorateur
2022-01-16 13:05:58 +00:00
helper context String
2021-12-09 15:39:41 +00:00
def: getTailleExp() : Integer =
game!Explorateur.allInstances()
->asSequence()
->first().tailleInventaire;
2022-01-16 13:05:58 +00:00
helper context String
def: getTransition() : petrinet!Transition =
petrinet!Transition.allInstances()
->asSequence()
->select(t | t.name = self)
->first();
2021-12-09 15:39:41 +00:00
-- Nombre d'objets initiaux de l'explo
helper context game!Objet
def : getNombreInit() : Integer =
game!Explorateur.allInstances()
->asSequence()
->first().objets
->select(o | o.nom = self.nom.nom)
->size();
-- Nombre de connaissances initiaux de l'explo
helper context game!Connaissance
def : getNombreInit() : Integer =
game!Explorateur.allInstances()
->asSequence()
->first().connaissances
->select(c | c.nom = self.nom.nom)
->size();
-- Nombre de place libre itiale de l'explo
helper context game!Explorateur
def : getNombreInit() : Integer =
game!Objet.allInstances()
->asSequence()
->iterate(o; res : Integer = self.tailleInventaire | res - o.getNombreInit() * o.taille);
-- Obtenir la place d'un chemin (in / out)
2021-12-04 08:47:10 +00:00
helper context game!Chemin
def: getPlaceOf(s : String): petrinet!Place =
petrinet!Place.allInstances()
->select(p | p.name = s)
2021-12-09 15:39:41 +00:00
->asSequence()
->first();
helper context game!Lieu
def: getPlace(): petrinet!Place =
petrinet!Place.allInstances()
->select(p | p.name = 'lieu_' + self.nom.nom)
->asSequence()
->first();
2022-01-16 13:05:58 +00:00
helper context game!Interaction
def: getPersonne(): game!Personne =
game!Personne.allInstances()
->select(p | (p.interactions
->select(i | i = self)
->size()
) > 0)
->asSequence()
->first();
2021-12-10 16:58:42 +00:00
helper context String
def : getObjet() : game!Objet =
game!Objet.allInstances()
->select(o | o.nom.nom = self)
->asSequence()
->first();
2021-12-09 15:39:41 +00:00
helper context game!Personne
def: getLieu(): game!Lieu =
game!Lieu.allInstances()
->select(l | l.personnes
->select(p | p.nom = self.nom.nom)
->asSequence()
->size() > 0)
->asSequence()
->first();
helper context game!Action
def : getInteraction() : game!Interaction =
game!Interaction.allInstances()
->select(i | i.actions
->select(a | a.nom.nom = self.nom.nom)
->asSequence()
->size() > 0)
->asSequence()
->first();
2021-12-10 14:31:43 +00:00
helper context petrinet!Transition
def : getPlace(s : String) : petrinet!Place =
petrinet!Place.allInstances()
->select(p | p.name = s)
->asSequence()
->first();
2021-12-09 15:39:41 +00:00
2021-12-04 08:47:10 +00:00
rule Game2PetriNet {
from p: game!Jeu
to pn: petrinet!Network (name <- 'jeu')
}
2021-12-09 15:39:41 +00:00
rule Explorateur2Petrinet {
from e: game!Explorateur
to
p: petrinet!Place(
name <- 'taille',
tokens <- e.getNombreInit(),
network <- e.getJeu())
}
rule Objet2PetriNet {
from o: game!Objet
to
p_obj: petrinet!Place(
name <- 'objet_' + o.nom.nom,
tokens <- o.getNombreInit(),
network <- o.getJeu()),
p_objneg: petrinet!Place(
name <- 'objet_' + o.nom.nom + '_neg',
2022-01-16 13:05:58 +00:00
tokens <- ''.getTailleExp() div o.taille - o.getNombreInit(),
2021-12-09 15:39:41 +00:00
network <- o.getJeu())
}
rule Connaissance2PetriNet {
from c: game!Connaissance
to
p_con: petrinet!Place(
name <- 'connaissance_' + c.nom.nom,
tokens <- c.getNombreInit(),
network <- c.getJeu()),
p_conneg: petrinet!Place(
name <- 'connaissance_' + c.nom.nom + '_neg',
tokens <- 1 - c.getNombreInit(),
network <- c.getJeu())
}
rule Personne2PetriNet {
from p: game!Personne
to
pers: petrinet!Place(
name <- 'personne_' + p.nom.nom,
tokens <- 0,
network <- p.getJeu())
}
2021-12-04 08:47:10 +00:00
rule Lieu2PetriNet {
from l: game!Lieu
to
p: petrinet!Place(
2021-12-04 11:34:01 +00:00
name <- 'lieu_' + l.nom.nom,
2021-12-09 15:39:41 +00:00
tokens <- l.estDepart(),
network <- l.getJeu())
2021-12-04 08:47:10 +00:00
}
rule Chemin2PetriNet {
from c: game!Chemin
to
t: petrinet!Transition(
2021-12-09 15:39:41 +00:00
name <- 'chemin_' + c.nom.nom,
network <- c.getJeu()),
2021-12-04 08:47:10 +00:00
arcIn: petrinet!Arc(
2021-12-09 15:39:41 +00:00
place <- c.getPlaceOf('lieu_' + c.lieuIn.nom),
2021-12-04 08:47:10 +00:00
transition <- t,
outgoing <- false,
weight <- 1),
2021-12-09 15:39:41 +00:00
2021-12-04 08:47:10 +00:00
arcOut: petrinet!Arc(
2021-12-09 15:39:41 +00:00
place <- c.getPlaceOf('lieu_' + c.lieuOut.nom),
2021-12-04 08:47:10 +00:00
transition <- t,
outgoing <- true,
weight <- 1)
2021-12-10 16:58:42 +00:00
do {
for (o in c.objetsConso) {
thisModule.consoObjet(t, o.nom);
}
for (o in c.objetsRecus) {
thisModule.recuObjet(t, o.nom);
}
for (con in c.connaissances) {
thisModule.recuConn(t, con.nom);
}
2022-01-16 13:05:58 +00:00
for (cond in c.visible.condition) {
for (cond2 in cond.conditionTest) {
if (cond2.oclIsKindOf(game!ConditionObjet)) {
thisModule.readObjetEga(t, cond2.objet, cond2.nombre);
} else {
if (cond2.negation = '!') {
thisModule.readConnNeg(t, cond2.connaissance);
} else {
thisModule.readConn(t, cond2.connaissance);
}
}
}
}
2021-12-10 16:58:42 +00:00
}
2021-12-09 15:39:41 +00:00
}
rule Interaction2PetriNet {
from i: game!Interaction
to
t: petrinet!Transition(
2022-01-16 13:05:58 +00:00
name <- 'interaction_' + i.nom.nom + '_' + i.getPersonne().nom.nom,
2021-12-09 15:39:41 +00:00
network <- i.getJeu()),
arcOut: petrinet!Arc(
place <- i.getPersonne(),
transition <- t,
outgoing <- true,
weight <- 1),
arcIn: petrinet!Arc(
place <- i.getPersonne().getLieu().getPlace(),
transition <- t,
outgoing <- false,
weight <- 1)
2021-12-10 16:58:42 +00:00
do {
for (o in i.objetsConso) {
thisModule.consoObjet(t, o.nom);
}
for (o in i.objetsRecus) {
thisModule.recuObjet(t, o.nom);
}
for (c in i.connaissances) {
thisModule.recuConn(t, c.nom);
}
2022-01-16 13:05:58 +00:00
for (cond in i.getPersonne().visible.condition) {
for (cond2 in cond.conditionTest) {
if (cond2.oclIsKindOf(game!ConditionObjet)) {
if (cond2.comparateur = '==') {
thisModule.readObjetEga(('interaction_' + i.nom.nom + '_' + i.getPersonne().nom.nom).getTransition(), cond2.objet, cond2.nombre);
} else if (cond2.comparateur = '>') {
thisModule.readObjetSup(('interaction_' + i.nom.nom + '_' + i.getPersonne().nom.nom).getTransition(), cond2.objet, cond2.nombre);
}
} else {
if (cond2.negation = '!') {
thisModule.readConnNeg(('interaction_' + i.nom.nom + '_' + i.getPersonne().nom.nom).getTransition(), cond2.connaissance);
} else {
thisModule.readConn(('interaction_' + i.nom.nom + '_' + i.getPersonne().nom.nom).getTransition(), cond2.connaissance);
}
}
}
}
2021-12-10 16:58:42 +00:00
}
2021-12-09 15:39:41 +00:00
}
rule Action2PetriNet {
from a: game!Action
to
t: petrinet!Transition(
name <- 'action_' + a.nom.nom,
network <- a.getJeu()),
arcIn: petrinet!Arc(
place <- a.getInteraction().getPersonne(),
transition <- t,
outgoing <- false,
weight <- 1),
arcOut: petrinet!Arc(
place <- a.getInteraction().getPersonne().getLieu().getPlace(),
transition <- t,
outgoing <- true,
weight <- 1)
2021-12-10 16:58:42 +00:00
do {
for (o in a.objetsConso) {
thisModule.consoObjet(t, o.nom);
}
for (o in a.objetsRecus) {
thisModule.recuObjet(t, o.nom);
}
for (c in a.connaissances) {
thisModule.recuConn(t, c.nom);
}
}
}
rule consoObjet(t : game!Transition, s : String) {
to
arc : petrinet!Arc(
place <- t.getPlace('objet_' + s),
transition <- t,
outgoing <- false,
weight <- 1),
arcNeg : petrinet!Arc(
place <- t.getPlace('objet_' + s + '_neg'),
transition <- t,
outgoing <- true,
weight <- 1),
arcTaille : petrinet!Arc(
place <- t.getPlace('taille'),
transition <- t,
outgoing <- true,
weight <- s.getObjet().taille)
2021-12-09 15:39:41 +00:00
}
2021-12-10 16:58:42 +00:00
2022-01-16 13:05:58 +00:00
rule readObjetEga(t : game!Transition, s : String, n : Integer) {
to
arc : petrinet!Arc(
place <- t.getPlace('objet_' + s),
transition <- t,
outgoing <- false,
weight <- n),
arc2 : petrinet!Arc(
place <- t.getPlace('objet_' + s),
transition <- t,
outgoing <- true,
weight <- n),
arc_neg : petrinet!Arc(
place <- t.getPlace('objet_' + s + '_neg'),
transition <- t,
outgoing <- false,
weight <- (s.getTailleExp() div s.getTaille()) - n),
arc2_neg : petrinet!Arc(
place <- t.getPlace('objet_' + s + '_neg'),
transition <- t,
outgoing <- true,
weight <- (s.getTailleExp() div s.getTaille()) - n)
}
rule readObjetSup(t : game!Transition, s : String, n : Integer) {
to
arc : petrinet!Arc(
place <- t.getPlace('objet_' + s),
transition <- t,
outgoing <- false,
weight <- n + 1),
arc2 : petrinet!Arc(
place <- t.getPlace('objet_' + s),
transition <- t,
outgoing <- true,
weight <- n + 1)
}
rule readConn(t : game!Transition, s : String) {
to
arc : petrinet!Arc(
place <- t.getPlace('connaissance_' + s),
transition <- t,
outgoing <- false,
weight <- 1),
arc2 : petrinet!Arc(
place <- t.getPlace('connaissance_' + s),
transition <- t,
outgoing <- true,
weight <- 1)
}
rule readConnNeg(t : game!Transition, s : String) {
to
arc : petrinet!Arc(
place <- t.getPlace('connaissance_' + s + '_neg'),
transition <- t,
outgoing <- false,
weight <- 1),
arc2 : petrinet!Arc(
place <- t.getPlace('connaissance_' + s + '_neg'),
transition <- t,
outgoing <- true,
weight <- 1)
}
2021-12-10 16:58:42 +00:00
rule recuObjet(t : game!Transition, s : String) {
to
arc : petrinet!Arc(
place <- t.getPlace('objet_' + s),
transition <- t,
outgoing <- true,
weight <- 1),
arcNeg : petrinet!Arc(
place <- t.getPlace('objet_' + s + '_neg'),
transition <- t,
outgoing <- false,
weight <- 1),
arcTaille : petrinet!Arc(
place <- t.getPlace('taille'),
transition <- t,
outgoing <- false,
weight <- s.getObjet().taille)
}
rule recuConn(t : game!Transition, s : String) {
to
arc : petrinet!Arc(
place <- t.getPlace('connaissance_' + s),
transition <- t,
outgoing <- true,
weight <- 1),
arcNeg : petrinet!Arc(
place <- t.getPlace('connaissance_' + s + '_neg'),
transition <- t,
outgoing <- false,
weight <- 1)
}