Compare commits

...

6 Commits

Author SHA1 Message Date
Richard Harrington 5885ecc7b2 tmp not exactly working, but closer! 2022-08-01 10:40:11 -04:00
Richard Harrington 3768178133 start restoring compojure (not entirely working yet) 2022-08-01 10:19:24 -04:00
Richard Harrington 23f18abdab add favicon placeholder 2022-08-01 10:13:09 -04:00
Richard Harrington 3edcb51469 updated many deps 2022-07-30 15:52:42 -04:00
Richard Harrington 3467d22a04 add compojure 2022-07-30 15:49:27 -04:00
Richard Harrington 8d4e942435 fix indentation in source_programs.clj 2022-07-30 15:49:15 -04:00
4 changed files with 88 additions and 70 deletions

View File

@ -4,12 +4,13 @@
:license {:name "Eclipse Public License"
:url "http://www.eclipse.org/legal/epl-v10.html"}
:min-lein-version "2.0.0"
:dependencies [[org.clojure/clojure "1.5.1"]
[clj-time "0.5.1"]
[ring/ring-json "0.3.1"]
[ring/ring-core "1.9.5"]]
:plugins [[lein-ring "0.12.5"]]
:dependencies [[org.clojure/clojure "1.11.1"]
[clj-time "0.15.2"]
[ring/ring-json "0.5.1"]
[ring/ring-core "1.9.5"]
[compojure "1.7.0"]]
:plugins [[lein-ring "0.12.6"]]
:ring {:handler robotwar.handler/app}
:profiles {:dev {:dependencies [[midje "1.5.1"]
:profiles {:dev {:dependencies [[midje "1.10.5"]
[ring-mock "0.1.5"]]}}
:main robotwar.core)

BIN
public/favicon.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 98 KiB

View File

@ -7,7 +7,9 @@
[ring.util.response :refer [response not-found]]
[robotwar.source-programs :as source-programs]
[robotwar.world :as world]
[robotwar.browser :as browser]))
[robotwar.browser :as browser]
[compojure.core :refer :all]
[compojure.route :as route]))
(def game-info {:ROBOT-RADIUS ROBOT-RADIUS
:ROBOT-RANGE-X ROBOT-RANGE-X
@ -18,7 +20,7 @@
"takes a string parameter from the browser and returns a sequence
of program keys"
[programs-str]
(map keyword (split programs-str #"[,\s]\s*")))
(map keyword (split programs-str #"[,\s]+")))
(defn get-programs
"gets a sequence of five programs from the source-code repository."
@ -54,37 +56,54 @@
(def games-store (atom {:next-id 0
:games {}}))
(defn consistently-typed-re-matches [re s]
(when-let [match (re-matches re s)]
(if (string? match) [match] match)))
(defroutes my-routes
(GET "/worlds/:id/:n" [id n]
(response
(take-drop-send
games-store
(Integer/parseInt id)
(Integer/parseInt n))))
(defn handler [{:keys [uri query-params request-method] :as request}]
(let [route (fn [acceptable-request-method re action]
(when (= request-method acceptable-request-method)
(when-let [[_ & url-params] (consistently-typed-re-matches re uri)]
(apply action url-params))))]
(or
(route :get #"\/worlds\/(\d+)\/(\d+)"
(fn [id n]
(response (take-drop-send
games-store
(Integer/parseInt id)
(Integer/parseInt n)))))
(route :get #"\/program-names"
(fn []
(response
{:names (map name (keys source-programs/programs))})))
(route :get #"\/init"
(fn []
(let [programs (query-params "programs")
next-id (:next-id @games-store)]
(GET "/program-names" []
(response
{:names (map name (keys source-programs/programs))}))
(GET "/init" {{programs "programs"} :params}
(println "in init")
(println (str programs))
(swap! games-store add-game programs)
(response {:id next-id
:game-info game-info}))))
(not-found "Not Found"))))
(response {:id (:next-id @games-store)
:game-info game-info})))
;
;(defn handler [{:keys [uri query-params request-method] :as request}]
; (let [route (fn [acceptable-request-method re action]
; (when (= request-method acceptable-request-method)
; (when-let [[_ & url-params] (consistently-typed-re-matches re uri)]
; (apply action url-params))))]
; (or
; (route :get #"\/worlds\/(\d+)\/(\d+)"
; (fn [id n]
; (response (take-drop-send
; games-store
; (Integer/parseInt id)
; (Integer/parseInt n)))))
; (route :get #"\/program-names"
; (fn []
; (response
; {:names (map name (keys source-programs/programs))})))
; (route :get #"\/init"
; (fn []
; (let [programs (query-params "programs")
; next-id (:next-id @games-store)]
; (swap! games-store add-game programs)
; (response {:id next-id
; :game-info game-info}))))
; (not-found "Not Found"))))
(def app
(-> handler
(-> my-routes
(wrap-file "public")
(wrap-json-response)
(wrap-json-body)

View File

@ -138,45 +138,43 @@
SHOOT
S TO SHOT
GOTO SHOOT
"
})
"})
(def dev-programs
(merge
programs
{
:multi-use
"
START
0 TO A
TEST
IF A > 2 GOTO START
GOSUB INCREMENT
GOTO TEST
100 TO A
INCREMENT
A + 1 TO A
ENDSUB
200 TO A
"
:multi-use
"
START
0 TO A
TEST
IF A > 2 GOTO START
GOSUB INCREMENT
GOTO TEST
100 TO A
INCREMENT
A + 1 TO A
ENDSUB
200 TO A
"
:index-data
; to test the INDEX/DATA pair of registers
"
300 TO A
1 TO INDEX
DATA TO B
"
:index-data
; to test the INDEX/DATA pair of registers
"
300 TO A
1 TO INDEX
DATA TO B
"
:random
; to test the RANDOM register
"
1000 TO RANDOM
RANDOM TO A
RANDOM TO A
RANDOM TO A
RANDOM TO A
RANDOM TO A
"
}))
:random
; to test the RANDOM register
"
1000 TO RANDOM
RANDOM TO A
RANDOM TO A
RANDOM TO A
RANDOM TO A
RANDOM TO A
"}))