projet-genie-logiciel-systeme/runtime-workspace/fr.n7.game2petrinet/Game2PetriNet.atl
2022-01-16 14:05:58 +01:00

486 lines
11 KiB
Plaintext
Executable file

module Game2PetriNet;
create OUT: petrinet from IN: game;
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();
helper context String
def: getTaille() : Integer =
game!Objet.allInstances()
->asSequence()
->select(o | o.nom.nom = self)
->first().taille;
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
helper def: getNetwork() : petrinet!Network =
petrinet!Network.allInstances()
->select(n | n.name = 'jeu')
->asSequence()->first();
-- Obtenir la taille de l'explorateur
helper context String
def: getTailleExp() : Integer =
game!Explorateur.allInstances()
->asSequence()
->first().tailleInventaire;
helper context String
def: getTransition() : petrinet!Transition =
petrinet!Transition.allInstances()
->asSequence()
->select(t | t.name = self)
->first();
-- 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)
helper context game!Chemin
def: getPlaceOf(s : String): petrinet!Place =
petrinet!Place.allInstances()
->select(p | p.name = s)
->asSequence()
->first();
helper context game!Lieu
def: getPlace(): petrinet!Place =
petrinet!Place.allInstances()
->select(p | p.name = 'lieu_' + self.nom.nom)
->asSequence()
->first();
helper context game!Interaction
def: getPersonne(): game!Personne =
game!Personne.allInstances()
->select(p | (p.interactions
->select(i | i = self)
->size()
) > 0)
->asSequence()
->first();
helper context String
def : getObjet() : game!Objet =
game!Objet.allInstances()
->select(o | o.nom.nom = self)
->asSequence()
->first();
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();
helper context petrinet!Transition
def : getPlace(s : String) : petrinet!Place =
petrinet!Place.allInstances()
->select(p | p.name = s)
->asSequence()
->first();
rule Game2PetriNet {
from p: game!Jeu
to pn: petrinet!Network (name <- 'jeu')
}
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',
tokens <- ''.getTailleExp() div o.taille - o.getNombreInit(),
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())
}
rule Lieu2PetriNet {
from l: game!Lieu
to
p: petrinet!Place(
name <- 'lieu_' + l.nom.nom,
tokens <- l.estDepart(),
network <- l.getJeu())
}
rule Chemin2PetriNet {
from c: game!Chemin
to
t: petrinet!Transition(
name <- 'chemin_' + c.nom.nom,
network <- c.getJeu()),
arcIn: petrinet!Arc(
place <- c.getPlaceOf('lieu_' + c.lieuIn.nom),
transition <- t,
outgoing <- false,
weight <- 1),
arcOut: petrinet!Arc(
place <- c.getPlaceOf('lieu_' + c.lieuOut.nom),
transition <- t,
outgoing <- true,
weight <- 1)
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);
}
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);
}
}
}
}
}
}
rule Interaction2PetriNet {
from i: game!Interaction
to
t: petrinet!Transition(
name <- 'interaction_' + i.nom.nom + '_' + i.getPersonne().nom.nom,
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)
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);
}
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);
}
}
}
}
}
}
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)
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)
}
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)
}
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)
}