Commit Graph

23 Commits

Author SHA1 Message Date
Karl Ostmo
a94ab9d97c
autogenerated sublibrary diagram (#1720)
Towards #1689

![sublibrary-graph](https://github.com/swarm-game/swarm/assets/261693/b300fb0d-be59-4fc9-a042-04ceaf4909b2)
2024-01-08 20:16:00 +00:00
Karl Ostmo
a388af6155
enforce scenario normalization (#1718)
Closes #1713.
2024-01-06 01:21:21 +00:00
Karl Ostmo
ab9f86ee70
normalize scenarios (#1711)
Closes #845

**All changes are non-significant whitespace.**  This can be verified with:

    git show --ignore-all-space --ignore-blank-lines

in which the remaining changes are only elimination of manual word-wrap in descriptions.

Normalization is accomplished with this command:

    scripts/normalize-all-scenarios.sh

This is an initial normalization pass that shall be a pre-requisite for #1713.
2024-01-05 11:32:26 -08:00
Karl Ostmo
979c72b72c
bump cabal-build version, fix haddock script (#1703)
Encountered this bug: https://github.com/commercialhaskell/stack/issues/5254#issuecomment-1874622685

Fixed by using `cabal` to generate haddocks instead of `stack`.
Also bumped `cabal-version` to latest and adjusted `swarm.cabal` to conform.
2024-01-03 20:47:00 +00:00
Brent Yorgey
e227230bbb
Specifically build swarm:swarm component in play.sh script (#1682)
This seems to help with rebuild times, since we are specifically requesting to only build the `swarm` executable and not, say, the `swarm-docs` executable.
2023-12-13 20:34:43 +00:00
Karl Ostmo
b244a4223c
Split Step.hs (#1665)
Both `execConst` and `stepCESK` are huge case statements.  This refactor puts them in different modules.

Also many supporting functions for implementing commands in `execConst` are moved to their own modules.

Whereas `Step.hs` previously had `2931` lines, the new linecounts are:

| File | lines |
| --- | --- |
| `Step.hs` | 848 |
| `Arithmetic.hs` | 124 |
| `Const.hs` | 1687 |
| `Command.hs` | 417 |

The only tricky thing was that `execConst` is mutually recursive with `runCESK`.  So to get them into different modules, I pass a wrapper of `runCESK` as an argument to `execConst`.
2023-11-28 17:41:14 +00:00
Ondřej Šebek
2c3fc525c9
Add wave program to benchmarks (#1576)
* add wave program and parametrise it to compare inlined/generic version
* use [`tasty-bench`](https://hackage.haskell.org/package/tasty-bench) library to show comparison
* move benchmarks to test folder as they can now share tasty code
* closes #1574 

Using the recursive definition with ifs leads to a 3x slowdown:
```
wavesInlined
  10: OK
    361  ms ±  29 ms
  20: OK
    718  ms ±  35 ms
  30: OK
    1.066 s ±  28 ms
  40: OK
    1.437 s ±  37 ms
wavesWithDef
  10: OK
    1.052 s ±  51 ms, 2.92x
  20: OK
    2.117 s ±  34 ms, 2.95x
  30: OK
    3.144 s ±  80 ms, 2.95x
  40: OK
    4.191 s ±  91 ms, 2.92x
```
But if we just inline and simplify the code, we can remove the runtime overhead completely.
2023-10-09 04:45:27 +00:00
Karl Ostmo
4e886e0c3c
Autogenerate scenario schema doc (#1441)
Closes #1436.

The schema `.json` files are now the authoritative source of truth for documentation.

Wrote a very simple parser for JsonSchema to extract the documentation from JSON.

Split the README.md into [static](c314cc50a1/data/scenarios/README.md) and [auto-generated](c314cc50a1/data/scenarios/doc-fragments/SCHEMA.md) parts.

Added a custom `"footers"` key to schema files to support inclusion of other markdown files for each object description.

# Schema doc regeneration

    ./scripts/regenerate-schema-docs.sh
2023-10-09 02:11:30 +00:00
Ondřej Šebek
694e00b678
Make function chains pretty (#1479)
- closes #1473
2023-10-07 21:04:01 +00:00
Brent Yorgey
85b33ef5c9
Refactor LogEntry type (#1513)
In preparation for #1483.   `LogEntry` started life as something specific to robot logs.  It then evolved to be used in the system log as well (see #1039 and #652), but in a sort of hacky way.  This PR refactors `LogEntry` to be more generic.

- Move `Swarm.Game.Log` -> `Swarm.Log` since it's not specific to gameplay.
- Rename `ErrorLevel` to `Severity`, add a new `Info` level, and add a top-level `leSeverity` field
- Rename `leRobotName` to just `leName`, since it was already being used to name both robots and system components anyway
- Move robot-specific fields (*e.g.* robot ID) into the new `RobotLogSource` type, and add `LogSource` to differentiate between robot and system logs
- Various other minor improvements and tweaks
2023-09-15 03:08:25 +00:00
Karl Ostmo
bb31126c75
Decompose GameState into sub-records (#1510)
Towards #872

Previously, the `GameState` record had `41` toplevel members.  It now has `22`.   Logical grouping of the fields makes it easier to peruse the code and paves the way to split `State.hs` into smaller modules.  Some functions now may even be able to operate exclusively on subsets of the game state, rather than having to pass in `GameState` as a whole.

There is potential to go even farther, by extracting view-related and robot-related members to their own records, but I figured I'd pursue this refactoring incrementally.
2023-09-11 18:25:45 +00:00
Karl Ostmo
98ebf74cfe
more documentation tweaks (#1493)
Also:
* adds a script to view locally-generated Haddocks.
* Describes module organization as per https://github.com/swarm-game/swarm/pull/1069#issue-1565024308 in the toplevel cabal package description
2023-09-07 07:00:44 +00:00
Karl Ostmo
bfc0c143b8
Validate scenarios against json schema (#1475)
Closes #1428

Since the authoritative validation of scenario files is actually performed by virtue of `swarm` parsing them, this CI job actually exists to ensure the JSON Schema descriptions are accurate.  This is important for two purposes:
* Documentation is generated from the JSON Schema files (#1436)
* JSON Schema has integration with VS Code and other IDEs

# Testing

Verified that the schema checker action does indeed work by intentionally pushing an invalid scenario file in f789f81.
2023-08-28 02:34:03 +00:00
Ondřej Šebek
f743c90027
Render markdown in entity descriptions (#1413)
* use `Markdown.Document` as `entityDescription`
* add missing spaces in `chunksOf`
* fix code in `entities.yaml` (mostly types and few outdated snippets)
* add code markdown in craft tutorial
* use colours for types and entities

- closes #1408
- closes #1409
2023-08-12 11:42:12 +00:00
Karl Ostmo
f9c22635b5
subworlds (#1353)
Closes #144.

This builds upon portals support (#1356)

# Demo

    scripts/play.sh --scenario data/scenarios/Testing/144-subworlds/subworld-mapped-robots.yaml --autoplay --speed 2

[![asciicast](https://asciinema.org/a/vC13dW8M1S8t2b1J4XkW80U1q.svg)](https://asciinema.org/a/vC13dW8M1S8t2b1J4XkW80U1q)

# Future work
* Augment portal definitions with an optional "relative orientation" attribute, that can turn the player around when passing through the portal (#1379)
* Specify whether portal performs instant transportation or whether `move down` is required (#1368)
2023-07-22 20:29:22 +00:00
Karl Ostmo
485e6ace1f
Fourmolu fixup (#1326)
Switch to `fourmolu-0.13` and reformat all source code.
2023-07-12 18:00:23 +00:00
Karl Ostmo
30e6bd67ad
sliding puzzle (#1237)
Note: I put some effort toward a completely general, automated solution, but eventually just reduced the board size to 3x3 and solved it manually, and used the API to obtain the manual commands to paste into the solution:

    curl http://localhost:5357/repl/history/full | jq .[].in -r

The board generator is generalized to any square dimension, but some scaffolding must be built to re-use the code across multiple scenarios.  The new `Sliding Puzzles` directory is intended to contain a 3x3, 4x4, and 5x5 puzzle, but currently only contains 3x3.

### 3x3 board
![image](https://github.com/swarm-game/swarm/assets/261693/babf3dbb-2d89-4c1e-a452-be8f61077180)

### 4x4 demo
![board](https://user-images.githubusercontent.com/261693/235421110-db0de5ce-8a25-482f-8a61-f42f5b469761.png)

## Demo

    scripts/play.sh --scenario "data/scenarios/Challenges/Sliding Puzzles/3x3.yaml" --autoplay
2023-06-17 23:58:46 +00:00
Karl Ostmo
9e2f8b2961
sniff/chirp commands (#1181)
towards #1171

## New tests

Unit tests:

    scripts/run-tests.sh --test-arguments '--pattern "Relative direction"'

Integration tests for `sniff` and `chirp` demonstrate how to home in on an item using distance and orientation, respectively.

## Efficiency

For the sake of execution time, I have capped the max "diameter" (`N`) of both commands to `200` cells.  In the worst case (the entity is not present), `O(N^2)` cells are inspected, which manifests as a perceptible delay when the command is run.  I came across the `getElemsInArea` function that seems to suggest that an `O(N * log N)` search may be possible.  Is that the case?

Otherwise we may be able to add some new data structures to the game state for efficient entity location querying.
2023-03-29 05:51:53 +00:00
Karl Ostmo
5927238497
Todo enforcement line number (#1045)
As an extension to #514, include the line number in the grep output, and move the grep logic to a script, so that it can be used within VS Code and clicking on the file:line will open the editor at the right place.

![vscode-demo](https://user-images.githubusercontent.com/261693/214456476-c27b2360-1018-4281-8930-45faaa17d66b.png)

The GitHub action still works.  See this CI run: https://github.com/swarm-game/swarm/actions/runs/4001861308/jobs/6868527786
2023-01-25 05:15:41 +00:00
Karl Ostmo
ae4f9a376d
stack exec invocation script with --fast compilation (#1009)
`stack` invocation with `--fast` to work around #1000

Example invocation:

    ./scripts/play.sh --scenario data/scenarios/Challenges/Ranching/gated-paddock.yaml --autoplay
2023-01-16 07:14:29 +00:00
Karl Ostmo
68c992aa2d
Isolate work directory for 'stack test' (#995)
Closes #936.

With this change, `stack build` should be invoked as normal, but to run tests one should invoke the new script, which will place compilation artifacts in a separate directory so as to not stomp on the previous `stack build` artifacts.

## Demo

```
stack build
./scripts/run-tests.sh
stack build
```
All perform incremental compilation rather than from-scratch.
2023-01-10 18:34:18 +00:00
Karl Ostmo
13c99bcc08
remove --cabal-default-extensions arg from fourmolu invocation (#889)
Restyled.io uses fourmolu version `0.10.1.0`.  It is not clear how it could be pegged to `0.4.0.0`.  The latest I was able to install on my machine with `cabal install` was `0.9.0.0`.

fixes #888
2022-12-08 03:10:42 +00:00
Karl Ostmo
ef31834a61
Make code reformatting command a script in the repo (#875) 2022-11-22 15:21:28 +00:00