<commit_before>(ns quoridor.board
  (:require [clojure.string :as s]))

(def ^{:private true} horiz-side "+---+")
(def ^{:private true} blank-column "   ")
(def ^{:private true} eight (partial repeat 8))

(defn- beside
  [left right]
  (let [left-lines (s/split-lines left)
        right-lines (s/split-lines right)]
    (s/join "\n" (map #(str %1 %2) (concat left-lines (repeat "")) right-lines))))

(defn- above
  [line1 line2]
  (str line1 "\n" line2))

(defn- square
  [state coords]
  (let [is-black-pos (= (state :black) coords)
        is-white-pos (= (state :white) coords)]
    (s/join "\n" [horiz-side
                  (cond is-black-pos "| B |"
                        is-white-pos "| W |"
                        :else        "|   |")
                  horiz-side])))

(defn- column
  [state coords]
  (reduce above (repeat 3 blank-column)))

(defn- row-separator
  [state n]
  (s/join (cons "     " (flatten (repeat 7 [blank-column "     "])))))

(defn char-range
  [start end]
  (set (map char (range (int start) (+ (int end) 1)))))

(defn- row
  [state n]
  (reduce beside (flatten (for [col (char-range \a \h)
                                :let [coords (str col n)]]
                            [(square state coords) (column state coords)]))))

(defn- column-headers
  []
  (s/join (cons blank-column (map #(str "  " % "  " blank-column)
                                    (char-range \A \H)))))

(defn- row-label
  [n]
  (let [padding (int (/ (count blank-column) 2))
        padding-str (s/join (repeat padding " "))]
    (above (above blank-column (s/join [padding-str n padding-str])) blank-column)))

(defn render
  ([] (render { :black "e1" :white "e8" :current "black" :walls #{} }))
  ([state]
   (let [rows (reduce above (for [n (range 8 0 -1)]
                              (above (beside (row-label n) (row state n))
                                     (row-separator state n))))]
     (above (column-headers) rows))))<commit_msg>render horizontal walls<commit_after>(ns quoridor.board
  (:require [clojure.string :as s]))

(def ^{:private true} horiz-side "+---+")
(def ^{:private true} blank-column "   ")
(def ^{:private true} eight (partial repeat 8))

(defn- beside
  [left right]
  (let [left-lines (s/split-lines left)
        right-lines (s/split-lines right)]
    (s/join "\n" (map #(str %1 %2) (concat left-lines (repeat "")) right-lines))))

(defn- above
  [line1 line2]
  (str line1 "\n" line2))

(defn- square
  [state coords]
  (let [is-black-pos (= (state :black) coords)
        is-white-pos (= (state :white) coords)]
    (s/join "\n" [horiz-side
                  (cond is-black-pos "| B |"
                        is-white-pos "| W |"
                        :else        "|   |")
                  horiz-side])))

(defn- column
  [state coords]
  (reduce above (repeat 3 blank-column)))

(defn- horizontal-wall-at?
  [state pos]
  (some (fn [x] (or (= (subs x 0 2) pos)
                    (= (subs x 2 4) pos)))
        (state :walls)))

(defn char-range
  [start end]
  (set (map char (range (int start) (+ (int end) 1)))))

(defn- row-separator
  [state n]
  (beside blank-column
          (s/join blank-column (for [c (char-range \a \h)]
                                 (if (horizontal-wall-at? state (str c n))
                                   "*****"
                                   "     ")))))

(defn- row
  [state n]
  (reduce beside (flatten (for [col (char-range \a \h)
                                :let [coords (str col n)]]
                            [(square state coords) (column state coords)]))))

(defn- column-headers
  []
  (s/join (cons blank-column (map #(str "  " % "  " blank-column)
                                    (char-range \A \H)))))

(defn- row-label
  [n]
  (let [padding (int (/ (count blank-column) 2))
        padding-str (s/join (repeat padding " "))]
    (above (above blank-column (s/join [padding-str n padding-str])) blank-column)))

(defn render
  ([] (render { :black "e1" :white "e8" :current "black" :walls #{} }))
  ([state]
   (let [rows (reduce above (for [n (range 8 0 -1)]
                              (above (beside (row-label n) (row state n))
                                     (row-separator state (- n 1)))))]
     (above (column-headers) rows))))
{'fraction_non_alphanumeric': 0.17611241217798596, 'fraction_numerical': 0.008430913348946136, 'mean_word_length': 1.8530394121576486, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 7, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '775114', 'n_tokens_mistral': 1513, 'n_tokens_neox': 1440, 'n_words': 419}