Commit 2192df06 authored by Davide Taviani's avatar Davide Taviani

different definition of correctness

parent ec5c3af3
......@@ -48,10 +48,66 @@
(get correct-positions (:neighbors cell))
(:status cell)))
(defn correct? [board]
(defn old-correct? [board]
(every? correct-position? (:cells board)))
;;;;; switching to a different definition of correctness
(defn points-to [{:keys [tile status]}]
(case tile
:0-tile #{}
:1-tile (case status
0 #{:N}
1 #{:E}
2 #{:S}
3 #{:W})
:2-tile-I (case status
0 #{:N :S}
1 #{:E :W}
2 #{:N :S}
3 #{:E :W})
:2-tile-L (case status
0 #{:N :E}
1 #{:E :S}
2 #{:S :W}
3 #{:N :W})
:3-tile (case status
0 #{:N :E :W}
1 #{:N :S :E}
2 #{:S :E :W}
3 #{:N :S :W})
:4-tile #{:N :S :W :E}))
(defn pointed-back? [{:keys [index] :as cell} {:keys [size] :as board}]
(let [connected-directions (points-to cell)]
(every? (fn [dir]
(let [i (quot index size)
j (rem index size)]
(case dir
:N (and (not= i 0)
(contains? (points-to (nth (:cells board)
(- index size)))
:S))
:S (and (not= i (dec size))
(contains? (points-to (nth (:cells board)
(+ index size)))
:N))
:W (and (not= j 0)
(contains? (points-to (nth (:cells board)
(- index 1)))
:E))
:E (and (not= j (dec size))
(contains? (points-to (nth (:cells board)
(+ index 1)))
:W)))))
connected-directions)))
(defn correct? [board]
(every? #(pointed-back? % board)
(:cells board)))
;;;;;;;;;;;;;;;;;
(def ideal-board-composition
......@@ -96,20 +152,24 @@
west? (conj :W)
east? (conj :E))))
(defn create-board [bl]
{:size (:size bl)
:cells (->> (range (Math/pow (:size bl) 2))
(defn create-board [{:keys [size] :as bl}]
{:size size
:cells (->> (range (Math/pow size 2))
(map (partial connected-neighbors bl))
(mapv (fn [n-set]
{:value (if (empty? n-set) 0 1)
:neighbors n-set
:tile (tile n-set)
:status (rand-int 4)})))})
(map-indexed (fn [idx n-set]
{:value (if (empty? n-set) 0 1)
:i (quot idx size)
:j (rem idx size)
:index idx
:neighbors n-set
:tile (tile n-set)
:status (rand-int 4)}))
(vec))})
(defn random-board [size]
(create-board {:size size
:row-links (repeatedly size #(rand-int 2))
(create-board {:size size
:row-links (repeatedly size #(rand-int 2))
:column-links (repeatedly size #(rand-int 2))}))
(comment
......
......@@ -57,10 +57,11 @@
(b/scramble state))
(defmethod handle-command :init-game
[state [_cmd data]]
[_state [_cmd data]]
(->> data
(b/create-board)))
(defn notification []
(if (and @game-state
(b/correct? @game-state))
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment