Advertisement
Guest User

Untitled

a guest
Dec 1st, 2016
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Oz 13.45 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.    Rotate
  23.    Map
  24.    Spawn
  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:nil pu:[translate(dx:250.0 dy:250.0 [spawn(tmin:5 tmax:15 [primitive(kind:pokemon)])])]) %% TODO change the map here
  44.  
  45.    fun{MyFunction Map}
  46.       case Map of map(ru: Ru pu: Pu) then
  47.      {AppendList {Build {Search {FlattenList Ru}}} {PokeBuild  {PokeSearch {FlattenList Pu}}}}
  48.       end
  49.    end
  50.  
  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}
  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}]}|{PokeTranslate Dx Dy T}
  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}
  147.      [] translate(dx: D1 dy: D2 1:Pu) then
  148.         {PokeTranslate Dx Dy {PokeTranslate D1 D2 Pu}}|{PokeTranslate Dx Dy T}
  149.      [] spawn(tmin:Tmin tmax:Tmax Pu) then
  150.         {Spawn Tmin Tmax  {PokeTranslate Dx Dy Pu}}|{PokeTranslate Dx Dy T}
  151.      end
  152.       end
  153.    end
  154.  
  155.    fun{Spawn Tmin Tmax L1}
  156.       L = {FlattenList L1}
  157.    in
  158.       case L
  159.       of H|T then
  160.      case H
  161.      of primitive(kind: K) then
  162.         {Spawn Tmin Tmax [{Primitive K}]}|{Spawn Tmin Tmax T}
  163.      [] pokeitem(kind: K position: pt(x: X y: Y)) then
  164.         spawn(tmin:Tmin tmax:Tmax 1:[pokeitem(kind: K position: pt(x:X y:Y))])|{Spawn Tmin Tmax T}
  165.      [] translate(dx: D1 dy: D2 1:Pu) then
  166.         spawn(tmin:Tmin tmax:Tmax 1:{PokeTranslate D1 D2 Pu})|{Spawn Tmin Tmax T}
  167.      [] spawn(tmin:A tmax:B 1:Pu) then
  168.         spawn(tmin:Tmin tmax:Tmax 1:{Spawn A B Pu})|{Spawn Tmin Tmax T}
  169.      end
  170.       [] nil then nil
  171.       end
  172.    end
  173.  
  174.    fun{PokeSearch Pu}
  175.       case Pu of nil then nil
  176.       [] H|T then
  177.      case H of primitive(kind: K) then {Primitive K}|{PokeSearch T}
  178.      [] translate(dx: Dx dy: Dy 1: Pu2) then
  179.         {FlattenList {PokeTranslate Dx Dy Pu2}|{PokeSearch T}}
  180.      [] spawn(tmin:Tmin tmax:Tmax 1:Pu2) then
  181.         {FlattenList {Spawn Tmin Tmax Pu2}|{PokeSearch T}}
  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.      [] spawn(tmin:Tmin tmax:Tmax 1:B) then
  194.         local X = {PokeBuild B} in
  195.            fun{$ Time}if({Float.toInt Time} >= Tmin andthen {Float.toInt Time} < Tmax)then {X.1 Time} else empty end end|{PokeBuild T}
  196.         end
  197.      [] nil then nil
  198.      end
  199.       end
  200.    end
  201.    
  202.    fun{Search Ru}
  203.       case Ru of nil then nil
  204.       [] H|T then
  205.      case H
  206.      of primitive(kind:K) then {Primitive K}|{Search T}
  207.      [] translate(dx:Dx dy:Dy 1:Ru2) then
  208.         {FlattenList {Translate Dx Dy Ru2}|{Search T}}
  209.      [] rotate(angle:Angle 1:Ru2) then
  210.         {FlattenList {Rotate Angle Ru2}|{Search T}}
  211.      [] scale(rx: Rx ry: Ry 1:Ru2) then
  212.         {FlattenList {Scale Rx Ry Ru2}|{Search T}}
  213.      end
  214.       end
  215.    end
  216.  
  217.    fun{Build L1}
  218.       L = {FlattenList L1}
  219.    in
  220.       case L of H|T then
  221.      fun{$ Time} H end|{Build T}
  222.       else nil
  223.       end
  224.    end
  225.  
  226.    fun{Value V}
  227.       % decrit les valeurs possibles de l'univers reel
  228.       if {Float.is V} then V
  229.       else case V
  230.        of plus(1:A 2:B) then {Value A} + {Value B}
  231.        [] minus(1:A 2:B) then {Value A} - {Value B}
  232.        [] mult(1:A 2:B) then {Value A} * {Value B}
  233.        [] 'div'(1:A 2:B) then {Value A} / {Value B}
  234.        [] cos(1:A) then {Float.cos {Value A}}
  235.        [] sin(1:A) then {Float.sin {Value A}}
  236.        [] tan(1:A) then {Float.tan {Value A}}
  237.        [] exp(1:A) then {Float.exp {Value A}}
  238.        [] log(1:A) then {Float.log {Value A}}
  239.        [] neg(1:A) then ~{Value A}
  240.        end
  241.       end
  242.    end
  243.  
  244.    fun{Formula F Time}
  245.       % donne les 'formules' du monde pokemon
  246.       if {Float.is F} then F
  247.       else
  248.      case F
  249.      of time then Time
  250.      [] plus(1:A 2:B) then {Formula A Time} + {Formula B Time}
  251.      [] minus(1:A 2:B) then {Formula A Time} - {Formula B Time}
  252.      [] mult(1:A 2:B) then {Formula A Time} * {Formula B Time}
  253.      [] 'div'(1:A 2:B) then {Formula A Time} / {Formula B Time}
  254.      [] cos(1:A) then {Float.cos {Formula A Time}}
  255.      [] sin(1:A) then {Float.sin {Formula A Time}}
  256.      [] tan(1:A) then {Float.tan {Formula A Time}}
  257.      [] exp(1:A) then {Float.exp {Formula A Time}}
  258.      [] log(1:A) then {Float.log {Formula A Time}}
  259.      [] neg(1:A) then ~{Formula A Time}
  260.      [] ite(1:A 2:B 3:C) then if {Formula A Time} == 0.0 then {Formula C Time} else {Formula B Time} end
  261.      [] eq(1:A 2:B) then if {Formula A Time} == {Formula B Time} then 1.0 else 0.0 end
  262.      [] ne(1:A 2:B) then if {Formula A Time} \= {Formula B Time} then 1.0 else 0.0 end
  263.      [] lt(1:A 2:B) then if {Formula A Time} < {Formula B Time} then 1.0 else 0.0 end
  264.      [] le(1:A 2:B) then if {Formula A Time} =< {Formula B Time} then 1.0 else 0.0 end
  265.      [] gt(1:A 2:B) then if {Formula A Time} > {Formula B Time} then 1.0 else 0.0 end
  266.      [] ge(1:A 2:B) then if {Formula A Time} >= {Formula B Time} then 1.0 else 0.0 end
  267.      end
  268.       end
  269.    end
  270.  
  271.    fun{AppendList X Y}
  272.       case X of nil then Y
  273.       [] H|T then H|{AppendList T Y}
  274.       end
  275.    end
  276.  
  277.  
  278.    fun{FlattenList X}
  279.       fun{IsList L}
  280.      case L of nil then true
  281.      [] H|T then true
  282.      else false
  283.      end
  284.       end
  285.    in
  286.       case X of nil then nil
  287.       [] H|T then
  288.      if {IsList H} then {AppendList {FlattenList H}{FlattenList T}}
  289.      else H|{FlattenList T}
  290.      end
  291.       end
  292.    end
  293.  
  294.  
  295.    fun{CheckMap Map}
  296.       fun{CheckVal Val}
  297.      if {Float.is Val} then true
  298.      else
  299.         case Val
  300.         of plus(A B) then ({CheckVal A} andthen {CheckVal B})
  301.         [] minus(A B) then ({CheckVal A} andthen {CheckVal B})
  302.         [] mult(A B) then ({CheckVal A} andthen {CheckVal B})
  303.         [] 'div'(A B) then ({CheckVal A} andthen {CheckVal B})
  304.         [] cos(A) then {CheckVal A}
  305.         [] sin(A) then {CheckVal A}
  306.         [] tan(A) then {CheckVal A}
  307.         [] exp(A) then {CheckVal A}
  308.         [] log(A) then {CheckVal A}
  309.         [] neg(A) then {CheckVal A}
  310.         else false
  311.         end
  312.      end
  313.       end
  314.       fun{CheckForm Form}
  315.      if {Float.is Form} then true
  316.      else
  317.         case Form
  318.         of plus(A B) then ({CheckForm A} andthen {CheckForm B})
  319.         [] time then true
  320.         [] minus(A B) then ({CheckForm A} andthen {CheckForm B})
  321.         [] mult(A B) then ({CheckForm A} andthen {CheckForm B})
  322.         [] 'div'(A B) then ({CheckForm A} andthen {CheckForm B})
  323.         [] cos(A) then {CheckForm A}
  324.         [] sin(A) then {CheckForm A}
  325.         [] tan(A) then {CheckForm A}
  326.         [] exp(A) then {CheckForm A}
  327.         [] log(A) then {CheckForm A}
  328.         [] neg(A) then {CheckForm A}
  329.         [] ite(A B C) then ({CheckForm A} andthen {CheckForm B} andthen {CheckForm C})
  330.         [] eq(A B) then ({CheckForm A} andthen {CheckForm B})
  331.         [] ne(A B) then ({CheckForm A} andthen {CheckForm B})
  332.         [] lt(A B) then ({CheckForm A} andthen {CheckForm B})
  333.         [] le(A B) then ({CheckForm A} andthen {CheckForm B})
  334.         [] gt(A B) then ({CheckForm A} andthen {CheckForm B})
  335.         [] ge(A B) then ({CheckForm A} andthen {CheckForm B})
  336.         else false
  337.         end
  338.      end
  339.  
  340.       end
  341.       fun{CheckPrim Prim}
  342.      case Prim
  343.      of road then true
  344.      [] building then true
  345.      [] water then true
  346.      else false
  347.      end
  348.       end
  349.       fun{CheckPrimPok Prim}
  350.      case Prim
  351.      of pokemon then true
  352.      [] arena then true
  353.      [] pokestop then true
  354.      else false
  355.      end
  356.       end
  357.       fun{CheckTrans Dx Dy Ru}
  358.      ({CheckVal Dx} andthen {CheckVal Dy} andthen {CheckR Ru})
  359.       end
  360.       fun{CheckTransPok Dx Dy Pu}
  361.      ({CheckForm Dx} andthen {CheckForm Dy} andthen {CheckP Pu})
  362.       end
  363.       fun{CheckRot Angle Ru}
  364.      ({CheckVal Angle} andthen {CheckR Ru})
  365.       end
  366.       fun{CheckScale Rx Ry Ru}
  367.      ({CheckVal Rx} andthen {CheckVal Ry} andthen {CheckR Ru})
  368.       end
  369.       fun{CheckSpa Tmin Tmax Pu}
  370.      ({Int.is Tmin} andthen {Int.is Tmax} andthen {CheckP Pu})
  371.       end
  372.       fun{CheckR Ru}
  373.      case Ru
  374.      of H|T then
  375.         case H
  376.         of primitive(kind:A) then ({CheckPrim A} andthen {CheckR T})
  377.         [] translate(dx:Dx dy:Dy 1:Ru1) then ({CheckTrans Dx Dy Ru1} andthen {CheckR T})
  378.         [] rotate(angle:Angle 1:Ru1) then ({CheckRot Angle Ru1} andthen {CheckR T})
  379.         [] scale(rx:Rx ry:Ry 1:Ru1) then ({CheckScale Rx Ry Ru1} andthen {CheckR T})
  380.         else false
  381.         end
  382.      [] nil then true
  383.      else false
  384.      end
  385.       end
  386.       fun{CheckP Pu}
  387.      case Pu
  388.      of H|T then
  389.         case H
  390.         of primitive(kind:A) then ({CheckPrimPok A} andthen {CheckP T})
  391.         [] translate(dx:Dx dy:Dy 1:Pu1) then ({CheckTransPok Dx Dy Pu1} andthen {CheckP T})
  392.         [] spawn(tmin:Tmin tmax:Tmax 1:Pu1) then ({CheckSpa Tmin Tmax Pu1} andthen {CheckP T})
  393.         else false
  394.         end
  395.      [] nil then true
  396.      else false
  397.      end
  398.       end
  399.    in
  400.       case Map
  401.       of map(ru:Ru pu:Pu) then
  402.      ({CheckR Ru} andthen {CheckP Pu})
  403.       else false
  404.       end
  405.    end
  406.    
  407.    {Projet.run MyFunction Map MaxTime Extensions CheckMap}
  408. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement