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

274 lines
5.9 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();
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
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)
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();
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();
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',
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())
}
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-09 15:39:41 +00:00
}
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)
}