Generating a chess state with clojure.spec

I want to hear some tips on how to generating a chess state with clojure.spec.

It’s easy to define the constraints on data shapes. However I don’t know to express some limitations for a chess game state and how to do generating.

After thinking for a while, I think is useless to try to validate the game state or try to do generating based on limitations(like one player can’t have 3 horses).

I think I should generate a series of play record, however knowing current board state is necessary for generating play record. Because I have to know the positions of all chess. how can I get a state-like spec generator? Is it a good idea to use spec on this?

Have you decided on a data model for your chess game? If you post it that would make answering your question a lot easier.

yes, just a little.

(s/def ::chess
  #{:king :guard :minister :knignt :rock :cannon :pawn})

(s/def ::player
  #{:red :black})

(s/def ::row (s/int-in 1 10))

(s/def ::col (s/int-in 1 11))

(s/def ::pos
  (s/tuple ::row ::col))

(s/def ::from ::pos)

(s/def ::to ::pos)

(s/def ::used-time pos-int?)

(s/def ::record
  (s/keys :req-un [::round ::player ::chess ::from ::to ::used-time]))

(s/def ::play-status
  #{:normal :check :checkmate :draw})

(s/def ::history
  (s/coll-of ::record))

(s/def ::round int?)

(s/def ::player-chess
  (s/tuple ::player ::chess))

(s/def ::board
  (s/map-of ::pos ::player-chess))

(s/def ::init-board ::board)

(s/def ::player-state
  (s/keys :req-un [::used-time]))

(s/def ::player-states
  (s/map-of ::player ::player-state))

(s/def ::game-opts
  (s/keys :req-un [::total-time ::init-board]))

(s/def ::game-state
  (s/keys :req-un [::board ::player-states ::round ::game-status]))

(s/def ::game
  (s/keys :req-un [::game-opts ::game-state]))