<commit_before>(ns chessground.data
  "Representation and manipulation of the application data"
  (:require [chessground.common :as common :refer [pp]]
            [chessground.chess :as chess]
            [chessground.premove :as premove]))

(def defaults
  "Default state, overridable by user configuration"
  {:chess (chess/make "start") ; representation of a chess game
   :orientation "white"
   :turn-color "white" ; turn to play. white | black
   :check nil; square currently in check "a2" | nil
   :last-move nil ; squares part of the last move ["c3" "c4"] | nil
   :selected nil ; square selected by the user "a1" | nil
   :movable {:free? true ; all moves are valid - board editor
             :color "both" ; color that can move. white | black | both | nil
             :dests nil ; valid moves. {"a2" ["a3" "a4"] "b1" ["a3" "c3"]} | nil
             :drop-off "revert" ; when a piece is dropped outside the board. "revert" | "trash"
             ; :drag-center? true ; whether to center the piece under the cursor on drag start
             :events {:after (fn [orig dest chess] nil) ; called after the moves has been played
                      }}
   :premovable {:enabled? true ; allow premoves for color that can not move
                :current nil ; keys of the current saved premove ["e2" "e4"] | nil
                }})

(defn- callback [function & args]
  "Call asynchronously a user supplied callback function, if any"
  (when function
    (js/setTimeout #(apply function (map clj->js args)) 50)))

(defn with-fen [state fen] (assoc state :chess (chess/make (or fen "start"))))

(defn movable? [state orig]
  (when-let [piece (chess/get-piece (:chess state) orig)]
    (or (= (-> state :movable :color) "both")
        (= (-> state :movable :color)
           (:turn-color state)
           (:color piece)))))<commit_msg>Fix movable?<commit_after>(ns chessground.data
  "Representation and manipulation of the application data"
  (:require [chessground.common :as common :refer [pp]]
            [chessground.chess :as chess]
            [chessground.premove :as premove]))

(def defaults
  "Default state, overridable by user configuration"
  {:chess (chess/make "start") ; representation of a chess game
   :orientation "white"
   :turn-color "white" ; turn to play. white | black
   :check nil; square currently in check "a2" | nil
   :last-move nil ; squares part of the last move ["c3" "c4"] | nil
   :selected nil ; square selected by the user "a1" | nil
   :movable {:free? true ; all moves are valid - board editor
             :color "both" ; color that can move. white | black | both | nil
             :dests nil ; valid moves. {"a2" ["a3" "a4"] "b1" ["a3" "c3"]} | nil
             :drop-off "revert" ; when a piece is dropped outside the board. "revert" | "trash"
             ; :drag-center? true ; whether to center the piece under the cursor on drag start
             :events {:after (fn [orig dest chess] nil) ; called after the moves has been played
                      }}
   :premovable {:enabled? true ; allow premoves for color that can not move
                :current nil ; keys of the current saved premove ["e2" "e4"] | nil
                }})

(defn- callback [function & args]
  "Call asynchronously a user supplied callback function, if any"
  (when function
    (js/setTimeout #(apply function (map clj->js args)) 50)))

(defn with-fen [state fen] (assoc state :chess (chess/make (or fen "start"))))

(defn movable? [state orig]
  (when-let [piece (chess/get-piece (:chess state) orig)]
    (or (and
          (= (-> state :movable :color) "both")
          (= (:turn-color state) (:color piece)))
        (= (-> state :movable :color)
           (:turn-color state)
           (:color piece)))))
{'fraction_non_alphanumeric': 0.12553304904051174, 'fraction_numerical': 0.007462686567164179, 'mean_word_length': 2.6830225711481845, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '208639', 'n_tokens_mistral': 1166, 'n_tokens_neox': 1117, 'n_words': 445}