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

Scenario launch options selection #1010

Merged
merged 10 commits into from Jun 9, 2023
Merged

Scenario launch options selection #1010

merged 10 commits into from Jun 9, 2023

Conversation

kostmo
Copy link
Member

@kostmo kostmo commented Jan 15, 2023

Closes #358 and closes #866.

Allows specification of a seed value and/or the path of a script to run. Specifying a script to run in advance allows eligibility for code size scoring.

Some effort was invested into integrating the Brick FileBrowser widget and discovering its idiosyncrasies. This paves the way for more applications of FileBrowser within Swarm.

Usage

From the scenario selection menu, press the o key to pop up a dialog for launch options.

Screenshot from 2023-06-06 01-38-25

Any manually-selected initial-script or seed are persisted to disk and will pre-populate the launch configuration dialog upon the next play. If a certain scenario is subsequently launched the normal way (i.e. by pressing Enter instead of o), then this clears the saved script path/seed, and the next pop-up of the launch configuration dialog will not see its fields pre-populated.

Warning: Save format changed

This PR changes the ScenarioStatus datatype, and therefore game status/progress saved previously to this PR will not be recognized. See #974 (comment) for discussion about this situation.

@kostmo kostmo force-pushed the scenario-launch-options branch 2 times, most recently from 9ef9e2b to 82baf9b Compare January 19, 2023 08:06
@kostmo kostmo mentioned this pull request Feb 4, 2023
@kostmo kostmo force-pushed the scenario-launch-options branch 2 times, most recently from c96caa6 to 213ebcd Compare February 25, 2023 09:06
mergify bot pushed a commit that referenced this pull request May 2, 2023
towards #866

NOTE: #1116 should be merged first so that the schema change of save files is less disruptive.

## Examples

Different criteria can have their own best score:
![image](https://user-images.githubusercontent.com/261693/219904496-fcd23ca0-b208-43e1-afc6-188acfe327cf.png)

All criteria share the same single best score:
![image](https://user-images.githubusercontent.com/261693/219904553-abe3011c-41b0-469c-b34d-95d84b91697a.png)

## Behavior notes

* As currently designed, the code size will only be scored if the the player has specified their code **before** the scenario begins.  Furthermore, any input into the REPL will invalidate code size scoring for the current game.
* Because of this, the only way to score code so far is with a command-line argument of `--run` or `--autoplay`.  However, #1010  shall implement code size scoring when a scenario is launched from the UI.
* In the "best scores" display, if multiple "best score" criteria were all from the same game, they will be consolidated.  If all criteria are for the same game, the criteria labels will be omitted.
* The code size metrics will not be displayed if a "best score" was not obtained via `--run`.

## Caveats

### `run` command

Currently, the code entailed in a `run "somescript.sw"` command is not transitively included, so using `run` make the code size score meaningless.

## Testing

### Unit tests

Run the subset of unit tests:

    scripts/run-tests.sh --test-arguments '--pattern "Tests.Precedence"'

### Manual integration tests

First, reset the score:

    rm -f ~/.local/share/swarm/saves/Tutorials_grab.yaml

Saving the following to `grab-soln.sw`:
```
move;
move; grab; turn back; move; turn back; move;
move; grab; turn back; move; turn back; move;
move; grab; turn back; move; turn back; move;
move; grab; turn back; move; turn back; move;
move; grab; turn back; move; turn back; move;
move; grab;
```
Run as follows:

    scripts/play.sh --scenario Tutorials/grab.yaml --run grab-soln.sw

This should establish a record for code size.

Then, play the Grab tutorial and immediately paste and run this in the REPL:

    move; move; grab; move; grab; move; grab; move; grab; move; grab; move; grab;

This solution is faster in terms of time, but should not displace the code-length record, since no code length should be recorded from a REPL solution.
@kostmo kostmo force-pushed the scenario-launch-options branch 4 times, most recently from cb72a1a to db30f27 Compare May 4, 2023 22:16
@kostmo kostmo force-pushed the scenario-launch-options branch 4 times, most recently from a2cb3e9 to fae2c52 Compare May 5, 2023 06:50
@kostmo kostmo force-pushed the scenario-launch-options branch 2 times, most recently from ce8cbd8 to b3b8719 Compare May 6, 2023 17:39
@kostmo kostmo force-pushed the scenario-launch-options branch 3 times, most recently from 69f3d2c to 80f8882 Compare June 6, 2023 21:25
@kostmo kostmo marked this pull request as ready for review June 6, 2023 21:28
@kostmo kostmo requested review from byorgey and xsebek June 6, 2023 21:28
@byorgey
Copy link
Member

byorgey commented Jun 7, 2023

Cool! Taking a look now! 👀

Copy link
Member

@byorgey byorgey left a comment

Choose a reason for hiding this comment

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

Wow, amazing work!

Typing in the initial seed field takes a long time (i.e. it takes a second or two to update after every keypress), I wonder why?

src/Swarm/Game/Scenario/Status.hs Outdated Show resolved Hide resolved
src/Swarm/Game/Scenario/Status.hs Outdated Show resolved Hide resolved
src/Swarm/TUI/Launch/Controller.hs Show resolved Hide resolved
src/Swarm/TUI/Launch/Model.hs Outdated Show resolved Hide resolved
src/Swarm/TUI/View.hs Show resolved Hide resolved
@kostmo kostmo force-pushed the scenario-launch-options branch 3 times, most recently from f513ba6 to 700ebfd Compare June 9, 2023 05:52
@kostmo kostmo added the merge me Trigger the merge process of the Pull request. label Jun 9, 2023
@mergify mergify bot merged commit b382494 into main Jun 9, 2023
9 checks passed
@mergify mergify bot deleted the scenario-launch-options branch June 9, 2023 06:38
@xsebek
Copy link
Member

xsebek commented Jun 9, 2023

@kostmo I finally got around to play with this and its great! 👍

Running custom scripts from UI feels like this was always supposed to be the way to do it. 🙂

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.

Code golf scoring Allow player to choose a specific seed through the UI
3 participants