projet-genie-logiciel-systeme/runtime-workspace/fr.n7.game2petrinet/Game2PetriNet.atl
2021-12-10 15:31:43 +01:00

274 lines
5.9 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 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 petrinet!Place
def: getTailleExp() : Integer =
game!Explorateur.allInstances()
->asSequence()
->first().tailleInventaire;
-- 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!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!Interaction
def : getPersonne() : game!Personne =
game!Personne.allInstances()
->select(p | p.interactions
->select(i | i.nom.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 <- p_objneg.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)
}
rule Interaction2PetriNet {
from i: game!Interaction
to
t: petrinet!Transition(
name <- 'interaction_' + i.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)
}
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)
}