Changes between Version 41 and Version 42 of Clojure Client Tutorial


Ignore:
Timestamp:
Aug 8, 2011 12:19:48 PM (13 years ago)
Author:
kedwar10
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • Clojure Client Tutorial

    v41 v42  
    335335 "player" ((768.875366 90.065201 0.0) (32.0 -90.0 0.0))}
    336336nil
    337 
    338 }}}
    339 
    340 
    341 
    342 
    343  
     337}}}
     338
     339The process of converting a sequence into doubles is so common that it has been included in the client as "seq->doubles".
     340
     341{{{
     342client.core=> (defn scan-area2 [quagent radius]
     343                (send-and-get quagent :radar :now [radius]
     344                              {}
     345                              (fn [prev [_ item-type & pos]]
     346                                (merge-with concat
     347                                            prev
     348                                            {item-type (list (seq->doubles pos))}))))
     349#'client.core/scan-area
     350client.core=> (scan-area :Bob 8000)
     351{"quagent_item_gold" ([375.085327 56.309933 1.374918] ... (output truncated)
     352client.core=> (pp)
     353{"quagent_item_gold"
     354 ([375.085327 56.309933 1.374918]
     355  [1019.278626 42.455196 0.505915]
     356  [905.141357 8.130102 0.569713]),
     357 "quagent_item_treasure"
     358 ([572.16864 20.462269 0.901278] [697.711304 63.434952 0.739097]),
     359 "info_player_deathmatch"
     360 ([32.000244 -90.0 0.223811] [0.125 0.0 90.0]),
     361 "player" ([768.875366 90.065201 0.0] [32.0 -90.0 0.0])}
     362nil
     363}}}
     364
     365You can now use the predefined "move" command to make the quagent walk to an item.
     366
     367{{{
     368client.core=> (apply (partial move :Bob) (take 2 (second (get (scan-area2 :Bob 8000) "quagent_item_gold"))))
     369[]
     370}}}
    344371
    345372----