Advertisement
Guest User

Untitled

a guest
Nov 28th, 2016
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Oz 9.29 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.    Spawn
  20.    Translate
  21.    PokeTranslate
  22.    Scale
  23.    Rotate
  24.    Map
  25.    CheckMap
  26.    Extensions = opt(withExtendedFormula:true
  27.             withIfThenElse:true
  28.             withComparison:true
  29.             withTimeWindow:false
  30.             withCheckMapEasy:false
  31.             withCheckMapComplete:false
  32.            )
  33.    Building = primitive(kind:building)
  34.    B = scale(rx:10.0 ry:10.0 [Building])
  35.  
  36.    fun{A Acc Max}
  37.       if Acc < Max then translate(dx:mult(sin(Acc) Acc) dy:mult(cos(Acc) Acc) [B])|{A Acc+1.0 Max}
  38.       else nil
  39.       end
  40.    end
  41.    
  42.    Ru = [translate(dx:250.0 dy:250.0 {A 0.0 400.0})]
  43. in
  44.    Map = map(ru:Ru pu:[translate(dx: mult(time time) dy: mult(time time) 1:[primitive(kind:pokemon)]) translate(dx:250.0 dy:250.0 [primitive(kind:arena)]) translate(dx:300.0 dy:100.0 [primitive(kind:pokestop)])]) %% TODO change the map here
  45.    
  46.  
  47.    fun{MyFunction Map}
  48.       case Map of map(ru: Ru pu: Pu) then
  49.      {AppendList {Build {Search {FlattenList Ru}}} {PokeBuild {PokeSearch {FlattenList Pu}}}}
  50.       else nil
  51.       end
  52.    end
  53.  
  54.    fun{Primitive K}
  55.       case K of road then
  56.      realitem(kind: road p1: pt(x: 0.0 y: 0.0) p2: pt(x: 1.0 y: 0.0))
  57.       [] building then
  58.      realitem(kind: building p1: pt(x: 0.0 y: 0.0) p2: pt(x: 1.0 y: 0.0) p3: pt(x: 1.0 y: 1.0) p4: pt(x: 0.0 y: 1.0))
  59.       [] water then
  60.      realitem(kind: water p1: pt(x: 0.0 y: 0.0) p2: pt(x: 1.0 y: 0.0) p3: pt(x: 1.0 y: 1.0) p4: pt(x: 0.0 y: 1.0))
  61.       [] pokemon then
  62.      pokeitem(kind: pokemon position: pt(x: 0.0 y: 0.0))
  63.       [] pokestop then
  64.      pokeitem(kind: pokestop position: pt(x: 0.0 y: 0.0))
  65.       [] arena then
  66.      pokeitem(kind: arena position: pt(x: 0.0 y: 0.0))
  67.       end
  68.    end
  69.  
  70.  
  71.    fun{Translate D1 D2 L1}
  72.       Dx = {Value D1}
  73.       Dy = {Value D2}
  74.       L = {FlattenList L1}
  75.    in
  76.       case L of nil then nil
  77.       [] H|T then
  78.      case H of primitive(kind:K) then
  79.         {Translate D1 D2 [{Primitive K}]}|{Translate D1 D2 T}
  80.      [] realitem(kind:K p1: pt(x:X1 y:Y1) p2: pt(x:X2 y:Y2)) then
  81.         realitem(kind:K p1: pt(x:X1+Dx y:Y1+Dy) p2: pt(x:X2+Dx y:Y2+Dy))|{Translate D1 D2 T}
  82.      [] 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
  83.         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}
  84.      [] translate(dx: A dy: B 1:Ru) then
  85.         {Translate D1 D2 {Translate A B Ru}}|{Translate D1 D2 T}
  86.      [] scale(rx: A ry: B 1: Ru) then
  87.         {Translate D1 D2 {Scale A B Ru}}|{Translate D1 D2 T}
  88.      [] rotate(angle: A 1:Ru) then
  89.         {Translate D1 D2 {Rotate A Ru}}|{Translate D1 D2 T}
  90.      end
  91.       end
  92.    end
  93.  
  94.    fun{Scale R1 R2 L1}
  95.       Rx = {Value R1}
  96.       Ry = {Value R2}
  97.       L = {FlattenList L1}
  98.    in
  99.       case L of nil then nil
  100.       [] H|T then
  101.      case H of primitive(kind:K) then
  102.         {Scale R1 R2 [{Primitive K}]}|{Scale R1 R2 T}
  103.      [] realitem(kind:K p1: pt(x:X1 y:Y1) p2: pt(x:X2 y:Y2)) then
  104.         realitem(kind:K p1: pt(x:X1*Rx y:Y1*Ry) p2: pt(x:X2*Rx y:Y2*Ry))|{Scale R1 R2 T}
  105.      [] 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
  106.         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}
  107.      [] translate(dx: A dy: B 1:Ru) then
  108.         {Scale R1 R2 {Translate A B Ru}}|{Scale R1 R2 T}
  109.      [] scale(rx: A ry: B 1: Ru) then
  110.         {Scale R1 R2 {Scale A B Ru}}|{Scale R1 R2 T}
  111.      [] rotate(angle: A 1:Ru) then
  112.         {Scale R1 R2 {Rotate A Ru}}|{Scale R1 R2 T}
  113.      end
  114.       end
  115.    end
  116.  
  117.  
  118.    fun{Rotate A1 Ru1}
  119.       A = {Value A1}
  120.       Ru = {FlattenList Ru1}
  121.    in
  122.       case Ru of nil then nil
  123.       [] H|T then
  124.      case H of primitive(kind:K) then
  125.         {Rotate A [{Primitive K}]}|{Rotate A T}
  126.      [] translate(dx: Dx dy: Dy 1: Ru) then
  127.         {Rotate A {Translate Dx Dy Ru}}|{Rotate A T}
  128.      [] rotate(angle: A2 1: Ru) then
  129.         {Rotate A {Rotate A2 Ru}}|{Rotate A T}
  130.      [] scale(rx: Rx ry: Ry 1: Ru) then
  131.         {Rotate A {Scale Rx Ry Ru}}|{Rotate A T}
  132.      [] realitem(kind:K p1: pt(x:X1 y:Y1) p2: pt(x:X2 y:Y2)) 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)))}))|{Rotate A T}
  134.      [] 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
  135.         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}
  136.      end
  137.       end
  138.    end
  139.  
  140.    fun{PokeTranslate Dx Dy L1}
  141.       L = {FlattenList L1}
  142.    in
  143.       case L of nil then nil
  144.       [] H|T then
  145.      case H of primitive(kind: K) then
  146.         {PokeTranslate Dx Dy [{Primitive K}]}|{PokeTranslate Dx Dy T}
  147.      [] pokeitem(kind: K position: pt(x: X y: Y)) then
  148.         pokeitem(kind: K position: pt(x: plus(X Dx) y: plus(Y Dy)))|{PokeTranslate Dx Dy T}
  149.      end
  150.       end
  151.    end
  152.  
  153.    
  154.  
  155.    fun{PokeSearch Pu}
  156.       case Pu of nil then nil
  157.       [] H|T then
  158.      case H of primitive(kind: K) then {Primitive K}|{PokeSearch T}
  159.      [] translate(dx: Dx dy: Dy 1: Pu2) then
  160.         {FlattenList {PokeTranslate Dx Dy Pu2}}|{PokeSearch T}
  161.      end
  162.       end
  163.    end
  164.  
  165.    fun{PokeBuild Pu1}
  166.       Pu = {FlattenList Pu1}
  167.    in
  168.       case Pu of nil then nil
  169.       [] H|T then
  170.      case H of pokeitem(kind: K position: pt(x:X y:Y)) then
  171.         fun{$ Time}pokeitem(kind: K position: pt(x:{Formula X Time} y:{Formula Y Time}))end|{PokeBuild T}
  172.      else nil
  173.      end
  174.       end
  175.    end
  176.    
  177.      
  178.    
  179.      
  180.        
  181.  
  182.    fun{Search Ru}
  183.       case Ru of nil then nil
  184.       [] H|T then
  185.      case H
  186.      of primitive(kind:K) then {Primitive K}|{Search T}
  187.      [] translate(dx:Dx dy:Dy 1:Ru2) then {FlattenList {Translate Dx Dy Ru2}}|{Search T}
  188.      [] rotate(angle:Angle 1:Ru2) then {FlattenList {Rotate Angle Ru2}}|{Search T}
  189.      [] scale(rx: Rx ry: Ry 1:Ru2) then {FlattenList {Scale Rx Ry Ru2}}|{Search T}
  190.      end
  191.       end
  192.    end
  193.  
  194.    fun{Build L1}
  195.       L = {FlattenList L1}
  196.    in
  197.       case L of H|T then
  198.      fun{$ Time} H end|{Build T}
  199.       else nil
  200.       end
  201.    end
  202.  
  203.    fun{Value V}
  204.       % decrit les valeurs possibles de l'univers reel
  205.       if {Float.is V} then V
  206.       elseif {Int.is V} then {Int.toFloat V}
  207.       else case V
  208.        of plus(1:A 2:B) then {Value A} + {Value B}
  209.        [] minus(1:A 2:B) then {Value A} - {Value B}
  210.        [] mult(1:A 2:B) then {Value A} * {Value B}
  211.        [] 'div'(1:A 2:B) then {Value A} / {Value B}
  212.        [] cos(1:A) then {Float.cos {Value A}}
  213.        [] sin(1:A) then {Float.sin {Value A}}
  214.        [] tan(1:A) then {Float.tan {Value A}}
  215.        [] exp(1:A) then {Float.exp {Value A}}
  216.        [] log(1:A) then {Float.log {Value A}}
  217.        [] neg(1:A) then ~{Value A}
  218.        end
  219.       end
  220.    end
  221.  
  222.    fun{Formula F Time}
  223.       % donne les 'formules' du monde pokemon
  224.       if {Float.is F} then F
  225.       elseif {Int.is F} then {Int.toFloat F}
  226.       else
  227.      case F
  228.      of time then Time
  229.      [] plus(1:A 2:B) then {Formula A Time} + {Formula B Time}
  230.      [] minus(1:A 2:B) then {Formula A Time} - {Formula B Time}
  231.      [] mult(1:A 2:B) then {Formula A Time} * {Formula B Time}
  232.      [] 'div'(1:A 2:B) then {Formula A Time} / {Formula B Time}
  233.      [] cos(1:A) then {Float.cos {Formula A Time}}
  234.      [] sin(1:A) then {Float.sin {Formula A Time}}
  235.      [] tan(1:A) then {Float.tan {Formula A Time}}
  236.      [] exp(1:A) then {Float.exp {Formula A Time}}
  237.      [] log(1:A) then {Float.log {Formula A Time}}
  238.      [] neg(1:A) then ~{Formula A Time}
  239.      [] ite(1:A 2:B 3:C) then if {Formula A Time} == 0.0 then {Formula C Time} else {Formula B Time} end
  240.      [] eq(1:A 2:B) then if {Formula A Time} == {Formula B Time} then 1.0 else 0.0 end
  241.      [] ne(1:A 2:B) then if {Formula A Time} \= {Formula B Time} then 1.0 else 0.0 end
  242.      [] lt(1:A 2:B) then if {Formula A Time} < {Formula B Time} then 1.0 else 0.0 end
  243.      [] le(1:A 2:B) then if {Formula A Time} =< {Formula B Time} then 1.0 else 0.0 end
  244.      [] gt(1:A 2:B) then if {Formula A Time} > {Formula B Time} then 1.0 else 0.0 end
  245.      [] ge(1:A 2:B) then if {Formula A Time} >= {Formula B Time} then 1.0 else 0.0 end
  246.      end
  247.       end
  248.    end
  249.  
  250.    fun{AppendList X Y}
  251.       case X of nil then Y
  252.       [] H|T then H|{AppendList T Y}
  253.       end
  254.    end
  255.  
  256.  
  257.    fun{FlattenList X}
  258.       fun{IsList L}
  259.      case L of nil then true
  260.      [] H|T then true
  261.      else false
  262.      end
  263.       end
  264.    in
  265.       case X of nil then nil
  266.       [] H|T then
  267.      if {IsList H} then {AppendList {FlattenList H}{FlattenList T}}
  268.      else H|{FlattenList T}
  269.      end
  270.       end
  271.    end
  272.  
  273.  
  274.    fun{CheckMap Map}
  275.       false %% TODO complete here the function for the checking of the maps
  276.    end
  277.  
  278.    
  279.    
  280.    {Projet.run MyFunction Map MaxTime Extensions CheckMap}
  281. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement