mirror of
https://github.com/richardharrington/robotwar.git
synced 2024-06-26 01:29:33 +00:00
got compojure going, with a few sample routes
This commit is contained in:
parent
02f9659df7
commit
12ee2260c1
|
@ -5,6 +5,11 @@
|
|||
:url "http://www.eclipse.org/legal/epl-v10.html"}
|
||||
:dependencies [[org.clojure/clojure "1.5.1"]
|
||||
[org.clojure/core.match "0.2.0-rc5"]
|
||||
[clj-time "0.5.1"]]
|
||||
:profiles {:dev {:dependencies [[midje "1.5.1"]]}}
|
||||
[clj-time "0.5.1"]
|
||||
[ring/ring-json "0.2.0"]
|
||||
[compojure "1.1.5"]]
|
||||
:plugins [[lein-ring "0.8.5"]]
|
||||
:ring {:handler robotwar.handler/app}
|
||||
:profiles {:dev {:dependencies [[midje "1.5.1"]
|
||||
[ring-mock "0.1.5"]]}}
|
||||
:main robotwar.core)
|
||||
|
|
|
@ -11,7 +11,8 @@
|
|||
|
||||
|
||||
(defn progs []
|
||||
(vals test-programs/programs))
|
||||
(repeat 3 (:moving-to-spot test-programs/programs)))
|
||||
|
||||
(defn world []
|
||||
(world/init-world 256.0 256.0 (progs)))
|
||||
(defn worlds []
|
||||
|
|
21
src/robotwar/handler.clj
Normal file
21
src/robotwar/handler.clj
Normal file
|
@ -0,0 +1,21 @@
|
|||
(ns robotwar.handler
|
||||
(:use compojure.core)
|
||||
(:require [compojure.handler :as handler]
|
||||
[ring.middleware.json :as middleware]
|
||||
[ring.util.response :as response]
|
||||
[compojure.route :as route]
|
||||
[robotwar.test-programs :as test-programs]
|
||||
[robotwar.core :as core]))
|
||||
|
||||
(defroutes app-routes
|
||||
(GET "/" [] "Hello World, Welcome to Robotwar.")
|
||||
(GET "/json-test" [] (response/response {:foo 6 :bar 8}))
|
||||
(GET "/programs" [] (response/response test-programs/programs))
|
||||
(GET "/simulations" [] (response/response (take 1 (core/simulation-rounds))))
|
||||
(route/resources "/")
|
||||
(route/not-found "Not Found"))
|
||||
|
||||
(def app
|
||||
(-> (handler/site app-routes)
|
||||
(middleware/wrap-json-response)
|
||||
(middleware/wrap-json-body)))
|
|
@ -47,18 +47,18 @@
|
|||
RANDOM TO B ; Store a random Y-coordinate in the arena.
|
||||
|
||||
MOVE
|
||||
IF A # X GOSUB MOVEX ; If we're moving in the X direction, recalibrate our SPEEDX.
|
||||
TO N ; N is for no-op. (This accounts for the lack of an ELSE clause).
|
||||
IF B # Y GOSUB MOVEY ; If we're moving in the Y direction, recalibrate our SPEEDY.
|
||||
IF A # X GOSUB MOVEX ; If we're moving in the X direction, recalibrate SPEEDX.
|
||||
TO N ; N is for no-op. (needed because there's no ELSE command).
|
||||
IF B # Y GOSUB MOVEY ; If we're moving in the Y direction, recalibrate SPEEDY.
|
||||
IF A = X GOTO LOOP ; A = X and B = Y, so we've stopped moving, so start over.
|
||||
GOTO MOVE ; Continue to move.
|
||||
|
||||
MOVEX
|
||||
A - X TO SPEEDX ; New speed: take distance from destination in meters and use
|
||||
A - X TO SPEEDX ; Take distance from destination in meters and use
|
||||
; it to set SPEEDX, which is measured in decimeters/second.
|
||||
ENDSUB
|
||||
|
||||
MOVEY
|
||||
B - Y TO SPEEDY ; New speed: take distance from destination in meters and use
|
||||
B - Y TO SPEEDY ; Take distance from destination in meters and use
|
||||
; it to set SPEEDY, which is measured in decimeters/second.
|
||||
ENDSUB "})
|
||||
|
|
Loading…
Reference in New Issue
Block a user