From e746172535a09b2f9ae0392a9f1251d2dab9cfa4 Mon Sep 17 00:00:00 2001 From: Guillotin Damien Date: Sun, 16 Jan 2022 14:05:58 +0100 Subject: [PATCH] feat: exemple to tina fonctionne --- .../fr.n7.game2petrinet/Game2PetriNet.atl | 142 ++++++++++++++++-- .../fr.n7.petrinet.examples/src-gen/jeu.net | 6 +- .../xtext/tests/.GameParsingTest.xtendbin | Bin 3389 -> 3389 bytes .../xtext/generator/.GameGenerator.xtendbin | Bin 2284 -> 2284 bytes 4 files changed, 132 insertions(+), 16 deletions(-) diff --git a/runtime-workspace/fr.n7.game2petrinet/Game2PetriNet.atl b/runtime-workspace/fr.n7.game2petrinet/Game2PetriNet.atl index 1ad32a5..cf822e4 100755 --- a/runtime-workspace/fr.n7.game2petrinet/Game2PetriNet.atl +++ b/runtime-workspace/fr.n7.game2petrinet/Game2PetriNet.atl @@ -52,6 +52,13 @@ def: getJeu() : game!Jeu = ->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 @@ -68,12 +75,19 @@ helper def: getNetwork() : petrinet!Network = ->asSequence()->first(); -- Obtenir la taille de l'explorateur -helper context petrinet!Place +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 = @@ -114,6 +128,16 @@ def: getPlace(): petrinet!Place = ->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() @@ -131,16 +155,6 @@ def: getLieu(): game!Lieu = ->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() @@ -183,7 +197,7 @@ rule Objet2PetriNet { p_objneg: petrinet!Place( name <- 'objet_' + o.nom.nom + '_neg', - tokens <- p_objneg.getTailleExp() div o.taille - o.getNombreInit(), + tokens <- ''.getTailleExp() div o.taille - o.getNombreInit(), network <- o.getJeu()) } @@ -247,6 +261,19 @@ rule Chemin2PetriNet { 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); + } + } + } + } } } @@ -254,7 +281,7 @@ rule Interaction2PetriNet { from i: game!Interaction to t: petrinet!Transition( - name <- 'interaction_' + i.nom.nom, + name <- 'interaction_' + i.nom.nom + '_' + i.getPersonne().nom.nom, network <- i.getJeu()), arcOut: petrinet!Arc( @@ -278,6 +305,23 @@ rule Interaction2PetriNet { 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); + } + } + } + } } } @@ -333,6 +377,78 @@ rule consoObjet(t : game!Transition, s : String) { 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( diff --git a/runtime-workspace/fr.n7.petrinet.examples/src-gen/jeu.net b/runtime-workspace/fr.n7.petrinet.examples/src-gen/jeu.net index 5c0c63d..c4d42fe 100644 --- a/runtime-workspace/fr.n7.petrinet.examples/src-gen/jeu.net +++ b/runtime-workspace/fr.n7.petrinet.examples/src-gen/jeu.net @@ -8,8 +8,8 @@ pl personne_Sphinx (0) pl lieu_Enigme (1) pl lieu_Succes (0) pl lieu_Echec (0) -tr chemin_win lieu_Enigme*1 -> lieu_Succes*1 -tr chemin_loose lieu_Enigme*1 -> lieu_Echec*1 -tr interaction_Parler lieu_Enigme*1 -> personne_Sphinx*1 +tr chemin_win lieu_Enigme*1 connaissance_Reussite*1 -> lieu_Succes*1 connaissance_Reussite*1 +tr chemin_loose lieu_Enigme*1 objet_tentative*0 objet_tentative_neg*3 -> lieu_Echec*1 objet_tentative*0 objet_tentative_neg*3 +tr interaction_Parler_Sphinx lieu_Enigme*1 connaissance_Reussite_neg*1 objet_tentative*1 -> personne_Sphinx*1 connaissance_Reussite_neg*1 objet_tentative*1 tr action_Reponse_1 personne_Sphinx*1 connaissance_Reussite_neg*1 -> lieu_Enigme*1 connaissance_Reussite*1 tr action_Reponse_2 personne_Sphinx*1 objet_tentative*1 -> lieu_Enigme*1 objet_tentative_neg*1 taille*1 diff --git a/workspace/fr.n7.game.xtext.tests/xtend-gen/fr/n7/game/xtext/tests/.GameParsingTest.xtendbin b/workspace/fr.n7.game.xtext.tests/xtend-gen/fr/n7/game/xtext/tests/.GameParsingTest.xtendbin index 8f72e0894b67aa5105f0dbb3d892d82037a57837..01c3976d7c41f2ee30fa1060e344b03cf9cc3c8f 100644 GIT binary patch delta 69 zcmdlhwO5KSz?+#xgn@&DgP|$KAY>!oJ60ADV-uS%3z)GvkV}UN%$nTDV+LXD=COk? I{_;2g0DjgJ+yDRo delta 69 zcmdlhwO5KSz?+#xgn@&DgW+RMSMWx@cdRTR#wIpj7BFLTAeRmkm^HbP#|*;Q&0_~) I{N-@~037cb8~^|S diff --git a/workspace/fr.n7.game.xtext/xtend-gen/fr/n7/game/xtext/generator/.GameGenerator.xtendbin b/workspace/fr.n7.game.xtext/xtend-gen/fr/n7/game/xtext/generator/.GameGenerator.xtendbin index a238c0eac20804f8589730b01e7e1f97b6480765..d34ad7b93edd7d0c59588a4fdafb27ba7d97ac8d 100644 GIT binary patch delta 70 zcmaDO_(qT~z?+#xgn@&DgP}3SAY>!oE@l=GWAhp2IwlCqkL?~Km^Ime!wka6;;@4- I)^Iog0KWAUkN^Mx delta 70 zcmaDO_(qT~z?+#xgn@&DgW*F>SMWx@UCb;X#^y83bxaVJAKN`fFl({_hZ%&C#bF0w Itl@9~0A9`+&;S4c