Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (fn [player board]
- (let [column
- (fn [[x y]]
- (for [newy [0 1 2]]
- [x newy]))
- row
- (fn [[x y]]
- (for [newx [0 1 2]]
- [newx y]))
- diags
- (fn [[x y :as pos]]
- (let [up [[0 2] [1 1] [2 0]]
- down [[0 0] [1 1] [2 2]]]
- (filter #(some (partial = pos) %) [up down])))
- triples
- (fn [pos]
- (into (diags pos) [(row pos) (column pos)]))
- winning?
- (fn [board triple]
- (every? #(= player (get-in board %)) triple))
- empties
- (fn [board]
- (for [x [0 1 2]
- y [0 1 2]
- :when (= :e (get-in board [x y]))]
- [x y]))
- ]
- (apply hash-set
- (filter
- (fn [pos]
- (let [new-board (assoc-in board pos player)
- lines (triples pos)]
- (some #(winning? new-board %) lines)))
- (empties board)))))
Add Comment
Please, Sign In to add comment