Advertisement
Guest User

Untitled

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