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

Pause on objective completion #2096

Merged
merged 10 commits into from
Sep 9, 2024
Merged

Pause on objective completion #2096

merged 10 commits into from
Sep 9, 2024

Conversation

xsebek
Copy link
Member

@xsebek xsebek commented Aug 4, 2024

  • add a new option --hide-goal Do not show goal modal window that pauses the game.
  • pause the game once an objective is finished - can be disabled by --hide-goal
  • show the goal modal window (and autopause) even when running with --autoplay
    • previous behavior can be achieved with --autoplay --hide-goal
    • removes the debug option autoplay_goals
  • closes Pause the game on objective completion #2073

@xsebek
Copy link
Member Author

xsebek commented Sep 8, 2024

For reference, this is how I debugged this with an output to file that showed the state of the objective display queue:

Show patch and debug output
--- b/src/swarm-engine/Swarm/Game/Step.hs
+++ a/src/swarm-engine/Swarm/Game/Step.hs
@@ -341,9 +341,22 @@ hypotheticalWinCheck em g ws oc = do
     _ -> return ()
 
   queue <- messageInfo . announcementQueue Swarm.Util.<%= (>< Seq.fromList (map ObjectiveCompleted $ completionAnnouncementQueue finalAccumulator))
-  shouldPause <- use $ temporal . pauseOnCompletion
 
-  when (newWinState /= Ongoing || (notNull queue && shouldPause == PauseOnAnyObjective)) $
+  shouldPause <- use $ temporal . pauseOnCompletion
+  let willPause = newWinState /= Ongoing || (notNull queue && shouldPause == PauseOnAnyObjective)
+  -- TODO: remove this debug ouput
+  sendIO $
+    appendFile "log_win.txt" $
+      intercalate
+        " \t"
+        [ show $ getTickNumber ts
+        , if newWinState == Ongoing then "ongoing" else "won"
+        , if notNull queue then "queued" else "empty"
+        , show shouldPause
+        , if willPause then "AutoPause" else "Running"
+        ] <> "\n"
+
+  when willPause $
     temporal . runStatus .= AutoPause
 
   mapM_ handleException $ exceptions finalAccumulator
1 	ongoing 	empty 	PauseOnAnyObjective 	Running
2 	ongoing 	queued 	PauseOnAnyObjective 	AutoPause
3 	ongoing 	empty 	PauseOnAnyObjective 	Running
4 	ongoing 	empty 	PauseOnAnyObjective 	Running
5 	ongoing 	empty 	PauseOnAnyObjective 	Running
6 	ongoing 	empty 	PauseOnAnyObjective 	Running
7 	ongoing 	empty 	PauseOnAnyObjective 	Running
8 	ongoing 	queued 	PauseOnAnyObjective 	AutoPause
9 	ongoing 	empty 	PauseOnAnyObjective 	Running
10 	ongoing 	empty 	PauseOnAnyObjective 	Running
11 	ongoing 	empty 	PauseOnAnyObjective 	Running
12 	ongoing 	empty 	PauseOnAnyObjective 	Running
13 	ongoing 	queued 	PauseOnAnyObjective 	AutoPause
14 	ongoing 	empty 	PauseOnAnyObjective 	Running
15 	ongoing 	empty 	PauseOnAnyObjective 	Running
16 	ongoing 	empty 	PauseOnAnyObjective 	Running
17 	ongoing 	empty 	PauseOnAnyObjective 	Running
18 	ongoing 	empty 	PauseOnAnyObjective 	Running
19 	ongoing 	empty 	PauseOnAnyObjective 	Running
20 	ongoing 	empty 	PauseOnAnyObjective 	Running
21 	ongoing 	empty 	PauseOnAnyObjective 	Running
22 	ongoing 	empty 	PauseOnAnyObjective 	Running
23 	ongoing 	empty 	PauseOnAnyObjective 	Running
24 	ongoing 	empty 	PauseOnAnyObjective 	Running
25 	ongoing 	empty 	PauseOnAnyObjective 	Running
26 	ongoing 	empty 	PauseOnAnyObjective 	Running
27 	ongoing 	empty 	PauseOnAnyObjective 	Running
28 	ongoing 	empty 	PauseOnAnyObjective 	Running
29 	ongoing 	empty 	PauseOnAnyObjective 	Running
30 	ongoing 	empty 	PauseOnAnyObjective 	Running
31 	ongoing 	empty 	PauseOnAnyObjective 	Running
32 	ongoing 	empty 	PauseOnAnyObjective 	Running
33 	ongoing 	empty 	PauseOnAnyObjective 	Running
34 	ongoing 	empty 	PauseOnAnyObjective 	Running
35 	ongoing 	empty 	PauseOnAnyObjective 	Running
36 	ongoing 	empty 	PauseOnAnyObjective 	Running
37 	won 	queued 	PauseOnAnyObjective 	AutoPause

@xsebek xsebek marked this pull request as ready for review September 8, 2024 18:25
src/swarm-engine/Swarm/Game/State/Runtime.hs Outdated Show resolved Hide resolved
src/swarm-engine/Swarm/Game/State/Substate.hs Outdated Show resolved Hide resolved
queue <- messageInfo . announcementQueue Swarm.Util.<%= (>< Seq.fromList (map ObjectiveCompleted $ completionAnnouncementQueue finalAccumulator))
shouldPause <- use $ temporal . pauseOnCompletion

when (newWinState /= Ongoing || (notNull queue && shouldPause == PauseOnAnyObjective)) $
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm trying to make sure I understand the logic here. What is the purpose of the notNull queue check? How does the newWinState check and the other check fit together? (And can you turn your answer into some comments in the code here?)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I named the parts using let. Is it clearer now? 🙂

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, much better, thanks!

src/swarm-tui/Swarm/TUI/Model/StateUpdate.hs Outdated Show resolved Hide resolved
@xsebek xsebek added the merge me Trigger the merge process of the Pull request. label Sep 9, 2024
@mergify mergify bot merged commit 65c5ef9 into main Sep 9, 2024
12 checks passed
@mergify mergify bot deleted the pause-on-objective branch September 9, 2024 10:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merge me Trigger the merge process of the Pull request.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Pause the game on objective completion
2 participants