Skip to content

Instantly share code, notes, and snippets.

@fversnel fversnel/baba.clj
Last active Apr 2, 2019

Embed
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
#{:word/is})
(s/def ::object
#{:word/you :word/push :word/stop :word/win})
(s/def ::sentence
(s/cat
:subject ::subject
:verb ::verb
:object ::object))
(s/def ::game-object
#{:baba :wall :flag :grass})
(s/def ::cell
(s/or
:word
(s/or
:subject ::subject
:verb ::verb
:object ::object)
:empty #{:empty}
:game-object ::game-object))
(s/def ::row
(s/*
(s/alt
:sentence ::sentence
:cell ::cell)))
(s/def ::level
(s/coll-of ::row))
(defn rules [level]
(let [filter-sentences
(filter
(fn [[type & _]]
(= type :sentence)))
map-rules (map second)]
(into
#{}
(comp cat filter-sentences map-rules)
level)))
(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.