<commit_before>(ns zetawar.players.ai.custom
  (:require
   [cljs.core.async :as async]
   [datascript.core :as d]
   [taoensso.timbre :as log]
   [zetawar.app :as app]
   [zetawar.db :as db]
   [zetawar.game :as game]
   [zetawar.hex :as hex]
   [zetawar.players :as players]
   [zetawar.players.simple-embedded :refer [simple-embedded-player]]))

(defn score-actor [db game actor actor-ctx]
  (cond
    (game/unit? actor) (rand-int 100)
    (game/base? actor) (+ (rand-int 100) 100)))

(defn score-base-action [db game base action-ctx action]
  (rand-int 200))

(defn mk-unit-action-ctx [db game actor-ctx unit]
  (assoc actor-ctx :closest-base (game/closest-capturable-base db game unit)))

(defn score-unit-action [db game unit action-ctx action]
  (let [{:keys [closest-base]} action-ctx]
    (case (:action/type action)
      :action.type/capture-base
      200

      :action.type/attack-unit
      100

      :action.type/move-unit
      (let [[base-q base-r] (game/terrain-hex closest-base)
            {:keys [action/to-q action/to-r]} action
            base-distance (hex/distance base-q base-r to-q to-r)]
        (- 100 base-distance))

      0)))

(defmethod players/new-player ::players/reference-ai
  [{:as app-ctx :keys [ev-chan notify-pub]} player-type faction-color]
  (let [fns {:score-actor #'score-actor
             :score-base-action #'score-base-action
             :mk-unit-action-ctx #'mk-unit-action-ctx
             :score-unit-action #'score-unit-action}]
    (simple-embedded-player faction-color
                            ev-chan
                            notify-pub
                            fns)))<commit_msg>Fixing custom AI ID<commit_after>(ns zetawar.players.ai.custom
  (:require
   [cljs.core.async :as async]
   [datascript.core :as d]
   [taoensso.timbre :as log]
   [zetawar.app :as app]
   [zetawar.db :as db]
   [zetawar.game :as game]
   [zetawar.hex :as hex]
   [zetawar.players :as players]
   [zetawar.players.simple-embedded :refer [simple-embedded-player]]))

(defn score-actor [db game actor actor-ctx]
  (cond
    (game/unit? actor) (rand-int 100)
    (game/base? actor) (+ (rand-int 100) 100)))

(defn score-base-action [db game base action-ctx action]
  (rand-int 200))

(defn mk-unit-action-ctx [db game actor-ctx unit]
  (assoc actor-ctx :closest-base (game/closest-capturable-base db game unit)))

(defn score-unit-action [db game unit action-ctx action]
  (let [{:keys [closest-base]} action-ctx]
    (case (:action/type action)
      :action.type/capture-base
      200

      :action.type/attack-unit
      100

      :action.type/move-unit
      (let [[base-q base-r] (game/terrain-hex closest-base)
            {:keys [action/to-q action/to-r]} action
            base-distance (hex/distance base-q base-r to-q to-r)]
        (- 100 base-distance))

      0)))

(defmethod players/new-player ::players/custom-ai
  [{:as app-ctx :keys [ev-chan notify-pub]} player-type faction-color]
  (let [fns {:score-actor #'score-actor
             :score-base-action #'score-base-action
             :mk-unit-action-ctx #'mk-unit-action-ctx
             :score-unit-action #'score-unit-action}]
    (simple-embedded-player faction-color
                            ev-chan
                            notify-pub
                            fns)))
{'fraction_non_alphanumeric': 0.14471692400847713, 'fraction_numerical': 0.013321223130487435, 'mean_word_length': 2.3509127789046653, '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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2875264', 'n_tokens_mistral': 1205, 'n_tokens_neox': 1140, 'n_words': 262}