Advertisement
Guest User

Untitled

a guest
Nov 30th, 2016
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Oz 13.35 KB | None | 0 0
  1. %====INFORMATION====%
  2. % LFSAB1402 Projet 2016
  3. % Nomas : 07891500-38421500
  4. % Noms : (Tascon Gutierrez,Luis)-(Mawait,Maxime)
  5. %====MODULELINK====%
  6. declare
  7. [Projet]={Module.link ["Projet2016.ozf"]}
  8.  
  9. %====CODE====%
  10. local
  11.    MaxTime = 25 % nombre de frame à l'animation
  12.    MyFunction
  13.    Primitive
  14.    FlattenList
  15.    AppendList
  16.    Value
  17.    PokeSearch
  18.    PokeBuild
  19.    Translate
  20.    PokeTranslate
  21.    Scale
  22.    Spawn
  23.    Rotate
  24.    Map
  25.    CheckMap
  26.    Extensions = opt(withExtendedFormula:true
  27.             withIfThenElse:true
  28.             withComparison:true
  29.             withTimeWindow:false
  30.             withCheckMapEasy:true
  31.             withCheckMapComplete:true)
  32.    Building = primitive(kind:building)
  33.    B = scale(rx:10.0 ry:10.0 [Building])
  34.  
  35.    fun{A Acc Max}
  36.       if Acc < Max then translate(dx:mult(sin(Acc) Acc) dy:mult(cos(Acc) Acc) [B])|{A Acc+1.0 Max}
  37.       else nil
  38.       end
  39.    end
  40.    
  41.    Ru = [translate(dx:250.0 dy:250.0 {A 0.0 400.0})]
  42. in
  43.    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
  44.  
  45.  
  46.    fun{MyFunction Map}
  47.       case Map of map(ru: Ru pu: Pu) then
  48.      {AppendList {Build {Search {FlattenList Ru}}} {PokeBuild fun{$ Time} {PokeSearch {FlattenList Pu} Time} end}}
  49.       end
  50.    end
  51.  
  52.    fun{Primitive K}
  53.       case K of road then
  54.      realitem(kind: road p1: pt(x: 0.0 y: 0.0) p2: pt(x: 1.0 y: 0.0))
  55.       [] building then
  56.      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))
  57.       [] water then
  58.      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))
  59.       [] pokemon then
  60.      pokeitem(kind: pokemon position: pt(x: 0.0 y: 0.0))
  61.       [] pokestop then
  62.      pokeitem(kind: pokestop position: pt(x: 0.0 y: 0.0))
  63.       [] arena then
  64.      pokeitem(kind: arena position: pt(x: 0.0 y: 0.0))
  65.       end
  66.    end
  67.  
  68.  
  69.    fun{Translate D1 D2 L1}
  70.       Dx = {Value D1}
  71.       Dy = {Value D2}
  72.       L = {FlattenList L1}
  73.    in
  74.       case L of nil then nil
  75.       [] H|T then
  76.      case H of primitive(kind:K) then
  77.         {Translate D1 D2 [{Primitive K}]}|{Translate D1 D2 T}
  78.      [] realitem(kind:K p1: pt(x:X1 y:Y1) p2: pt(x:X2 y:Y2)) then
  79.         realitem(kind:K p1: pt(x:X1+Dx y:Y1+Dy) p2: pt(x:X2+Dx y:Y2+Dy))|{Translate D1 D2 T}
  80.      [] 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
  81.         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}
  82.      [] translate(dx:A dy:B 1:Ru) then
  83.         {Translate D1 D2 {Translate A B Ru}}|{Translate D1 D2 T}
  84.      [] scale(rx:A ry:B 1:Ru) then
  85.         {Translate D1 D2 {Scale A B Ru}}|{Translate D1 D2 T}
  86.      [] rotate(angle:A 1:Ru) then
  87.         {Translate D1 D2 {Rotate A Ru}}|{Translate D1 D2 T}
  88.      end
  89.       end
  90.    end
  91.  
  92.    fun{Scale R1 R2 L1}
  93.       Rx = {Value R1}
  94.       Ry = {Value R2}
  95.       L = {FlattenList L1}
  96.    in
  97.       case L of nil then nil
  98.       [] H|T then
  99.      case H of primitive(kind:K) then
  100.         {Scale Rx Ry [{Primitive K}]}|{Scale R1 R2 T}
  101.      [] realitem(kind:K p1: pt(x:X1 y:Y1) p2: pt(x:X2 y:Y2)) then
  102.         realitem(kind:K p1: pt(x:X1*Rx y:Y1*Ry) p2: pt(x:X2*Rx y:Y2*Ry))|{Scale R1 R2 T}
  103.      [] 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
  104.         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}
  105.      [] translate(dx: A dy: B 1:Ru) then
  106.         {Scale R1 R2 {Translate A B Ru}}|{Scale R1 R2 T}
  107.      [] scale(rx: A ry: B 1: Ru) then
  108.         {Scale R1 R2 {Scale A B Ru}}|{Scale R1 R2 T}
  109.      [] rotate(angle: A 1:Ru) then
  110.         {Scale R1 R2 {Rotate A Ru}}|{Scale R1 R2 T}
  111.      end
  112.       end
  113.    end
  114.  
  115.  
  116.    fun{Rotate A1 Ru1}
  117.       A = {Value A1}
  118.       Ru = {FlattenList Ru1}
  119.    in
  120.       case Ru of nil then nil
  121.       [] H|T then
  122.      case H of primitive(kind:K) then
  123.         {Rotate A [{Primitive K}]}|{Rotate A T}
  124.      [] translate(dx: Dx dy: Dy 1: L) then
  125.         {Rotate A {Translate Dx Dy L}}|{Rotate A T}
  126.      [] rotate(angle: A2 1: L) then
  127.         {Rotate A {Rotate A2 L}}|{Rotate A T}
  128.      [] scale(rx: Rx ry: Ry 1: L) then
  129.         {Rotate A {Scale Rx Ry L}}|{Rotate A T}
  130.      [] realitem(kind:K p1: pt(x:X1 y:Y1) p2: pt(x:X2 y:Y2)) then
  131.         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}
  132.      [] 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
  133.         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}
  134.      end
  135.       end
  136.    end
  137.  
  138.    fun{PokeTranslate Dx Dy L1 Time}
  139.       L = {FlattenList L1}
  140.    in
  141.       case L of nil then nil
  142.       [] H|T then
  143.      case H of primitive(kind: K) then
  144.         {PokeTranslate Dx Dy [{Primitive K}] Time}|{PokeTranslate Dx Dy T Time}
  145.      [] pokeitem(kind: K position: pt(x: X y: Y)) then
  146.         pokeitem(kind: K position: pt(x: plus(X Dx) y: plus(Y Dy)))|{PokeTranslate Dx Dy T Time}
  147.      [] translate(dx: D1 dy: D2 1:Pu) then
  148.         {PokeTranslate Dx Dy {PokeTranslate D1 D2 Pu Time}Time}|{PokeTranslate Dx Dy T Time}
  149.      [] spawn(tmin:Tmin tmax:Tmax Pu) then
  150.         {PokeTranslate Dx Dy {Spawn Tmin Tmax Pu Time} Time}|{PokeTranslate Dx Dy T Time}
  151.      [] empty then
  152.         empty|{PokeTranslate Dx Dy T Time}
  153.      end
  154.       end
  155.    end
  156.  
  157.    fun{Spawn Tmin1 Tmax1 L1 Time}
  158.       Tmin = {Int.toFloat Tmin1}
  159.       Tmax = {Int.toFloat Tmax1}
  160.    in
  161.       if Time >= Tmin then
  162.      if Time < Tmax then
  163.         L = {FlattenList L1}
  164.      in
  165.         L
  166.      else [empty]
  167.      end
  168.       else [empty]
  169.       end
  170.    end
  171.  
  172.    fun{PokeSearch Pu Time}
  173.       case Pu of nil then nil
  174.       [] H|T then
  175.      case H of primitive(kind: K) then {Primitive K}|{PokeSearch T Time}
  176.      [] translate(dx: Dx dy: Dy 1: Pu2) then
  177.         {FlattenList {PokeTranslate Dx Dy Pu2 Time}}|{PokeSearch T Time}
  178.      [] spawn(tmin:Tmin tmax:Tmax 1:Pu2) then
  179.         {PokeSearch {Spawn Tmin Tmax Pu2 Time} Time}|{PokeSearch T Time}
  180.      [] empty then
  181.         empty|{PokeSearch T Time}
  182.      end
  183.       end
  184.    end
  185.  
  186.    fun{PokeBuild Pu1}
  187.       Pu = {FlattenList Pu1}
  188.    in
  189.       case Pu of nil then nil
  190.       [] H|T then
  191.      case H of pokeitem(kind: K position: pt(x:X y:Y)) then
  192.         fun{$ Time}pokeitem(kind: K position: pt(x:{Formula X Time} y:{Formula Y Time}))end|{PokeBuild T}
  193.      [] nil then nil
  194.      [] empty then
  195.         fun{$ Time} empty end|{PokeBuild T}
  196.      end
  197.       end
  198.    end
  199.    
  200.    fun{Search Ru}
  201.       case Ru of nil then nil
  202.       [] H|T then
  203.      case H
  204.      of primitive(kind:K) then {Primitive K}|{Search T}
  205.      [] translate(dx:Dx dy:Dy 1:Ru2) then
  206.         {FlattenList {Translate Dx Dy Ru2}}|{Search T}
  207.      [] rotate(angle:Angle 1:Ru2) then
  208.         {FlattenList {Rotate Angle Ru2}}|{Search T}
  209.      [] scale(rx: Rx ry: Ry 1:Ru2) then
  210.         {FlattenList {Scale Rx Ry Ru2}}|{Search T}
  211.      end
  212.       end
  213.    end
  214.  
  215.    fun{Build L1}
  216.       L = {FlattenList L1}
  217.    in
  218.       case L of H|T then
  219.      fun{$ Time} H end|{Build T}
  220.       else nil
  221.       end
  222.    end
  223.  
  224.    fun{Value V}
  225.       % decrit les valeurs possibles de l'univers reel
  226.       if {Float.is V} then V
  227.       else case V
  228.        of plus(1:A 2:B) then {Value A} + {Value B}
  229.        [] minus(1:A 2:B) then {Value A} - {Value B}
  230.        [] mult(1:A 2:B) then {Value A} * {Value B}
  231.        [] 'div'(1:A 2:B) then {Value A} / {Value B}
  232.        [] cos(1:A) then {Float.cos {Value A}}
  233.        [] sin(1:A) then {Float.sin {Value A}}
  234.        [] tan(1:A) then {Float.tan {Value A}}
  235.        [] exp(1:A) then {Float.exp {Value A}}
  236.        [] log(1:A) then {Float.log {Value A}}
  237.        [] neg(1:A) then ~{Value A}
  238.        end
  239.       end
  240.    end
  241.  
  242.    fun{Formula F Time}
  243.       % donne les 'formules' du monde pokemon
  244.       if {Float.is F} then F
  245.       else
  246.      case F
  247.      of time then Time
  248.      [] plus(1:A 2:B) then {Formula A Time} + {Formula B Time}
  249.      [] minus(1:A 2:B) then {Formula A Time} - {Formula B Time}
  250.      [] mult(1:A 2:B) then {Formula A Time} * {Formula B Time}
  251.      [] 'div'(1:A 2:B) then {Formula A Time} / {Formula B Time}
  252.      [] cos(1:A) then {Float.cos {Formula A Time}}
  253.      [] sin(1:A) then {Float.sin {Formula A Time}}
  254.      [] tan(1:A) then {Float.tan {Formula A Time}}
  255.      [] exp(1:A) then {Float.exp {Formula A Time}}
  256.      [] log(1:A) then {Float.log {Formula A Time}}
  257.      [] neg(1:A) then ~{Formula A Time}
  258.      [] ite(1:A 2:B 3:C) then if {Formula A Time} == 0.0 then {Formula C Time} else {Formula B Time} end
  259.      [] eq(1:A 2:B) then if {Formula A Time} == {Formula B Time} then 1.0 else 0.0 end
  260.      [] ne(1:A 2:B) then if {Formula A Time} \= {Formula B Time} then 1.0 else 0.0 end
  261.      [] lt(1:A 2:B) then if {Formula A Time} < {Formula B Time} then 1.0 else 0.0 end
  262.      [] le(1:A 2:B) then if {Formula A Time} =< {Formula B Time} then 1.0 else 0.0 end
  263.      [] gt(1:A 2:B) then if {Formula A Time} > {Formula B Time} then 1.0 else 0.0 end
  264.      [] ge(1:A 2:B) then if {Formula A Time} >= {Formula B Time} then 1.0 else 0.0 end
  265.      end
  266.       end
  267.    end
  268.  
  269.    fun{AppendList X Y}
  270.       case X of nil then Y
  271.       [] H|T then H|{AppendList T Y}
  272.       end
  273.    end
  274.  
  275.  
  276.    fun{FlattenList X}
  277.       fun{IsList L}
  278.      case L of nil then true
  279.      [] H|T then true
  280.      else false
  281.      end
  282.       end
  283.    in
  284.       case X of nil then nil
  285.       [] H|T then
  286.      if {IsList H} then {AppendList {FlattenList H}{FlattenList T}}
  287.      else H|{FlattenList T}
  288.      end
  289.       end
  290.    end
  291.  
  292.  
  293.    fun{CheckMap Map}
  294.       fun{CheckVal Val}
  295.      if {Float.is Val} then true
  296.      else
  297.         case Val
  298.         of plus(A B) then ({CheckVal A} andthen {CheckVal B})
  299.         [] minus(A B) then ({CheckVal A} andthen {CheckVal B})
  300.         [] mult(A B) then ({CheckVal A} andthen {CheckVal B})
  301.         [] 'div'(A B) then ({CheckVal A} andthen {CheckVal B})
  302.         [] cos(A) then {CheckVal A}
  303.         [] sin(A) then {CheckVal A}
  304.         [] tan(A) then {CheckVal A}
  305.         [] exp(A) then {CheckVal A}
  306.         [] log(A) then {CheckVal A}
  307.         [] neg(A) then {CheckVal A}
  308.         else false
  309.         end
  310.      end
  311.       end
  312.       fun{CheckForm Form}
  313.      if {Float.is Form} then true
  314.      else
  315.         case Form
  316.         of plus(A B) then ({CheckForm A} andthen {CheckForm B})
  317.         [] time then true
  318.         [] minus(A B) then ({CheckForm A} andthen {CheckForm B})
  319.         [] mult(A B) then ({CheckForm A} andthen {CheckForm B})
  320.         [] 'div'(A B) then ({CheckForm A} andthen {CheckForm B})
  321.         [] cos(A) then {CheckForm A}
  322.         [] sin(A) then {CheckForm A}
  323.         [] tan(A) then {CheckForm A}
  324.         [] exp(A) then {CheckForm A}
  325.         [] log(A) then {CheckForm A}
  326.         [] neg(A) then {CheckForm A}
  327.         [] ite(A B C) then ({CheckForm A} andthen {CheckForm B} andthen {CheckForm C})
  328.         [] eq(A B) then ({CheckForm A} andthen {CheckForm B})
  329.         [] ne(A B) then ({CheckForm A} andthen {CheckForm B})
  330.         [] lt(A B) then ({CheckForm A} andthen {CheckForm B})
  331.         [] le(A B) then ({CheckForm A} andthen {CheckForm B})
  332.         [] gt(A B) then ({CheckForm A} andthen {CheckForm B})
  333.         [] ge(A B) then ({CheckForm A} andthen {CheckForm B})
  334.         else false
  335.         end
  336.      end
  337.  
  338.       end
  339.       fun{CheckPrim Prim}
  340.      case Prim
  341.      of road then true
  342.      [] building then true
  343.      [] water then true
  344.      else false
  345.      end
  346.       end
  347.       fun{CheckPrimPok Prim}
  348.      case Prim
  349.      of pokemon then true
  350.      [] arena then true
  351.      [] pokestop then true
  352.      else false
  353.      end
  354.       end
  355.       fun{CheckTrans Dx Dy Ru}
  356.      ({CheckVal Dx} andthen {CheckVal Dy} andthen {CheckR Ru})
  357.       end
  358.       fun{CheckTransPok Dx Dy Pu}
  359.      ({CheckForm Dx} andthen {CheckForm Dy} andthen {CheckP Pu})
  360.       end
  361.       fun{CheckRot Angle Ru}
  362.      ({CheckVal Angle} andthen {CheckR Ru})
  363.       end
  364.       fun{CheckScale Rx Ry Ru}
  365.      ({CheckVal Rx} andthen {CheckVal Ry} andthen {CheckR Ru})
  366.       end
  367.       fun{CheckSpa Tmin Tmax Pu}
  368.      ({Int.is Tmin} andthen {Int.is Tmax} andthen {CheckP Pu})
  369.       end
  370.       fun{CheckR Ru}
  371.      case Ru
  372.      of H|T then
  373.         case H
  374.         of primitive(kind:A) then ({CheckPrim A} andthen {CheckR T})
  375.         [] translate(dx:Dx dy:Dy 1:Ru1) then ({CheckTrans Dx Dy Ru1} andthen {CheckR T})
  376.         [] rotate(angle:Angle 1:Ru1) then ({CheckRot Angle Ru1} andthen {CheckR T})
  377.         [] scale(rx:Rx ry:Ry 1:Ru1) then ({CheckScale Rx Ry Ru1} andthen {CheckR T})
  378.         else false
  379.         end
  380.      [] nil then true
  381.      else false
  382.      end
  383.       end
  384.       fun{CheckP Pu}
  385.      case Pu
  386.      of H|T then
  387.         case H
  388.         of primitive(kind:A) then ({CheckPrimPok A} andthen {CheckP T})
  389.         [] translate(dx:Dx dy:Dy 1:Pu1) then ({CheckTransPok Dx Dy Pu1} andthen {CheckP T})
  390.         [] spawn(tmin:Tmin tmax:Tmax 1:Pu1) then ({CheckSpa Tmin Tmax Pu1} andthen {CheckP T})
  391.         else false
  392.         end
  393.      [] nil then true
  394.      else false
  395.      end
  396.       end
  397.    in
  398.       case Map
  399.       of map(ru:Ru pu:Pu) then
  400.      ({CheckR Ru} andthen {CheckP Pu})
  401.       else false
  402.       end
  403.    end
  404.  
  405.    
  406.    
  407.    {Projet.run MyFunction Map MaxTime Extensions CheckMap}
  408. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement