<commit_before>(ns game.core
  (:require [game.utils :refer [remove-once has? merge-costs zone make-cid to-keyword capitalize
                                costs-to-symbol vdissoc distinct-by]]
            [game.macros :refer [effect req msg]]
            [clojure.string :refer [split-lines split join]]))

(declare cards)

(def game-states (atom {}))

(defn card-def [card]
  (when-let [title (:title card)]
    (cards (.replace title "'" ""))))

(defn say [state side {:keys [user text]}]
  (let [author (or user (get-in @state [side :user]))]
    (swap! state update-in [:log] #(conj % {:user author :text text}))))

(defn system-msg [state side text]
  (let [username (get-in @state [side :user :username])]
    (say state side {:user "__system__" :text (str username " " text ".")})))

(declare prompt! forfeit trigger-event handle-end-run trash update-advancement-cost update-all-advancement-costs
         update-all-ice update-ice-strength update-breaker-strength all-installed)

(defn pay [state side card & args]
  (let [costs (merge-costs (remove #(or (nil? %) (= % [:forfeit])) args))
        forfeit-cost (some #{[:forfeit] :forfeit} args)
        scored (get-in @state [side :scored])]
    (when (and (every? #(>= (- (get-in @state [side (first %)]) (last %)) 0) costs)
               (or (not forfeit-cost) (not (empty? scored))))
      (when forfeit-cost
           (if (= (count scored) 1)<commit_msg>split pay function into pay and can-pay?<commit_after>(ns game.core
  (:require [game.utils :refer [remove-once has? merge-costs zone make-cid to-keyword capitalize
                                costs-to-symbol vdissoc distinct-by]]
            [game.macros :refer [effect req msg]]
            [clojure.string :refer [split-lines split join]]))

(declare cards)

(def game-states (atom {}))

(defn card-def [card]
  (when-let [title (:title card)]
    (cards (.replace title "'" ""))))

(defn say [state side {:keys [user text]}]
  (let [author (or user (get-in @state [side :user]))]
    (swap! state update-in [:log] #(conj % {:user author :text text}))))

(defn system-msg [state side text]
  (let [username (get-in @state [side :user :username])]
    (say state side {:user "__system__" :text (str username " " text ".")})))

(declare prompt! forfeit trigger-event handle-end-run trash update-advancement-cost update-all-advancement-costs
         update-all-ice update-ice-strength update-breaker-strength all-installed)

(defn can-pay? [state side & args]
  (let [costs (merge-costs (remove #(or (nil? %) (= % [:forfeit])) args))
        forfeit-cost (some #{[:forfeit] :forfeit} args)
        scored (get-in @state [side :scored])]
    (if (and (every? #(>= (- (get-in @state [side (first %)]) (last %)) 0) costs)
             (or (not forfeit-cost) (not (empty? scored))))
      {:costs costs, :forfeit-cost forfeit-cost, :scored scored}
    )))

(defn pay [state side card & args]
  (when-let [{:keys [costs forfeit-cost scored]} (apply can-pay? state side args)]
    (when (and (every? #(>= (- (get-in @state [side (first %)]) (last %)) 0) costs)
               (or (not forfeit-cost) (not (empty? scored))))
      (when forfeit-cost
           (if (= (count scored) 1)
{'fraction_non_alphanumeric': 0.17296284733062753, 'fraction_numerical': 0.0015610365282547611, 'mean_word_length': 3.086734693877551, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 6, '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': '4401572', 'n_tokens_mistral': 1116, 'n_tokens_neox': 1064, 'n_words': 328}