Island Wari game written in Compojure

2 views
Skip to first unread message

Eric Lavigne

unread,
Dec 28, 2009, 12:30:38 AM12/28/09
to Compojure
I wrote an Island Wari web application this afternoon for a speed
programming competition. This should be a fun example for anyone who
is starting to learn Compojure right now.


Contest description:
http://www.codetown.us/group/contesttown/forum/topics/wari-contest-1

Code:
http://github.com/ericlavigne/island-wari/

Running application:
http://ericlavigne.net:8054/

James Reeves

unread,
Dec 28, 2009, 5:57:02 AM12/28/09
to Compojure
I took a look through the source, and it looks pretty good :)

The only suggestion I have is that compojure.html automatically
expands seqs, so:

[:span '(a b c)]

Is equivalent to:

[:span 'a 'b 'c]

This means you can use functions like 'map' in a more concise fashion:

[:tr (map #(vector :td %) (interpose horiz (repeat 7 small)))]

Or perhaps using a for:

[:tr (for [x (interpose horiz (repeat 7 small))] [:td x])]

- James

Eric Lavigne

unread,
Dec 28, 2009, 9:07:51 AM12/28/09
to comp...@googlegroups.com
Thanks, James. I simplified the rendering as you suggested.

The part that bothered me most was my routes definition, specifically:

(GET "/:whosturn/:computerplays/:a/:b/:c/:d/:e/:f/:g/:h/:i/:j/:k/:l/:m/:n"
(let [turn (Integer/parseInt (params :whosturn))
board (map #(Integer/parseInt (params %))
[:a :b :c :d :e :f :g
:h :i :j :k :l :m :n])]
...

I would have wanted to specify names for the first two params, then
indicate that there were 14 other params that should be put in a list.
My approach of typing out 14 letters would not have worked so well for
a larger game board.

> --
>
> You received this message because you are subscribed to the Google Groups "Compojure" group.
> To post to this group, send email to comp...@googlegroups.com.
> To unsubscribe from this group, send email to compojure+...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/compojure?hl=en.
>
>
>

James Reeves

unread,
Dec 28, 2009, 9:44:01 AM12/28/09
to Compojure
Well, you could rewrite it as:

(GET
"/:whosturn/:computerplays/:x/:x/:x/:x/:x/:x/:x/:x/:x/:x/:x/:x/:x/:x"


(let [turn (Integer/parseInt (params :whosturn))

board (map #(Integer/parseInt %) (params :x))]
...))

If a Compojure route contains more than one parameter with the same
name, it collects the results in a vector.

- James

On Dec 28, 2:07 pm, Eric Lavigne <lavigne.e...@gmail.com> wrote:
> Thanks, James. I simplified the rendering as you suggested.
>
> The part that bothered me most was my routes definition, specifically:
>
>   (GET "/:whosturn/:computerplays/:a/:b/:c/:d/:e/:f/:g/:h/:i/:j/:k/:l/:m/:n"
>        (let [turn (Integer/parseInt (params :whosturn))
>              board (map #(Integer/parseInt (params %))
>                                   [:a :b :c :d :e :f :g
>                                    :h :i :j :k :l :m :n])]
>   ...
>
> I would have wanted to specify names for the first two params, then
> indicate that there were 14 other params that should be put in a list.
> My approach of typing out 14 letters would not have worked so well for
> a larger game board.
>
> On Mon, Dec 28, 2009 at 5:57 AM, James Reeves
>

Reply all
Reply to author
Forward
0 new messages