Advertisement
Guest User

Untitled

a guest
Dec 1st, 2016
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Oz 12.08 KB | None | 0 0
  1. %====CODE====%
  2. local
  3.    MaxTime = 10 % nombre de frame  l'animation
  4.    MyFunction
  5.    Map
  6.    CheckMap
  7.    Extensions = opt(withExtendedFormula:true
  8.             withIfThenElse:true
  9.             withComparison:true
  10.             withTimeWindow:false
  11.             withCheckMapEasy:true
  12.             withCheckMapComplete:false
  13.            )
  14. in
  15.    Map = map(ru:scale(rx:20.0 ry:20.0 1:primitive(kind:water)|nil)|nil  pu:translate(dx:200.0 dy:200.0 1:primitive(kind:pokestop)|nil)|nil) %% TODO change the map here
  16.    fun{MyFunction Map}
  17. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  18.       %%REALUNIVERSE%%
  19.       local ListeReal ListePoke Append in
  20.      local Runiverse  in
  21.         fun {Runiverse P}      
  22.            local Traduction Liste FlattenList Translate Scale Rotate Affiche Take Inverse L CheckValue in
  23.           fun {CheckValue Value}
  24.              if {Float.is Value} then Value
  25.              else
  26.             case Value
  27.             of plus(X Y) then {CheckValue X}+{CheckValue Y}
  28.             []minus(X Y) then {CheckValue X}-{CheckValue Y}
  29.             []mult(X Y) then {CheckValue X}*{CheckValue Y}
  30.             []'div'(X Y) then {CheckValue X}/{CheckValue Y}
  31.             []sin(X) then {Float.sin {CheckValue X}}
  32.             []cos(X) then {Float.cos {CheckValue X}}
  33.             []tan(X) then {Float.tan {CheckValue X}}
  34.             []exp(X) then {Float.exp {CheckValue X}}
  35.             []log(X) then {Float.log {CheckValue X}}
  36.             []neg(X) then ~{CheckValue X}
  37.             end
  38.              end
  39.           end
  40.              
  41.           fun {Liste L Acc Acc2}
  42.              case L of nil then Acc2
  43.              []H|T then case H
  44.                 of translate(dx:DX dy:DY 1:N) then {Liste N H|Acc Acc2}|{Liste T Acc Acc2}  
  45.                 [] rotate(angle:A 1:N) then {Liste N H|Acc Acc2}|{Liste T Acc Acc2}
  46.                 [] scale(rx:RX ry:RY 1:N) then{Liste N H|Acc Acc2}|{Liste T Acc Acc2}
  47.                 [] primitive(kind:A) then  [H|Acc]|Acc2|{Liste T Acc Acc2}
  48.                 end
  49.              end
  50.           end
  51.           fun {FlattenList L}
  52.              case L
  53.              of nil then nil
  54.              [] nil|T then {FlattenList T}
  55.              [](H1|T1)|T then {FlattenList H1|T1|T}
  56.              [] X|T then X|{FlattenList T}
  57.              else L
  58.              end
  59.           end
  60.           fun {Take L Acc Acc2}%%Sors la premiere liste contenant une primitive et ses deformations associees.
  61.              case L of nil then Acc2
  62.              []primitive(kind:K)|T then {Take T nil {Traduction primitive(kind:K)|Acc nil}|Acc2}
  63.              []H|T then {Take T H|Acc Acc2}
  64.              end
  65.           end
  66.           fun{Inverse L Acc}%%retourne une liste inversee.
  67.              case L of nil then Acc
  68.              []H|T then {Inverse T H|Acc}
  69.              end
  70.           end
  71.           fun {Scale A Rx Ry} %%Ok
  72.              case A
  73.              of realitem(kind:H p1:pt(x:B y:C) p2:pt(x:D y:E))
  74.              then realitem(kind:H
  75.                    p1:pt(x:B*{CheckValue Rx} y:C*{CheckValue Ry})
  76.                    p2:pt(x:D*{CheckValue Rx} y:E*{CheckValue Ry}))%pour translater la road
  77.              []realitem(kind:H p1:B p2:C p3:D p4:E)
  78.              then
  79.             realitem(kind:H
  80.                  p1:pt(x:B.x*{CheckValue Rx} y:B.y*{CheckValue Ry})
  81.                  p2:pt(x:C.x*{CheckValue Rx} y:C.y*{CheckValue Ry})
  82.                  p3:pt(x:D.x*{CheckValue Rx} y:D.y*{CheckValue Ry})
  83.                  p4:pt(x:E.x*{CheckValue Rx} y:E.y*{CheckValue Ry}))%pour translater water et building
  84.              else nil
  85.              end
  86.           end
  87.  
  88.           fun{Rotate A B}
  89.              case A
  90.              of r(kind:Q position:pt(x:D y:E))
  91.              then r(kind:Q position:pt(x:D*{CheckValue cos(B)}+E*{CheckValue sin(B)} y:~D*{CheckValue sin(B)}+E*{CheckValue cos(B)}))
  92.              []r(kind:Q p1:pt(x:M y:N) p2:pt(x:D y:E))
  93.              then r(kind:Q
  94.                 p1:pt(x:M*{CheckValue cos(B)}+N*{CheckValue sin(B)} y:~M*{CheckValue sin(B)}+N*{CheckValue cos(B)})
  95.                 p2:pt(x:D*{CheckValue cos(B)}+E*{CheckValue sin(B)} y:~D*{CheckValue sin(B)}+E*{CheckValue cos(B)}))%pour faire une rotation de la road
  96.  
  97.              []r(kind:Q p1:pt(x:M y:N) p2:pt(x:D y:E) p3:pt(x:F y:G) p4:pt(x:H y:I))
  98.              then r(kind:Q
  99.                 p1:pt(x:M*{CheckValue cos(B)}+N*{CheckValue sin(B)} y:~M*{CheckValue sin(B)}+N*{CheckValue cos(B)})
  100.                 p2:pt(x:D*{CheckValue cos(B)}+E*{CheckValue sin(B)} y:~D*{CheckValue sin(B)}+E*{CheckValue cos(B)})
  101.                 p3:pt(x:F*{CheckValue cos(B)}+G*{CheckValue sin(B)} y:~F*{CheckValue sin(B)}+G*{CheckValue cos(B)})
  102.                 p4:pt(x:H*{CheckValue cos(B)}+I*{CheckValue sin(B)} y:~H*{CheckValue sin(B)}+I*{CheckValue cos(B)}))%pour faire une rotation de  water et buildin
  103.              end
  104.           end
  105.            
  106.           fun{Translate Z DX DY}%ok
  107.              case Z
  108.              of realitem(kind:A p1:pt(x:B y:C) p2:pt(x:D y:E))
  109.              then realitem(kind:A
  110.                    p1:pt(x:B+{CheckValue DX} y:C+{CheckValue DY})
  111.                    p2:pt(x:D+{CheckValue DX} y:E+{CheckValue DY}))%pour translater la road
  112.              []realitem(kind:A p1:pt(x:B y:C) p2:pt(x:D y:E) p3:pt(x:F y:G) p4:pt(x:H y:I))
  113.              then realitem(kind:A
  114.                    p1:pt(x:B+{CheckValue DX} y:C+{CheckValue DY})
  115.                    p2:pt(x:D+{CheckValue DX} y:E+{CheckValue DY})
  116.                    p3:pt(x:F+{CheckValue DX} y:G+{CheckValue DY})
  117.                    p4:pt(x:H+{CheckValue DX} y:I+{CheckValue DY}))%pour translater water et building
  118.              else nil
  119.              end
  120.           end
  121.          
  122.           fun {Traduction L F}%fonction prend en arg une liste contenant une prim et sort une fct prenant le temps en arg qui affiche un mapitem
  123.              case L of nil then fun{$ Time} F end
  124.              []translate(dx:DX dy:DY 1:New)|T then {Traduction T {Translate F DX DY}}
  125.              []rotate(angle:A 1:New)|T then {Traduction T {Rotate F A}}
  126.              []scale(rx:A ry:B 1:New)|T then {Traduction T {Scale F A B}}
  127.              []primitive(kind:A)|T then {Traduction T {Affiche L.1}}
  128.              end
  129.           end
  130.    
  131.  
  132.           fun{Affiche A}
  133.              local P1 P2 P3 P4 in
  134.             P1=pt(x:0.0 y:0.0)
  135.             P2=pt(x:0.0 y:1.0)
  136.             P3=pt(x:1.0 y:1.0)
  137.             P4=pt(x:1.0 y:0.0)
  138.             case A of nil then nil
  139.             [] primitive(kind:K) then
  140.                case K of building  then realitem(kind:building p1:P1 p2:P2 p3:P3 p4:P4)
  141.                [] water then realitem(kind:water p1:P1 p2:P2 p3:P3 p4:P4)
  142.                else realitem(kind:road p1:P1 p2:P4)
  143.                end
  144.             end
  145.              end
  146.           end
  147.  
  148.           L= {Inverse {FlattenList {Liste Map.ru  nil nil}} nil}
  149.           {Take L nil nil}       
  150.  
  151.            end
  152.         end
  153.         ListeReal={Runiverse Map}
  154.      end
  155. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  156.      %%POKEUNIVERSE%%
  157.      local Puniverse in
  158.         fun {Puniverse L}
  159.            local Liste FlattenList Affiche  Traduction Inverse Take Formula L in
  160.           fun {Traduction L F}%fonction prend en arg une liste contenant une prim et sort une fct prenant le temps en arg qui affiche un mapitem
  161.              case L of nil then nil
  162.              []translate(dx:DX dy:DY 1:New)|T then
  163.             local Translate in
  164.                fun{Translate Z Time DX DY}
  165.                   fun{$ Time}
  166.                  case {Z Time}
  167.                  of pokeitem(kind:A position:B) then pokeitem(kind:A position: pt(x:{Formula plus(B DX) Time} y:{Formula plus(B DY) Time}))%pour deplacer le pokeitem
  168.                  end
  169.                   end|{Translate T Time DX DY}
  170.                end
  171.                {Traduction T Translate}
  172.             end
  173.              []primitive(kind:A)|T then  fun{$ Time} {Affiche L.1} end|nil
  174.              end
  175.           end
  176.          
  177.      
  178.              
  179.           fun{Affiche A}
  180.              case A
  181.              of nil then nil
  182.              [] primitive(kind:K) then
  183.             case K
  184.             of pokemon then pokeitem(kind:pokemon position:pt(x:0.0 y:0.0))  
  185.             [] arena then pokeitem(kind:arena position:pt(x:0.0 y:0.0))
  186.             else pokeitem(kind:pokestop position:pt(x:0.0 y:0.0))
  187.             end
  188.              end
  189.           end
  190.           fun {Take L Acc Acc2}%%Sors la premiere liste contenant une primitive et ses deformations associees.
  191.              case L of nil then Acc2
  192.              []primitive(kind:K)|T then {Take T nil {Traduction primitive(kind:K)|Acc nil}|Acc2}
  193.              []H|T then {Take T H|Acc Acc2}
  194.              end
  195.           end
  196.          
  197.           fun {Formula Value Time}
  198.              if {Float.is Value} then Value
  199.              else
  200.             case Value
  201.             of time then Time
  202.             []plus(X Y) then {Formula X Time}+{Formula Y Time}
  203.             []minus(X Y) then{Formula X Time}-{Formula Y Time}
  204.             []mult(X Y) then{Formula X Time}*{Formula Y Time}
  205.             []'div'(X Y) then {Formula X Time}/{Formula Y Time}
  206.             []sin(X) then {Float.sin {Formula X Time}}
  207.             []cos(X) then {Float.cos {Formula X Time}}
  208.             []tan(X) then {Float.tan {Formula X Time}}
  209.             []exp(X) then {Float.exp {Formula X Time}}
  210.             []log(X) then {Float.log {Formula X Time}}
  211.             []neg(X) then {Float.neg {Formula X Time}}
  212.             else 0.0
  213.             end
  214.              end
  215.           end
  216.           fun {FlattenList L}
  217.              case L
  218.              of nil then nil
  219.              [] nil|T then {FlattenList T}
  220.              [](H1|T1)|T then {FlattenList H1|T1|T}
  221.              [] X|T then X|{FlattenList T}
  222.              else L
  223.              end
  224.           end
  225.           fun{Inverse L Acc}%%retourne une liste inversee.
  226.              case L of nil then Acc
  227.              []H|T then {Inverse T H|Acc}
  228.              end
  229.           end
  230.           fun {Liste L Acc Acc2}
  231.              case L
  232.              of nil then Acc2
  233.              []H|T then case H
  234.                 of translate(dx:DX dy:DY 1:N) then {Liste N H|Acc Acc2}|{Liste T Acc Acc2}
  235.                 [] primitive(kind:A) then [H|Acc]|Acc2|{Liste T Acc Acc2}
  236.                 end
  237.              end         
  238.           end
  239.           L={Inverse {FlattenList {Liste Map.pu nil nil}} nil}
  240.           {FlattenList {Take L nil nil}}
  241.            end
  242.         end
  243.         ListePoke={Puniverse Map}
  244.      end
  245.      fun{Append L1 L2}
  246.         case L1
  247.         of nil then L2
  248.         [] H|T then H|{Append T L2}
  249.         end
  250.        
  251.      end
  252.      
  253.      local VI in
  254.         proc{VI L}
  255.            case L
  256.           of nil then {Browse nil}
  257.            [] H|T then {Browse {H 0.0}} {VI T}
  258.            end
  259.         end
  260.         {VI ListePoke}
  261.      end
  262.      
  263.  
  264.      {Append ListeReal ListePoke}
  265.       end
  266.      
  267.    end
  268.  
  269.  
  270.    fun{CheckMap Map}
  271.       local IsRU IsPU IsRPOI CheckValue IsPPOI Formula in
  272.  
  273.      fun{IsRU A}
  274.         case A of nil then true
  275.         []translate(dx:X dy:Y 1:Z)|T then if {IsRU Z} andthen {IsRU T} andthen {CheckValue X} andthen {CheckValue Y} then true
  276.                           else false
  277.                           end
  278.          
  279.         []rotate(angle:A 1:B)|T then if {IsRU B} andthen {IsRU T} andthen {CheckValue A} then true
  280.                      else false
  281.                      end
  282.         []scale(rx:A ry:B 1:C)|T then if {IsRU C} andthen {IsRU T} then true
  283.                       else false
  284.                       end
  285.         []primitive(kind:A)|T then if {IsRU T} andthen {IsRPOI A} then true
  286.                        else false
  287.                        end
  288.         []nil|T then {IsRU T}
  289.         else false
  290.         end
  291.      end
  292.      fun {IsRPOI A}
  293.         case A of road then true
  294.         []building then true
  295.         []water then true
  296.         else false
  297.         end
  298.      end
  299.      fun {CheckValue Value}
  300.         if {Float.is Value}==true then Value
  301.         else
  302.            case Value
  303.            of plus(X Y) then {CheckValue X}+{CheckValue Y}
  304.            []minus(X Y) then {CheckValue X}-{CheckValue Y}
  305.            []mult(X Y) then {CheckValue X}*{CheckValue Y}
  306.            []'div'(X Y) then {CheckValue X}/{CheckValue Y}
  307.            []sin(X) then {Float.sin {CheckValue X}}
  308.            []cos(X) then {Float.cos {CheckValue X}}
  309.            []tan(X) then {Float.tan {CheckValue X}}
  310.            []exp(X) then {Float.exp {CheckValue X}}
  311.            []log(X) then {Float.log {CheckValue X}}
  312.            []neg(X) then ~{CheckValue X}
  313.            end
  314.         end
  315.      end
  316.  
  317.      fun {IsPU X}
  318.         case X of nil then true
  319.         []primitive(kind:A)|T then if {IsPPOI A} andthen {IsPU T} then true
  320.                        else false
  321.                        end
  322.         []translate(dx:X dy:Y 1:Z)|T then if {IsPU T} andthen {IsPU Z} andthen {Formula X} andthen {Formula Y} then true
  323.                           else false
  324.                           end
  325.         []nil|T then {IsPU T}
  326.         end
  327.      end
  328.      
  329.  
  330.      fun {Formula Value}
  331.         if {Float.is Value}==true then true
  332.         else
  333.            case Value
  334.            of time then true
  335.            []plus(X Y) then {Formula X}+{Formula Y}
  336.            []minus(X Y) then{Formula X}-{Formula Y}
  337.            []mult(X Y) then{Formula X}*{Formula Y}
  338.            []'div'(X Y) then {Formula X}/{Formula Y}
  339.            []sin(X) then {Float.sin {Formula X }}
  340.            []cos(X) then {Float.cos {Formula X }}
  341.            []tan(X) then {Float.tan {Formula X }}
  342.            []exp(X) then {Float.exp {Formula X }}
  343.            []log(X) then {Float.log {Formula X }}
  344.            []neg(X) then {Float.neg {Formula X }}
  345.            else false
  346.            end
  347.         end
  348.      end
  349.      fun {IsPPOI X}
  350.         case X of pokemon then true
  351.         []pokestop then true
  352.         []arena then true
  353.         else false
  354.         end
  355.      end
  356.  
  357.      case Map of nil then false
  358.      []map(ru:A pu:B) then if {IsRU A} andthen {IsPU B} then true
  359.                    else false
  360.                    end
  361.      else false
  362.      end
  363.       end
  364.  
  365.    end
  366.    
  367.    {Projet.run MyFunction Map MaxTime Extensions CheckMap}
  368. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement