Advertisement
Guest User

Untitled

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