Skip to content

Instantly share code, notes, and snippets.



Last active Apr 2, 2019
What would you like to do?
Baba is you spec
(ns babaisyou.spec
(:require [clojure.spec.alpha :as s]))
(s/def ::subject
#{:word/baba :word/wall :word/flag :word/grass})
(s/def ::verb
(s/def ::object
#{:word/you :word/push :word/stop :word/win})
(s/def ::sentence
:subject ::subject
:verb ::verb
:object ::object))
(s/def ::game-object
#{:baba :wall :flag :grass})
(s/def ::cell
:subject ::subject
:verb ::verb
:object ::object)
:empty #{:empty}
:game-object ::game-object))
(s/def ::row
:sentence ::sentence
:cell ::cell)))
(s/def ::level
(s/coll-of ::row))
(defn rules [level]
(let [filter-sentences
(fn [[type & _]]
(= type :sentence)))
map-rules (map second)]
(comp cat filter-sentences map-rules)
(def example-level
[[:word/flag :empty :word/baba :word/is :word/you :empty :wall]
[:wall :empty :empty :baba :empty :empty :wall]
[:wall :wall :wall :wall :wall :empty :wall]
[:empty :word/flag :word/is :word/win :grass :grass :empty]])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.