<commit_before>(ns tictactoe.core
  (:require
    [reagent.core :as reagent :refer [atom]]
    [tictactoe.cell :as cell]
    ))

(enable-console-print!)


;; Constants

(def board-size 3)

(def cell-state?
  #{:cell/empty :cell/cross :cell/circle})


;; Game logic

(defn init-board
  []
  (into {}
    (for [x (range board-size)
          y (range board-size)]
      [[x y] :cell/empty]
      )))

(defonce app-state
  (atom {:board (init-board)
         :player :cell/cross}))

(defn play-move
  [board player x y]
  (assoc board [x y] player))

(defn next-player
  [current]
  (if (= current :cell/cross) :cell/circle :cell/cross))

(defn on-move
  [app-state x y]
  (-> app-state
    (update-in [:board] play-move (:player app-state) x y)
    (update-in [:player] next-player)
    ))

(defn on-move-event
  [x y]
  (swap! app-state on-move x y))


;; Rendering

(defn render-board-cell
  [app-state x y]
  (let [cell-state (get (:board app-state) [x y])]
    (cell/render-cell cell-state x y
      (if (= :cell/empty cell-state)
        {:on-click #(on-move-event x y)} {}))
    ))

(defn render-board
  [board-size]
  [:svg.board
   {:view-box (str "0 0 " board-size " " board-size)
    :style {:max-height "500px"}}])

(defn tictactoe
  []
  [:div
   [:h1 "tic tac toe"]
   (into
     (render-board board-size)
     (for [x (range board-size)
           y (range board-size)]
       [render-board-cell @app-state x y]
       ))
   ])

<commit_msg>make code simpler<commit_after>(ns tictactoe.core
  (:require
    [reagent.core :as reagent :refer [atom]]
    [tictactoe.cell :as cell]
    ))

(enable-console-print!)


;; Constants

(def board-size 3)

(def cell-state?
  #{:cell/empty :cell/cross :cell/circle})


;; Game logic

(defn init-board
  []
  (into {}
    (for [x (range board-size)
          y (range board-size)]
      [[x y] :cell/empty]
      )))

(defonce app-state
  (atom {:board (init-board)
         :player :cell/cross}))

(defn play-move
  [board player x y]
  (assoc board [x y] player))

(defn next-player
  [current]
  (if (= current :cell/cross) :cell/circle :cell/cross))

(defn on-move
  [app-state x y]
  (-> app-state
    (update-in [:board] play-move (:player app-state) x y)
    (update-in [:player] next-player)
    ))

(defn on-move-event
  [x y]
  (swap! app-state on-move x y))


;; Rendering

(defn render-board-cell
  [app-state x y]
  (let [cell-state (get (:board app-state) [x y])]
    (cell/render-cell cell-state x y
      (if (= :cell/empty cell-state)
        {:on-click #(on-move-event x y)} {}))
    ))

(defn tictactoe
  []
  [:div
   [:h1 "tic tac toe"]
   (into
     [:svg.board
      {:view-box (str "0 0 " board-size " " board-size)
       :style {:max-height "500px"}}]
     (for [x (range board-size)
           y (range board-size)]
       [render-board-cell @app-state x y]
       ))
   ])


{'fraction_non_alphanumeric': 0.1774193548387097, 'fraction_numerical': 0.004908835904628331, 'mean_word_length': 2.458181818181818, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '4200498', 'n_tokens_mistral': 1158, 'n_tokens_neox': 1118, 'n_words': 287}