<commit_before>(ns gobanbot.image
  (:require [dali.io :as svg]
            [clojure.string :as s]))

(def cell-size 100)
(def font-size (* cell-size 0.72))

(defn mv-to-xy [mv]
  (let [[a b] (s/lower-case mv)
        x (- (int a) 97)
        y (- (int b) 97)]
    [x y]))

(defn xy-to-circle [xy color]
  (let [style (if (= color "b") 
                {:fill :black} 
                {:stroke :black :fill :white :width 1})]
    [:circle style (vec (map #(-> % (* cell-size) (+ cell-size)) xy)) (* 0.45 cell-size)]))

(defn get-stones [moves]
  (map (fn [{:keys [mv color]}] 
         (xy-to-circle (mv-to-xy mv) color))
    moves))

(defn get-hlines [size]
  (map 
    (fn [i] [:line {:stroke :black :stroke-width 5} [i cell-size] [i (* cell-size size)]])  
    (range cell-size (-> size (+ 1) (* cell-size)) cell-size)))

(defn get-vlines [size]
  (map 
    (fn [i] [:line {:stroke :black :stroke-width 5} [cell-size i] [(* cell-size size) i]])  
    (range cell-size (-> size (+ 1) (* cell-size)) cell-size)))

(defn get-htext [size]
  (map
    (fn [i] [:text {:font-family "sans-serif" 
                    :font-size font-size 
                    :x (+ font-size (* i cell-size)) 
                    :y font-size}
             (-> i (+ 97) char str)])
    (range size)))

(defn get-vtext [size]
  (map
    (fn [i] [:text {:font-family "sans-serif" :font-size 72 :x 10 :y (+ 122 (* i cell-size))}  
             (-> i (+ 97) char str)])
    (range size)))

(defn get-goban [filename game]
  (let [f-n (str filename ".png")]
    (svg/render-png (vec (concat [:dali/page] 
                                 (get-hlines (:size game)) 
                                 (get-vlines (:size game))
                                 (get-htext (:size game))
                                 (get-vtext (:size game))
                                 (get-stones (:moves game))))
                    (str "resources/" f-n))
    f-n))
<commit_msg>star dots, last move<commit_after>(ns gobanbot.image
  (:require [dali.io :as svg]
            [clojure.string :as s]))

(def cell-size 100)
(def font-size (* cell-size 0.72))

(defn mv-to-xy [mv]
  (let [[a b] (s/lower-case mv)
        x (- (int a) 97)
        y (- (int b) 97)]
    [x y]))

(defn xy-to-circle [xy color]
  (let [style (if (= color "b") 
                {:fill :black} 
                {:stroke :black :fill :white :width 3})]
    [:circle style (vec (map #(-> % (* cell-size) (+ cell-size)) xy)) (* 0.45 cell-size)]))

(defn get-stones [moves]
  (map (fn [{:keys [mv color]}] 
         (xy-to-circle (mv-to-xy mv) color))
    moves))

(defn get-last-move [{:keys [mv color] :as move}]
  (if move
    (let [xy (mv-to-xy mv)
          style (case color 
                  "b" {:stroke :white :fill :black :width 3}
                  "w" {:stroke :black :fill :white :width 3})]
      [[:circle style 
               (vec (map #(-> % (* cell-size) (+ cell-size)) xy)) 
               (* 0.3 cell-size)]])))

(defn get-hlines [size]
  (map 
    (fn [i] [:line {:stroke :black :stroke-width 5} [i cell-size] [i (* cell-size size)]])  
    (range cell-size (-> size (+ 1) (* cell-size)) cell-size)))

(defn get-vlines [size]
  (map 
    (fn [i] [:line {:stroke :black :stroke-width 5} [cell-size i] [(* cell-size size) i]])  
    (range cell-size (-> size (+ 1) (* cell-size)) cell-size)))

(defn get-htext [size]
  (map
    (fn [i] [:text {:font-family "sans-serif" 
                    :font-size font-size 
                    :x (+ font-size (* i cell-size)) 
                    :y font-size}
             (-> i (+ 97) char str)])
    (range size)))

(defn get-stars [size]
  (map (fn [xy] [:circle {:fill :black} 
         (vec (map #(-> % (* cell-size) (+ cell-size)) xy)) 
         (* 0.1 cell-size)])
    (case size
      9 [[2 2] [2 6] [6 2] [6 6] [4 4]]
      13 [[2 2] [2 6] [2 10] [6 2] [6 6] [6 10] [10 2] [10 6] [10 10]]
      19 [[3 3] [3 9] [3 15] [9 3] [9 9] [9 15] [15 3] [15 9] [15 15]])))

(defn get-vtext [size]
  (map
    (fn [i] [:text {:font-family "sans-serif" :font-size 72 :x 10 :y (+ 122 (* i cell-size))}  
             (-> i (+ 97) char str)])
    (range size)))

(defn get-goban [filename game]
  (let [f-n (str filename ".png")]
    (svg/render-png (vec (concat [:dali/page] 
                                 (get-hlines (:size game)) 
                                 (get-vlines (:size game))
                                 (get-stars (:size game))
                                 (get-htext (:size game))
                                 (get-vtext (:size game))
                                 (get-stones (:moves game))
                                 (get-last-move (-> game :moves last))))
                    (str "resources/" f-n))
    f-n))

{'fraction_non_alphanumeric': 0.19460257221168037, 'fraction_numerical': 0.02677630191861691, 'mean_word_length': 1.6355555555555557, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 16, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1965901', 'n_tokens_mistral': 1874, 'n_tokens_neox': 1704, 'n_words': 506}