Changes between Version 38 and Version 39 of Clojure Client Tutorial


Ignore:
Timestamp:
Aug 8, 2011 11:25:08 AM (13 years ago)
Author:
kedwar10
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • Clojure Client Tutorial

    v38 v39  
    9595
    9696{{{
    97 client.core=> (run-ioquake "firstroom")                                                                                                     
     97client.core=> (run-ioquake "sat")                                                                                                     
    9898#<UNIXProcess java.lang.UNIXProcess@56c3cf>
    9999}}}
     
    237237}}}
    238238
    239 Say we want to define a function "scan-area" that takes two arguments (a quagent key and a radius) and returns a hash map of the positions of the items.
     239Notice that the room has a few items scattered around it, let's define a function "scan-area" that takes two arguments (a quagent key and a radius) and returns a hash map of the positions of the items.  The simplest implementation is to just use the basic radar op from protocol zero with a vector for an initial value and "conj" for the combination function. (Note the use of "pp" to pretty-print the previous result.)
     240
     241{{{
     242client.core=> (send-and-get :Bob :radar :now [8000] [] conj)
     243[("0" "player" "768.875366" "90.065201" "0.000000") ... (output-truncated)
     244client.core=> (pp)                                         
     245[("0" "player" "768.875366" "90.065201" "0.000000")
     246 ("2" "player" "32.000000" "-90.000000" "0.000000")
     247 ("72" "info_player_deathmatch" "32.000244" "-90.000000" "0.223811")
     248 ("74" "quagent_item_treasure" "572.168640" "20.462269" "0.901278")
     249 ("75" "quagent_item_gold" "375.085327" "56.309933" "1.374918")
     250 ("76" "quagent_item_gold" "1019.278626" "42.455196" "0.505915")
     251 ("77" "quagent_item_treasure" "697.711304" "63.434952" "0.739097")
     252 ("78" "quagent_item_gold" "905.141357" "8.130102" "0.569713")
     253 ("79" "info_player_deathmatch" "0.125000" "0.000000" "90.000000")]
     254nil
     255}}}
     256
     257
     258 
    240259
    241260----