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 à l'animation
- MyFunction
- Primitive
- FlattenList
- AppendList
- Value
- PokeSearch
- PokeBuild
- Translate
- PokeTranslate
- Scale
- Spawn
- Rotate
- Map
- CheckMap
- Extensions = opt(withExtendedFormula:true
- withIfThenElse:true
- withComparison:true
- withTimeWindow:false
- withCheckMapEasy:true
- withCheckMapComplete:true)
- 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})]
- in
- Map = map(ru:Ru 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)) [primitive(kind:pokemon)])]) translate(dx: 300.0 dy: 100.0 [primitive(kind:pokestop)]) translate(dx:100.0 dy:300.0 1:[primitive(kind:arena)]) spawn(tmin:0 tmax:3 1:[primitive(kind:pokemon)])]) %% TODO change the map here
- fun{MyFunction Map}
- case Map of map(ru: Ru pu: Pu) then
- {AppendList {Build {Search {FlattenList Ru}}} {PokeBuild fun{$ Time} {PokeSearch {FlattenList Pu} Time} end}}
- end
- end
- fun{Primitive 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}
- Dx = {Value D1}
- Dy = {Value D2}
- L = {FlattenList L1}
- in
- case L of nil then nil
- [] H|T then
- case H of primitive(kind:K) then
- {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
- 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
- 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
- {Translate D1 D2 {Translate A B Ru}}|{Translate D1 D2 T}
- [] scale(rx:A ry:B 1:Ru) then
- {Translate D1 D2 {Scale A B Ru}}|{Translate D1 D2 T}
- [] rotate(angle:A 1:Ru) then
- {Translate D1 D2 {Rotate A Ru}}|{Translate D1 D2 T}
- end
- end
- end
- fun{Scale R1 R2 L1}
- 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
- {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
- 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
- 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
- {Scale R1 R2 {Translate A B Ru}}|{Scale R1 R2 T}
- [] scale(rx: A ry: B 1: Ru) then
- {Scale R1 R2 {Scale A B Ru}}|{Scale R1 R2 T}
- [] rotate(angle: A 1:Ru) then
- {Scale R1 R2 {Rotate A Ru}}|{Scale R1 R2 T}
- end
- end
- end
- fun{Rotate A1 Ru1}
- A = {Value A1}
- Ru = {FlattenList Ru1}
- in
- case Ru of nil then nil
- [] H|T then
- case H of primitive(kind:K) then
- {Rotate A [{Primitive K}]}|{Rotate A T}
- [] translate(dx: Dx dy: Dy 1: L) then
- {Rotate A {Translate Dx Dy L}}|{Rotate A T}
- [] rotate(angle: A2 1: L) then
- {Rotate A {Rotate A2 L}}|{Rotate A T}
- [] scale(rx: Rx ry: Ry 1: L) then
- {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
- 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
- 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 Time}
- L = {FlattenList L1}
- in
- case L of nil then nil
- [] H|T then
- case H of primitive(kind: K) then
- {PokeTranslate Dx Dy [{Primitive K}] Time}|{PokeTranslate Dx Dy T Time}
- [] pokeitem(kind: K position: pt(x: X y: Y)) then
- pokeitem(kind: K position: pt(x: plus(X Dx) y: plus(Y Dy)))|{PokeTranslate Dx Dy T Time}
- [] translate(dx: D1 dy: D2 1:Pu) then
- {PokeTranslate Dx Dy {PokeTranslate D1 D2 Pu Time}Time}|{PokeTranslate Dx Dy T Time}
- [] spawn(tmin:Tmin tmax:Tmax Pu) then
- {PokeTranslate Dx Dy {Spawn Tmin Tmax Pu Time} Time}|{PokeTranslate Dx Dy T Time}
- [] empty then
- empty|{PokeTranslate Dx Dy T Time}
- end
- end
- end
- fun{Spawn Tmin1 Tmax1 L1 Time}
- Tmin = {Int.toFloat Tmin1}
- Tmax = {Int.toFloat Tmax1}
- in
- if Time >= Tmin then
- if Time < Tmax then
- L = {FlattenList L1}
- in
- L
- else [empty]
- end
- else [empty]
- end
- end
- fun{PokeSearch Pu Time}
- case Pu of nil then nil
- [] H|T then
- case H of primitive(kind: K) then {Primitive K}|{PokeSearch T Time}
- [] translate(dx: Dx dy: Dy 1: Pu2) then
- {FlattenList {PokeTranslate Dx Dy Pu2 Time}}|{PokeSearch T Time}
- [] spawn(tmin:Tmin tmax:Tmax 1:Pu2) then
- {PokeSearch {Spawn Tmin Tmax Pu2 Time} Time}|{PokeSearch T Time}
- [] empty then
- empty|{PokeSearch T Time}
- 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}
- [] nil then nil
- [] empty then
- fun{$ Time} empty end|{PokeBuild T}
- 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
- {FlattenList {Translate Dx Dy Ru2}}|{Search T}
- [] rotate(angle:Angle 1:Ru2) then
- {FlattenList {Rotate Angle Ru2}}|{Search T}
- [] scale(rx: Rx ry: Ry 1:Ru2) then
- {FlattenList {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