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" :license {:name "Eclipse Public License"
:url "http://www.eclipse.org/legal/epl-v10.html"} :url "http://www.eclipse.org/legal/epl-v10.html"}
:min-lein-version "2.0.0" :min-lein-version "2.0.0"
:dependencies [[org.clojure/clojure "1.5.1"] :dependencies [[org.clojure/clojure "1.11.1"]
[clj-time "0.5.1"] [clj-time "0.15.2"]
[ring/ring-json "0.3.1"] [ring/ring-json "0.5.1"]
[ring/ring-core "1.9.5"]] [ring/ring-core "1.9.5"]
:plugins [[lein-ring "0.12.5"]] [compojure "1.7.0"]]
:plugins [[lein-ring "0.12.6"]]
:ring {:handler robotwar.handler/app} :ring {:handler robotwar.handler/app}
:profiles {:dev {:dependencies [[midje "1.5.1"] :profiles {:dev {:dependencies [[midje "1.10.5"]
[ring-mock "0.1.5"]]}} [ring-mock "0.1.5"]]}}
:main robotwar.core) :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]] [ring.util.response :refer [response not-found]]
[robotwar.source-programs :as source-programs] [robotwar.source-programs :as source-programs]
[robotwar.world :as world] [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 (def game-info {:ROBOT-RADIUS ROBOT-RADIUS
:ROBOT-RANGE-X ROBOT-RANGE-X :ROBOT-RANGE-X ROBOT-RANGE-X
@ -18,7 +20,7 @@
"takes a string parameter from the browser and returns a sequence "takes a string parameter from the browser and returns a sequence
of program keys" of program keys"
[programs-str] [programs-str]
(map keyword (split programs-str #"[,\s]\s*"))) (map keyword (split programs-str #"[,\s]+")))
(defn get-programs (defn get-programs
"gets a sequence of five programs from the source-code repository." "gets a sequence of five programs from the source-code repository."
@ -54,37 +56,54 @@
(def games-store (atom {:next-id 0 (def games-store (atom {:next-id 0
:games {}})) :games {}}))
(defn consistently-typed-re-matches [re s] (defroutes my-routes
(when-let [match (re-matches re s)] (GET "/worlds/:id/:n" [id n]
(if (string? match) [match] match))) (response
(take-drop-send
games-store
(Integer/parseInt id)
(Integer/parseInt n))))
(defn handler [{:keys [uri query-params request-method] :as request}] (GET "/program-names" []
(let [route (fn [acceptable-request-method re action] (response
(when (= request-method acceptable-request-method) {:names (map name (keys source-programs/programs))}))
(when-let [[_ & url-params] (consistently-typed-re-matches re uri)]
(apply action url-params))))] (GET "/init" {{programs "programs"} :params}
(or (println "in init")
(route :get #"\/worlds\/(\d+)\/(\d+)" (println (str programs))
(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) (swap! games-store add-game programs)
(response {:id next-id (response {:id (:next-id @games-store)
:game-info game-info})))) :game-info game-info})))
(not-found "Not Found"))))
;
;(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 (def app
(-> handler (-> my-routes
(wrap-file "public") (wrap-file "public")
(wrap-json-response) (wrap-json-response)
(wrap-json-body) (wrap-json-body)

View File

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