Skip to content

Instantly share code, notes, and snippets.

@deque-blog
Last active March 8, 2017 23:36
Show Gist options
  • Save deque-blog/8e7f793dcb444284c901d1591e77ddc1 to your computer and use it in GitHub Desktop.
Save deque-blog/8e7f793dcb444284c901d1591e77ddc1 to your computer and use it in GitHub Desktop.
(defn- ^boolean block-jump? [owner]
(or (= owner :none) (= owner :wall)))
(defn- ^boolean jump-start? [looser owner]
(and looser (not= looser owner)))
(defn- ^boolean in-board? [x y]
(and (< -1 x board/width) (< -1 y board/height)))
(defn- seek-jump-source-toward
"Starting from the destination of a jump (a non-owned cell):
* Search for valid source for the jump
* Collect the jumped cells along the way"
[board [x-init y-init :as jump-destination] [dx dy]]
(loop [x (+ x-init dx)
y (+ y-init dy)
looser nil
taken []]
(if (in-board? x y)
(let [owner (aget board x y)]
(cond
(block-jump? owner) nil
(jump-start? looser owner) {:winner owner
:looser looser
:destination jump-destination
:taken taken}
:else (recur
(+ x dx)
(+ y dy)
owner
(conj taken [x y])))
))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment