Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- %====INFORMATION====%
- % LFSAB1402 Projet 2016
- % Nomas : 07891500-38421500
- % Noms : (Tascon Gutierrez,Luis)-(Mawait,Maxime)
- %====MODULELINK====%
- declare
- [Projet]={Module.link ["Projet2016.ozf"]}
- %====CODE====%
- local
- MaxTime = 25 % nombre de frame a l'animation
- MyFunction % fonction principale
- Primitive
- FlattenList
- AppendList
- Value
- PokeSearch
- PokeBuild
- Translate
- PokeTranslate
- Scale
- Rotate
- Map % map principale
- Spawn
- CheckMap
- Extensions = opt(withExtendedFormula:true
- withIfThenElse:true
- withComparison:true
- withTimeWindow:true
- withCheckMapEasy:true
- withCheckMapComplete:true) %toutes les extensions sont implementees.
- Building = primitive(kind:building)
- B = scale(rx:10.0 ry:10.0 [Building])
- fun{A Acc Max}
- if Acc < Max then translate(dx:mult(sin(Acc) Acc) dy:mult(cos(Acc) Acc) [B])|{A Acc+1.0 Max}
- else nil
- end
- end
- Ru = [translate(dx:250.0 dy:250.0 {A 0.0 400.0})] %Monde reel
- Pu = [translate(dx: 250.0 dy: 250.0 1:[translate(dx:mult(sin(time) mult(5.0 time)) dy:mult(cos(time) mult(5.0 time)) [spawn(tmin:3 tmax:MaxTime [primitive(kind:pokemon)])])]) translate(dx: 300.0 dy: 100.0 [primitive(kind:pokestop)]) translate(dx:100.0 dy:300.0 1:[primitive(kind:arena)])] %Monde pokemon
- in
- Map = map(ru:Ru pu:Pu) %Map envoyee
- fun{MyFunction Map}
- %Fait plusieurs appels de fonctions imbriquees afin de retourner une liste de fonctions anonymes en fonction de Map recu.
- case Map of map(ru: Ru pu: Pu) then
- {AppendList {Build {Search {FlattenList Ru}}} {PokeBuild {PokeSearch {FlattenList Pu}}}}
- end
- end
- fun{Primitive K}
- %C'est la fonction qui recois une string en argument et qui retourne un realitem ou un pokeitem en fonction de K.
- case K of road then
- realitem(kind: road p1: pt(x: 0.0 y: 0.0) p2: pt(x: 1.0 y: 0.0))
- [] building then
- realitem(kind: building p1: pt(x: 0.0 y: 0.0) p2: pt(x: 0.0 y: 1.0) p3: pt(x: 1.0 y: 1.0) p4: pt(x: 1.0 y: 0.0))
- [] water then
- realitem(kind: water p1: pt(x: 0.0 y: 0.0) p2: pt(x: 0.0 y: 1.0) p3: pt(x: 1.0 y: 1.0) p4: pt(x: 1.0 y: 0.0))
- [] pokemon then
- pokeitem(kind: pokemon position: pt(x: 0.0 y: 0.0))
- [] pokestop then
- pokeitem(kind: pokestop position: pt(x: 0.0 y: 0.0))
- [] arena then
- pokeitem(kind: arena position: pt(x: 0.0 y: 0.0))
- end
- end
- fun{Translate D1 D2 L1}
- %Cette fonction applique une translation a un pokeitem ou un realitem de D1 dans l'axe des x et de D2 dans l'axe des y.
- %D'abord, on applique FlattenList sur L1 afin d'etre sur qu'on ai une liste simple et pas une liste de listes.
- %Ensuite, on regarde le premier element de L1 et on applique une recursion sur le reste de la liste.
- Dx = {Value D1}
- Dy = {Value D2}
- L = {FlattenList L1}
- in
- case L of nil then nil
- [] H|T then
- %Apres avoir fait le pattern matching, nous observons plusieurs cas:
- case H
- of primitive(kind:K) then %Si on a une primitive, on rappelle la fonction avec comme nouvel argument pour la liste l'item que va nous retourner {Primitive K}
- {Translate D1 D2 [{Primitive K}]}|{Translate D1 D2 T}
- [] realitem(kind:K p1: pt(x:X1 y:Y1) p2: pt(x:X2 y:Y2)) then %Si c'est un realitem a deux points (road) on applique la translation sur les 2points.
- realitem(kind:K p1: pt(x:X1+Dx y:Y1+Dy) p2: pt(x:X2+Dx y:Y2+Dy))|{Translate D1 D2 T}
- [] realitem(kind:K p1: pt(x:X1 y:Y1) p2: pt(x:X2 y:Y2) p3: pt(x:X3 y:Y3) p4: pt(x:X4 y:Y4)) then %Si c'est un realitem a 4 points (water & building), on applique la translation sur les 4 points.
- realitem(kind:K p1: pt(x:X1+Dx y:Y1+Dy) p2: pt(x:X2+Dx y:Y2+Dy) p3: pt(x:X3+Dx y:Y3+Dy) p4: pt(x:X4+Dx y:Y4+Dy))|{Translate D1 D2 T}
- [] translate(dx:A dy:B 1:Ru) then %Si on a deux translates imbriques, on appelle {Translate} dans {Translate} car on ne peut pas appliquer une translation sur un autre tuple que realitem.
- {Translate D1 D2 {Translate A B Ru}}|{Translate D1 D2 T}
- [] scale(rx:A ry:B 1:Ru) then %Si on a scale, on appelle {Scale} dans le {Translate}.
- {Translate D1 D2 {Scale A B Ru}}|{Translate D1 D2 T}
- [] rotate(angle:A 1:Ru) then %Si on a rotate, on appelle {Rotate} dans le {Translate}.
- {Translate D1 D2 {Rotate A Ru}}|{Translate D1 D2 T}
- end
- end
- end
- fun{Scale R1 R2 L1}
- %Cette fonction applique un redimensionnement a un pokeitem ou un realitem de R1 dans l'axe des x et de R2 dans l'axe des y.
- %D'abord, on applique FlattenList sur L1 afin d'etre sur qu'on ai une liste simple et pas une liste de listes.
- %Ensuite, on regarde le premier element de L1 et on applique une recursion sur le reste de la liste.
- Rx = {Value R1}
- Ry = {Value R2}
- L = {FlattenList L1}
- in
- case L of nil then nil
- [] H|T then
- case H of primitive(kind:K) then %Si on a une primitive, on appelle la fonction {Primitive} en recursion avec Scale afin de recevoir un realitem.
- {Scale Rx Ry [{Primitive K}]}|{Scale R1 R2 T}
- [] realitem(kind:K p1: pt(x:X1 y:Y1) p2: pt(x:X2 y:Y2)) then %Si on a un realitem a 2 points (road), on applique le dimensionnement aux 2 points.
- realitem(kind:K p1: pt(x:X1*Rx y:Y1*Ry) p2: pt(x:X2*Rx y:Y2*Ry))|{Scale R1 R2 T}
- [] realitem(kind:K p1: pt(x:X1 y:Y1) p2: pt(x:X2 y:Y2) p3: pt(x:X3 y:Y3) p4: pt(x:X4 y:Y4)) then %Si on a un realitem a 4 points (water & building), on applique le dimensionnement aux 4 points.
- realitem(kind:K p1: pt(x:X1*Rx y:Y1*Ry) p2: pt(x:X2*Rx y:Y2*Ry) p3: pt(x:X3*Rx y:Y3*Ry) p4: pt(x:X4*Rx y:Y4*Ry))|{Scale R1 R2 T}
- [] translate(dx: A dy: B 1:Ru) then %Si on a translate, on appelle {Transtlate} dans le {Scale}.
- {Scale R1 R2 {Translate A B Ru}}|{Scale R1 R2 T}
- [] scale(rx: A ry: B 1: Ru) then %Si on a deux scales imbriques, on appelle {Scale} dans {Scale} car on ne peut pas appliquer un dimensionnement sur un autre tuple que realitem.
- {Scale R1 R2 {Scale A B Ru}}|{Scale R1 R2 T}
- [] rotate(angle: A 1:Ru) then %Si on a rotate, on appelle {Rotate} dans le {Scale}.
- {Scale R1 R2 {Rotate A Ru}}|{Scale R1 R2 T}
- end
- end
- end
- fun{Rotate A1 Ru1}
- %Cette fonction applique une rotation a un pokeitem ou un realitem d'un angle qui vaut A1 en radian autour de (0;0).
- %D'abord, on applique FlattenList sur L1 afin d'etre sur qu'on ai une liste simple et pas une liste de listes.
- %Ensuite, on regarde le premier element de L1 et on applique une recursion sur le reste de la liste.
- A = {Value A1}
- Ru = {FlattenList Ru1}
- in
- case Ru of nil then nil
- [] H|T then
- case H of primitive(kind:K) then %Si on a une primitive, on appelle la fonction {Primitive} en recursion avec Rotate afin de recevoir un realitem.
- {Rotate A [{Primitive K}]}|{Rotate A T}
- [] translate(dx: Dx dy: Dy 1: L) then %Si on a translate, on appelle {Translate} dans le {Rotate}.
- {Rotate A {Translate Dx Dy L}}|{Rotate A T}
- [] rotate(angle: A2 1: L) then %Si on a deux rotates imbriques, on appelle {Rotate} dans {Rotate} car on ne peut pas appliquer un dimensionnement sur un autre tuple que realitem.
- {Rotate A {Rotate A2 L}}|{Rotate A T}
- [] scale(rx: Rx ry: Ry 1: L) then %Si on a Scale, on appelle {Scale} dans le {Rotate}.
- {Rotate A {Scale Rx Ry L}}|{Rotate A T}
- [] realitem(kind:K p1: pt(x:X1 y:Y1) p2: pt(x:X2 y:Y2)) then %Si on a un realitem a 2 points (road), on applique la rotation aux 2 points.
- realitem(kind:K p1: pt(x: {Value plus(mult(X1 cos(A)) mult(Y1 sin(A)))} y: {Value plus(mult(neg(X1) sin(A)) mult(Y1 cos(A)))}) p2: pt(x: {Value plus(mult(X2 cos(A)) mult(Y2 sin(A)))} y: {Value plus(mult(neg(X2) sin(A)) mult(Y2 cos(A)))}))|{Rotate A T}
- [] realitem(kind:K p1: pt(x:X1 y:Y1) p2: pt(x:X2 y:Y2) p3: pt(x:X3 y:Y3) p4: pt(x:X4 y:Y4)) then %Si on a un realitem a 4 points (water & building), on applique la rotation aux 4 points.
- realitem(kind:K p1: pt(x: {Value plus(mult(X1 cos(A)) mult(Y1 sin(A)))} y: {Value plus(mult(neg(X1) sin(A)) mult(Y1 cos(A)))}) p2: pt(x: {Value plus(mult(X2 cos(A)) mult(Y2 sin(A)))} y: {Value plus(mult(neg(X2) sin(A)) mult(Y2 cos(A)))}) p3: pt(x: {Value plus(mult(X3 cos(A)) mult(Y3 sin(A)))} y: {Value plus(mult(neg(X3) sin(A)) mult(Y3 cos(A)))}) p4: pt(x: {Value plus(mult(X4 cos(A)) mult(Y4 sin(A)))} y: {Value plus(mult(neg(X4) sin(A)) mult(Y4 cos(A)))}))|{Rotate A T}
- end
- end
- end
- fun{PokeTranslate Dx Dy L1}
- %Cette fonction a le meme principe que Translate a l'exception de la transformation appliquee au point.
- %Pour faire des transformations, a la place de faire directement les plus, on cree des tuples du type plus(A B).
- %Ce tuple va rester la jusqu'a ce qu'on emballe l'item dans une fonction anonyme, a ce moment la, on va evaluer le tuple avec {Formula A Time}.
- L = {FlattenList L1}
- in
- case L of nil then nil
- [] H|T then
- case H of primitive(kind: K) then%Si on a une primitive, on appelle la fonction {Primitive} en recursion avec PokeTranslate afin de recevoir un realitem.
- {PokeTranslate Dx Dy [{Primitive K}]}|{PokeTranslate Dx Dy T}
- [] pokeitem(kind: K position: pt(x: X y: Y)) then %Si on a un pokeitem, on met un tuple plus dans chacune des coordonnees du point indiquant le pokeitem.
- pokeitem(kind: K position: pt(x: plus(X Dx) y: plus(Y Dy)))|{PokeTranslate Dx Dy T}
- [] translate(dx: D1 dy: D2 1:Pu) then %Si on a translate, on appelle {PokeTranslate} en recursion avec {PokeTranslate}.
- {PokeTranslate Dx Dy {PokeTranslate D1 D2 Pu}}|{PokeTranslate Dx Dy T}
- [] spawn(tmin:Tmin tmax:Tmax Pu) then %Si on a Spawn, on appelle {PokeTranslate} dans le {Spawn}.
- {Spawn Tmin Tmax {PokeTranslate Dx Dy Pu}}|{PokeTranslate Dx Dy T}
- end
- end
- end
- fun{Spawn Tmin Tmax L1}
- %Cette fonction renvoie une liste de tuple spawn.
- %Le tuple spawn
- L = {FlattenList L1}
- in
- case L
- of H|T then
- case H
- of primitive(kind: K) then
- {Spawn Tmin Tmax [{Primitive K}]}|{Spawn Tmin Tmax T}
- [] pokeitem(kind: K position: pt(x: X y: Y)) then
- spawn(tmin:Tmin tmax:Tmax 1:[pokeitem(kind: K position: pt(x:X y:Y))])|{Spawn Tmin Tmax T}
- [] translate(dx: D1 dy: D2 1:Pu) then
- spawn(tmin:Tmin tmax:Tmax 1:{PokeTranslate D1 D2 Pu})|{Spawn Tmin Tmax T}
- [] spawn(tmin:A tmax:B 1:Pu) then
- spawn(tmin:Tmin tmax:Tmax 1:{Spawn A B Pu})|{Spawn Tmin Tmax T}
- end
- [] nil then nil
- end
- end
- fun{PokeSearch Pu}
- case Pu of nil then nil
- [] H|T then
- case H of primitive(kind: K) then {Primitive K}|{PokeSearch T}
- [] translate(dx: Dx dy: Dy 1: Pu2) then
- {FlattenList {PokeTranslate Dx Dy Pu2}|{PokeSearch T}}
- [] spawn(tmin:Tmin tmax:Tmax 1:Pu2) then
- {FlattenList {Spawn Tmin Tmax Pu2}|{PokeSearch T}}
- end
- end
- end
- fun{PokeBuild Pu1}
- Pu = {FlattenList Pu1}
- in
- case Pu of nil then nil
- [] H|T then
- case H of pokeitem(kind: K position: pt(x:X y:Y)) then
- fun{$ Time}pokeitem(kind: K position: pt(x:{Formula X Time} y:{Formula Y Time}))end|{PokeBuild T}
- [] spawn(tmin:Tmin tmax:Tmax 1:B) then
- local X = {PokeBuild B} in
- fun{$ Time}if({Float.toInt Time} >= Tmin andthen {Float.toInt Time} < Tmax)then {X.1 Time} else empty end end|{PokeBuild T}
- end
- [] nil then nil
- end
- end
- end
- fun{Search Ru}
- case Ru of nil then nil
- [] H|T then
- case H
- of primitive(kind:K) then {Primitive K}|{Search T}
- [] translate(dx:Dx dy:Dy 1:Ru2) then
- {Translate Dx Dy Ru2}|{Search T}
- [] rotate(angle:Angle 1:Ru2) then
- {Rotate Angle Ru2}|{Search T}
- [] scale(rx: Rx ry: Ry 1:Ru2) then
- {Scale Rx Ry Ru2}|{Search T}
- end
- end
- end
- fun{Build L1}
- L = {FlattenList L1}
- in
- case L of H|T then
- fun{$ Time} H end|{Build T}
- else nil
- end
- end
- fun{Value V}
- % decrit les valeurs possibles de l'univers reel
- if {Float.is V} then V
- else case V
- of plus(1:A 2:B) then {Value A} + {Value B}
- [] minus(1:A 2:B) then {Value A} - {Value B}
- [] mult(1:A 2:B) then {Value A} * {Value B}
- [] 'div'(1:A 2:B) then {Value A} / {Value B}
- [] cos(1:A) then {Float.cos {Value A}}
- [] sin(1:A) then {Float.sin {Value A}}
- [] tan(1:A) then {Float.tan {Value A}}
- [] exp(1:A) then {Float.exp {Value A}}
- [] log(1:A) then {Float.log {Value A}}
- [] neg(1:A) then ~{Value A}
- end
- end
- end
- fun{Formula F Time}
- % donne les 'formules' du monde pokemon
- if {Float.is F} then F
- else
- case F
- of time then Time
- [] plus(1:A 2:B) then {Formula A Time} + {Formula B Time}
- [] minus(1:A 2:B) then {Formula A Time} - {Formula B Time}
- [] mult(1:A 2:B) then {Formula A Time} * {Formula B Time}
- [] 'div'(1:A 2:B) then {Formula A Time} / {Formula B Time}
- [] cos(1:A) then {Float.cos {Formula A Time}}
- [] sin(1:A) then {Float.sin {Formula A Time}}
- [] tan(1:A) then {Float.tan {Formula A Time}}
- [] exp(1:A) then {Float.exp {Formula A Time}}
- [] log(1:A) then {Float.log {Formula A Time}}
- [] neg(1:A) then ~{Formula A Time}
- [] ite(1:A 2:B 3:C) then if {Formula A Time} == 0.0 then {Formula C Time} else {Formula B Time} end
- [] eq(1:A 2:B) then if {Formula A Time} == {Formula B Time} then 1.0 else 0.0 end
- [] ne(1:A 2:B) then if {Formula A Time} \= {Formula B Time} then 1.0 else 0.0 end
- [] lt(1:A 2:B) then if {Formula A Time} < {Formula B Time} then 1.0 else 0.0 end
- [] le(1:A 2:B) then if {Formula A Time} =< {Formula B Time} then 1.0 else 0.0 end
- [] gt(1:A 2:B) then if {Formula A Time} > {Formula B Time} then 1.0 else 0.0 end
- [] ge(1:A 2:B) then if {Formula A Time} >= {Formula B Time} then 1.0 else 0.0 end
- end
- end
- end
- fun{AppendList X Y}
- case X of nil then Y
- [] H|T then H|{AppendList T Y}
- end
- end
- fun{FlattenList X}
- fun{IsList L}
- case L of nil then true
- [] H|T then true
- else false
- end
- end
- in
- case X of nil then nil
- [] H|T then
- if {IsList H} then {AppendList {FlattenList H}{FlattenList T}}
- else H|{FlattenList T}
- end
- end
- end
- fun{CheckMap Map}
- fun{CheckVal Val}
- if {Float.is Val} then true
- else
- case Val
- of plus(A B) then ({CheckVal A} andthen {CheckVal B})
- [] minus(A B) then ({CheckVal A} andthen {CheckVal B})
- [] mult(A B) then ({CheckVal A} andthen {CheckVal B})
- [] 'div'(A B) then ({CheckVal A} andthen {CheckVal B})
- [] cos(A) then {CheckVal A}
- [] sin(A) then {CheckVal A}
- [] tan(A) then {CheckVal A}
- [] exp(A) then {CheckVal A}
- [] log(A) then {CheckVal A}
- [] neg(A) then {CheckVal A}
- else false
- end
- end
- end
- fun{CheckForm Form}
- if {Float.is Form} then true
- else
- case Form
- of plus(A B) then ({CheckForm A} andthen {CheckForm B})
- [] time then true
- [] minus(A B) then ({CheckForm A} andthen {CheckForm B})
- [] mult(A B) then ({CheckForm A} andthen {CheckForm B})
- [] 'div'(A B) then ({CheckForm A} andthen {CheckForm B})
- [] cos(A) then {CheckForm A}
- [] sin(A) then {CheckForm A}
- [] tan(A) then {CheckForm A}
- [] exp(A) then {CheckForm A}
- [] log(A) then {CheckForm A}
- [] neg(A) then {CheckForm A}
- [] ite(A B C) then ({CheckForm A} andthen {CheckForm B} andthen {CheckForm C})
- [] eq(A B) then ({CheckForm A} andthen {CheckForm B})
- [] ne(A B) then ({CheckForm A} andthen {CheckForm B})
- [] lt(A B) then ({CheckForm A} andthen {CheckForm B})
- [] le(A B) then ({CheckForm A} andthen {CheckForm B})
- [] gt(A B) then ({CheckForm A} andthen {CheckForm B})
- [] ge(A B) then ({CheckForm A} andthen {CheckForm B})
- else false
- end
- end
- end
- fun{CheckPrim Prim}
- case Prim
- of road then true
- [] building then true
- [] water then true
- else false
- end
- end
- fun{CheckPrimPok Prim}
- case Prim
- of pokemon then true
- [] arena then true
- [] pokestop then true
- else false
- end
- end
- fun{CheckTrans Dx Dy Ru}
- ({CheckVal Dx} andthen {CheckVal Dy} andthen {CheckR Ru})
- end
- fun{CheckTransPok Dx Dy Pu}
- ({CheckForm Dx} andthen {CheckForm Dy} andthen {CheckP Pu})
- end
- fun{CheckRot Angle Ru}
- ({CheckVal Angle} andthen {CheckR Ru})
- end
- fun{CheckScale Rx Ry Ru}
- ({CheckVal Rx} andthen {CheckVal Ry} andthen {CheckR Ru})
- end
- fun{CheckSpa Tmin Tmax Pu}
- ({Int.is Tmin} andthen {Int.is Tmax} andthen {CheckP Pu})
- end
- fun{CheckR Ru}
- case Ru
- of H|T then
- case H
- of primitive(kind:A) then ({CheckPrim A} andthen {CheckR T})
- [] translate(dx:Dx dy:Dy 1:Ru1) then ({CheckTrans Dx Dy Ru1} andthen {CheckR T})
- [] rotate(angle:Angle 1:Ru1) then ({CheckRot Angle Ru1} andthen {CheckR T})
- [] scale(rx:Rx ry:Ry 1:Ru1) then ({CheckScale Rx Ry Ru1} andthen {CheckR T})
- else false
- end
- [] nil then true
- else false
- end
- end
- fun{CheckP Pu}
- case Pu
- of H|T then
- case H
- of primitive(kind:A) then ({CheckPrimPok A} andthen {CheckP T})
- [] translate(dx:Dx dy:Dy 1:Pu1) then ({CheckTransPok Dx Dy Pu1} andthen {CheckP T})
- [] spawn(tmin:Tmin tmax:Tmax 1:Pu1) then ({CheckSpa Tmin Tmax Pu1} andthen {CheckP T})
- else false
- end
- [] nil then true
- else false
- end
- end
- in
- case Map
- of map(ru:Ru pu:Pu) then
- ({CheckR Ru} andthen {CheckP Pu})
- else false
- end
- end
- {Projet.run MyFunction Map MaxTime Extensions CheckMap}
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement