Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added util fns - play-from-hand-with-prompt, click-prompts #7942

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions test/clj/game/cards/events_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -2225,8 +2225,7 @@
(do-game
(new-game {:runner {:deck [(qty "Dirty Laundry" 2)]}})
(take-credits state :corp)
(play-from-hand state :runner "Dirty Laundry")
(click-prompt state :runner "Archives")
(play-from-hand-with-prompts state :runner "Dirty Laundry" "Archives")
(run-continue state)
(is (= 8 (:credit (get-runner))) "Gained 5 credits")
(play-from-hand state :runner "Dirty Laundry")
Expand Down
19 changes: 7 additions & 12 deletions test/clj/game/cards/operations_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -214,11 +214,7 @@
:hand ["Ad Blitz" "Launch Campaign"]
:discard ["Pop-up Window"]}})
(play-from-hand state :corp "Ad Blitz")
(click-prompt state :corp "2")
(click-card state :corp "Launch Campaign")
(click-prompt state :corp "New remote")
(click-card state :corp "Pop-up Window")
(click-prompt state :corp "Server 1")
(click-prompts state :corp "2" "Launch Campaign" "New remote" "Pop-up Window" "Server 1")
(is (zero? (count (:hand (get-corp)))) "Corp should have no cards in HQ")
(is (= ["Ad Blitz"] (->> (get-corp) :discard (map :title))) "Corp should have only Ad Blitz in Archives")))

Expand Down Expand Up @@ -3223,10 +3219,11 @@
(play-from-hand state :corp "Oppo Research")
(is (not (no-prompt? state :runner)) "Runner prompted to avoid tag")
(card-ability state :runner (get-resource state 0) 0)
(click-prompt state :corp "0")
(click-prompt state :runner "0")
(click-prompt state :runner "Done")
(click-prompt state :corp "Yes"))
(click-prompts state :corp
"0"
{:side :runner :choice "0"}
{:side :runner :choice "Done"}
"Yes"))
"Runner prevented 2 tag")))

(deftest oversight-ai-rez-at-no-cost
Expand Down Expand Up @@ -5193,9 +5190,7 @@
(advance state (refresh ngo) 2)
(is (= 2 (get-counters (refresh ngo) :advancement)) "NGO Front should have 2 counters")
(play-from-hand state :corp "Trick of Light")
(click-card state :corp iw)
(click-card state :corp ngo)
(click-prompt state :corp "2")
(click-prompts state :corp iw ngo "2")
(is (= 2 (get-counters (refresh iw) :advancement)) "Ice Wall is now advanced")
(is (zero? (get-counters (refresh ngo) :advancement)) "NGO Front should have 0 counters"))))

Expand Down
6 changes: 2 additions & 4 deletions test/clj/game/cards/programs_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -1840,8 +1840,7 @@
:runner {:hand ["Chisel"]}})
(play-from-hand state :corp "Ice Wall" "HQ")
(take-credits state :corp)
(play-from-hand state :runner "Chisel")
(click-card state :runner "Ice Wall")
(play-from-hand-with-prompts state :runner "Chisel" "Ice Wall")
(let [iw (get-ice state :hq 0)
chisel (first (:hosted (refresh iw)))]
(run-on state "HQ")
Expand Down Expand Up @@ -1891,8 +1890,7 @@
:runner {:hand ["Chisel" "Devil Charm"]}})
(play-from-hand state :corp "Ice Wall" "HQ")
(take-credits state :corp)
(play-from-hand state :runner "Chisel")
(click-card state :runner "Ice Wall")
(play-from-hand-with-prompts state :runner "Chisel" "Ice Wall")
(play-from-hand state :runner "Devil Charm")
(let [iw (get-ice state :hq 0)
chisel (first (:hosted (refresh iw)))]
Expand Down
56 changes: 56 additions & 0 deletions test/clj/game/test_framework.clj
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,38 @@
[state side choice & args]
`(error-wrapper (click-prompt-impl ~state ~side ~choice ~@args)))

(defn click-prompts-impl
[state side prompts]
(loop [[prompt & prompts] prompts]
(let [prompt
;; if an 1-fn is passed in, scry it's output based on the game state
(cond
(fn? prompt) (prompt state)
(fn? (:choice prompt)) (merge prompt {:choice ((:choice prompt) state)})
:else prompt)]
(cond
(and (not prompt) (not (seq prompts))) true
(not prompt) (is` nil "attempt to resolve nil prompt option")
;; it's a select prompt - we want to click on a card
(prompt-is-type? state side :select)
(do (if (or (:cid prompt) (string? prompt))
(click-card state side prompt)
(click-card state (or (:side prompt) side) (:choice prompt)))
(recur prompts))
:else
(do (if (or (:cid prompt) (string? prompt))
(click-prompt state side prompt)
(click-prompt state (or (:side prompt) side) (:choice prompt)))
(recur prompts))))))

(defmacro click-prompts
"click an arbitrary number of prompts, one after the other.
You can tag a prompt like {:side :runner :choice ...}, feed in raw cards,
or feed in cards like {:choice ...}"
([state side] true)
([state side & prompts]
`(error-wrapper (click-prompts-impl ~state ~side ~(vec prompts)))))

(defn do-trash-prompt
[state cost]
(click-prompt state :runner (str "Pay " cost " [Credits] to trash")))
Expand Down Expand Up @@ -532,6 +564,10 @@
(let [card (find-card title (get-in @state [side :hand]))]
(ensure-no-prompts state)
(is' (some? card) (str title " is in the hand"))
(when-not (some? card)
(let [other-side (if (= side :runner) :corp :runner)]
(when (some? (find-card title (get-in @state [other-side :hand])))
(println title " was instead found in the opposing hand - was the wrong side used?"))))
(when server
(is' (some #{server} (concat (server-list state) ["New remote"]))
(str server " is not a valid server.")))
Expand All @@ -546,6 +582,26 @@
([state side title server]
`(error-wrapper (play-from-hand-impl ~state ~side ~title ~server))))

(defn play-from-hand-with-prompts-impl
[state side title choices]
(let [card (find-card title (get-in @state [side :hand]))]
(ensure-no-prompts state)
(is' (some? card) (str title "is in hand"))
(if-not (some? card)
(do (let [other-side (if (= side :runner) :corp :runner)]
(when (some? (find-card title (get-in @state [other-side :hand])))
(println title " was instead found in the opposing hand - was the wrong side used?")))
true)
(when-let [played (core/process-action "play" state side {:card card})]
(click-prompts-impl state side choices)))))

(defmacro play-from-hand-with-prompts
"Play a card from hand based on it's title, and then click any number of prompts
accepts for prompt: a string, a fn, a card object"
([state side title] `(play-from-hand ~state ~side ~title nil))
([state side title & prompts]
`(error-wrapper (play-from-hand-with-prompts-impl ~state ~side ~title ~(vec prompts)))))

;;; Run functions
(defn run-on-impl
[state server]
Expand Down