Commit Graph

1175 Commits

Author SHA1 Message Date
Karl Ostmo
5f53082971
Render command matrix (#1658)
## Demo

1. Run `scripts/play.sh`
2. Load http://localhost:5357/command-matrix.html

The rows are sortable by column.

### Also

    stack build swarm:swarm-docs --fast && stack exec swarm-docs -- cheatsheet --matrix



## Screenshot

![Screenshot from 2024-01-21 21-32-56](https://github.com/swarm-game/swarm/assets/261693/f92f5ac9-8440-4aac-9a4b-9e5edac616f2)
2024-01-26 01:02:14 +00:00
Karl Ostmo
101b17c882
Improve separation of engine and scenario sublibraries (#1743)
Closes #1741

Remaining blocker was to move logging to concrete robot.

Most notably, the `swarm-scenario` sublibrary has been purged of its temporal component, corroborated by the removal of the `time` package dependency.
2024-01-26 00:48:20 +00:00
Karl Ostmo
3720e94c0a
move activity counts into swarm-engine (#1742)
Towards #1741
2024-01-24 23:47:44 +00:00
Karl Ostmo
17b327fc1d
workspace spelling dictionary (#1587)
The spellchecker in VS code can be quite noisy, given all of the esoteric terminology and shorthand variable names in code.
However, it is also super helpful for catching typos, if you can wade through the noise.

Adding a project-specific dictionary will significantly cut down on that noise.
2024-01-24 21:59:53 +00:00
Karl Ostmo
05613dfba4
split scenario construction into separate sublibrary (#1719)
Towards #1715 and #1043

Creates a new `swarm-scenario` sublibrary intended for scenario data that is independent of game state.

# Planned follow-ups

This PR is already pretty large, but there is still more that can be done regarding sublibrary reorganization/splitting.

* May want to pare-down a sublibrary exclusively for world-generation without all the other baggage of scenarios.
* `Swarm.Game.ScenarioInfo`, `Swarm.Game.Tick`, and `Swarm.Game.Scenario.Status` could probably be moved from `swarm-scenario` to `swarm-engine`.
2024-01-24 21:11:14 +00:00
Karl Ostmo
cf5f064828
do not call updateEntityAt twice for Swap command (#1738) 2024-01-23 21:05:24 -08:00
Karl Ostmo
d1a41de8ad
simplify infinite entity grabbing logic (#1737)
Refactoring towards #1598
2024-01-24 04:53:05 +00:00
Karl Ostmo
9320a985e4
Use type family for RobotContext field (#1732)
Continuation of #1731.

Towards #1715 and #1043.

This refactoring step is a prerequisite for #1719 to extricate references to the `CESK` module from the base `RobotR` definition.

# In this PR:

* Extracts the `RobotContext` type to a new module
* Introduces a type family for the `RobotContext` field
2024-01-20 21:35:27 +00:00
Karl Ostmo
40ea471686
Remove superfluous trobotContext lens (#1731)
# Motivation

Want to remove dependence of `TRobot` on the `RobotContext` record.  However, a lens `trobotContext` had been added in #817 to fix #394.

# Test

    scripts/run-tests.sh --test-arguments '--pattern "394-build-drill"'
2024-01-16 17:36:36 +00:00
Karl Ostmo
3d87e71939
Use type family for robot CESK machine field (#1729)
Towards #1715 and #1043.

This refactoring step is a prerequisite for #1719 to extricate references to the `CESK` module from the base `RobotR` definition.

In this PR:
* `Swarm.Game.CESK` is imported qualified to more easily track usages
* A new `RobotMachine` type family is added to parameterize the `_machine` field.
* `CESK` is a new parameter to `addTRobot`
2024-01-14 20:11:44 +00:00
Brent Yorgey
36df471087
infinite improbability drive device enabling teleport command (#1724)
* `tea plant` (which now spawns rarely in a certain biome of the classic world) can be harvested to yield...
* `tea leaves`, which can be combined with `water` to produce...
* `cup of tea`, which, along with `atomic vector plotter` (= `rubber band` + `typewriter` + `compass` + `counter`), are ingredients for...
* `infinite improbability drive`, which enables `teleport`.

When used by a privileged robot (system robot or in creative mode), the `teleport` command continues to function as before.  When used by an unprivileged robot, that is, via the `infinite improbability drive` device, a random entity spawns somewhere near the target location.

Closes #1041.
2024-01-14 00:31:12 +00:00
Brent Yorgey
5adc8c7429
Child robots only inherit their parent's displayAttr (#1722)
Fixes #1693.  It's not necessarily appropriate to copy the entire `Display` record.  So instead, we explicitly list the fields that should be inherited.  For now, it is only `displayAttr`, but we could add `invisible` in the future (see #1670, #1663).

Tested to make sure behavior is preserved with:
```
scripts/play.sh -i scenarios/Challenges/Ranching/beekeeping.yaml --autoplay
```
2024-01-14 00:14:29 +00:00
Brent Yorgey
ded3c24223
Depend only on vty-crossplatform (#1727)
Closes #1623.

Note that we still have to list both `vty-unix` and `vty-windows` in `stack.yaml` but that's OK; it just means they are both made available as extra dependencies, but only whichever is needed will actually be installed.  In the codebase itself, we now get to avoid CPP on imports, and the code is quite a bit simpler.
2024-01-13 23:47:17 +00:00
Brent Yorgey
778ba71079
Grant achievement for crafting a bitcoin (#1688)
Grant `CraftedBitcoin` achievement when using the `make` command to craft a `bitcoin`,  not in creative mode, and not a system robot.

Towards #1435 .
2024-01-13 22:43:52 +00:00
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
47a8ffe115
rename 'portable' to 'pickable' (#1706)
Closes #1695.

Updating occurrences was pretty easy:

    yq --inplace '(.[].properties[] | select(. == "portable")) |= "pickable"' data/entities.yaml

and

    find data/scenarios -type f -name '*.yaml' -print0 | xargs --max-args 1 --null yq --inplace '(select(has("entities")) | .entities[] | select(has("properties")) | .properties[] | select(. == "portable")) |= "pickable"'
2024-01-05 19:58:19 +00:00
Karl Ostmo
666f86d24b
normalize entities and recipes (#1717) 2024-01-05 11:41:16 -08: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
3cfc3c4ee9
extract game engine sublibrary (#1714)
Towards #1043

Extracts `Swarm.Game.*` modules to their own sublibrary.

There was already pretty good separation along this boundary; just had to move three functions into a new module `Swarm.Util.Content`.
2024-01-05 18:26:06 +00:00
Karl Ostmo
a11fa43344
enhance styling test, fix yaml syntax (#1712)
YAML syntax in this file was actually fixed in #1672, which is not yet merged.
Cherry-pick that fix as well as enhancements to the scenario.
Towards #845.

Aside from fixing the syntax for https://github.com/swarm-game/swarm/pull/1706#discussion_r1442273107, this provides a good "before" example to showcase the fix in #1672.

    scripts/run-tests.sh --test-arguments '--pattern "1034-custom-attributes"'

and

    scripts/play.sh -i data/scenarios/Testing/1034-custom-attributes.yaml --autoplay --speed 1

![Screenshot from 2024-01-04 16-46-53](https://github.com/swarm-game/swarm/assets/261693/5e5a4435-1a36-4f59-bd6f-639c065baf2d)
2024-01-05 17:08:07 +00:00
Karl Ostmo
743ec13a1c
Eliminate trailing whitespace in all scenarios (#1710)
Towards #845

This is to avoid the undesirable transformation by `yq` of whitespace-preserving string fields into quoted one-line strings, described in https://github.com/swarm-game/swarm/pull/1706#discussion_r1442274007.

Command:

    find data/scenarios -type f -name '*.yaml' -print0 | xargs -0 --max-args 1 sed -i -e 's/[[:blank:]]\+$//'
2024-01-05 16:56:01 +00:00
Brent Yorgey
e350ab8ae7
update to LTS-21.25 (#1708)
21.25 uses GHC 9.4.8 instead of 9.4.7; the latest HLS release supports 9.4.8 but not 9.4.7.
2024-01-04 22:12:36 +00:00
Brent Yorgey
6fa150bdcb
fix color of trees in main logo (#1707) 2024-01-04 22:00:58 +00:00
Karl Ostmo
be34d0c027
sort module list (#1705) 2024-01-04 13:23:15 -08:00
Karl Ostmo
e4487aba0f
move 'Swarm.Language.*' modules to sublibrary (#1704) 2024-01-04 13:21:02 -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
Karl Ostmo
ea2863334a
snake game (#1699)
Demos use of a string to maintain a queue of coordinates.

![Screenshot from 2024-01-02 10-34-05](https://github.com/swarm-game/swarm/assets/261693/eaa24d48-40dc-4294-8243-2977caf4b79f)
2024-01-03 17:46:16 +00:00
Karl Ostmo
1da74a79dd
move ReadableIORef to util sublibrary (#1700)
As title.
2024-01-01 02:29:07 +00:00
Karl Ostmo
f6f01b264c
web sublibrary (#1697)
Towards #1043

Creates a new sub-library for the web service.  Also moved the `Swarm.App` module from the `swarm` library to the `swarm` executable.
2024-01-01 02:06:58 +00:00
Karl Ostmo
ccd64fcff8
return distance from path command (#1698)
Augments #836.

Should have access to the remaining distance, since it's available internally.  This will help in implementing #1696.
2023-12-31 20:14:47 +00:00
Karl Ostmo
358e60bb87
demo pixi.js (#1650)
Towards #1415.

Potential candidate for a web-based world display

Uses [pixi.js](https://pixijs.com/).

# Demo

1. Run swarm: `scripts/play.sh -i scenarios/Fun/horton.yaml --autoplay --speed 6`
1. Visit http://localhost:5357/play.html
2023-12-20 06:41:38 +00:00
Karl Ostmo
c48a46cac4
refactor for colors and grid type (#1692)
This is in preparation for both #1672 and #1650.

* Added some utility methods for color flattening
* The `Grid` type has a new home in `Area.hs` and now derives more instances
* `getTerrainEntityColor` is extracted from the `getDisplayColor` function
* Add a favicon to silence browser warnings
2023-12-18 15:07:47 +00:00
Karl Ostmo
7fa97b6461
short module descriptions (#1690)
Towards #1689

The [`Description:` field](https://haskell-haddock.readthedocs.io/en/latest/markup.html#the-module-description) in a module's toplevel haddock will be displayed on the Contents page.

![Screenshot from 2023-12-14 20-55-26](https://github.com/swarm-game/swarm/assets/261693/841f2834-8273-4394-b764-8f5f4479b9c4)
2023-12-16 19:05:27 +00:00
Karl Ostmo
53e6f35c0e
dim sum restaurant (#1686)
scripts/play.sh -i scenarios/Challenges/dimsum.yaml --autoplay

![Screenshot from 2023-12-13 22-39-53](https://github.com/swarm-game/swarm/assets/261693/d3039776-c819-4b1c-acfe-dbd0265e9cb0)
2023-12-15 04:49:54 +00:00
Karl Ostmo
eaa5551471
robot cardinal direction literals (#1685)
Closes #1679.

Split into two commits:
1. Parser and JSON schema changes
2. Update all scenario files (except `chess_horse.yaml`)
2023-12-14 21:04:44 +00:00
Karl Ostmo
b158251a20
pushable property (#1683)
Closes #1681
2023-12-13 21:32:55 +00:00
Karl Ostmo
13ae996306
recognize structures with rotation (#1678)
Closes #1644.

The `"recognize"` property in scenario `.yaml` files is changed from a boolean to a list of "up" directions.

The structure recognizer adds a rotated copy of each supported orientation to its automaton.  Rotational symmetry is accounted for to avoid duplicate work in the recognizer.

Also in this PR:
* Add cardinal directions to the JSON schema
* Tetromino packing challenge scenario

## Demos

    scripts/run-tests.sh --test-arguments '--pattern "1644-rotated"'

### Structures dialog

![Screenshot from 2023-12-10 18-47-01](https://github.com/swarm-game/swarm/assets/261693/3904b66e-dd22-455b-8b68-5913021f806a)

### Tetromino packing

    scripts/play.sh -i data/scenarios/Challenges/pack-tetrominoes.yaml --autoplay

![Screenshot from 2023-12-09 23-11-00](https://github.com/swarm-game/swarm/assets/261693/0ad7c0ce-3553-4ad5-a927-82bbfdbe63d8)
2023-12-13 21:21:08 +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
1bcd050780
Inventory requirements for child robots of system robots (#1677)
Towards #1664.

This PR adds a failing unit test.
2023-12-13 16:49:33 +00:00
Karl Ostmo
36a0046ece
unit test for recipe coverage (#1676)
Towards #1268

## Demo

    scripts/run-tests.sh --test-arguments '--pattern "Recipe coverage"'
2023-12-12 15:32:38 +00:00
Karl Ostmo
8e1fe17758
use strictly background color for terrain (#1674)
Towards #1662

Prerequisite for #1672

To allow a robot-occupied cell to take on the underlying terrain color as the background color of its cell, the terrain color must be representable strictly as a "background".  However, currently, the `dirt`, `stone`, and `grass` terrains are represented by a half-shaded **foreground** glyph upon `black` background.

Currently the ["Medium Shade" unicode character](https://www.compart.com/en/unicode/U+2592) (`▒`) is used  to "blend" a somewhat bright color with a black background, resulting in a moderately dark color in the terminal for `dirt`, `stone`, and `grass`.  However, these same dark colors are not reproducible in the 240-color scheme without this foreground+background blending trick; the closest approximations as a background-only or foreground-only color come out quite a bit lighter.

## Visual comparison

Using:

    scripts/play.sh -i creative --seed 2 --autoplay

| Before | After |
| --- | --- |
| ![Screenshot from 2023-12-03 23-33-15](https://github.com/swarm-game/swarm/assets/261693/edeeaeac-13e0-4641-9822-773fdb20f1d4) | ![Screenshot from 2023-12-03 23-32-36](https://github.com/swarm-game/swarm/assets/261693/ae5a5b5d-aa69-4580-b7e1-85eec21b4aeb) |

## Possible approaches

So, we need to decide whether to:
1. Accept the new lighter colors
2. Choose new, alternative terrain colors that may be darker given the 240-color palette
3. Abandon support for 240 colors and assume "full" color terminals
4. Abandon efforts to passthrough terrain color as background of robot cells
2023-12-12 04:08:32 +00:00
Karl Ostmo
938aa2cbce
split utils into sublibrary (#1675)
Towards #1043

This is the first of potentially more granular sub-library splits.
2023-12-07 17:21:03 +00:00
Karl Ostmo
b8d37a9364
extract doc generator to separate executable (#1671)
Closes #1443.

Also added `-Wunused-packages` to clean up dependencies.

## Demo

This still works as usual:

    stack run

Output editor keywords:

    stack run swarm-docs -- editors --emacs
2023-12-04 03:45:07 +00:00
Karl Ostmo
437f70418c
Move more code to Robots.hs, do not export private fields (#1669)
A continuation of #1667.

* Do not export `_viewCenter` or `_focusedRobotID`
* Move record initialization code to `Robot.hs` as `setRobotInfo`.
* `modifyViewCenter`, `unfocus`, `recalcViewCenter` now operate directly on `Robots` instead of `GameState`.
2023-12-03 22:31:35 +00:00
Karl Ostmo
536f1dcf47
Inherit parent robot display (#1670)
Closes #1663.

The status quo is that built-children of system robots are visible, even if the system robot is invisible.  So we preserve that behavior for now, with the potential to override it at some future point.  We don't yet have a definite need to make children of system robots invisible, but this PR does at least provide a mechanism to set the foreground and background of child robots (as a stopgap until #1230).

Tested with:

    scripts/play.sh -i scenarios/Challenges/Ranching/beekeeping.yaml --autoplay

| Before | After |
| --- | --- |
| ![Screenshot from 2023-12-01 17-31-00](https://github.com/swarm-game/swarm/assets/261693/9a9a49cb-fee5-424d-a748-9cb3c65ffe8f) | ![Screenshot from 2023-12-01 17-35-19](https://github.com/swarm-game/swarm/assets/261693/4da17e20-8f1a-46fc-ac9c-6154ccb7d4c7) |
2023-12-03 22:04:07 +00:00
Karl Ostmo
3094abd565
Offload subrecords of GameState to other modules (#1667)
This is a continuation of #1652.

Most of the sub-records are bundled into `Swarm.Game.State.Substate`, but we create a `Swarm.Game.State.Robot` module just for robots.

We introduce a `zoomRobots` function so that applicable functions can operate directly on `Robots` state instead of `GameState`.

## Size comparison

### Before

| File | Lines |
| --- | --- |
| `State.hs` | 1569 |

### After

| File | Lines |
| --- | --- |
| `State.hs` | 812 |
| `Substate.hs` | 497 |
| `Robot.hs` | 395 |
| `Config.hs` | 21 |
## For follow-up PR:
- [ ]  Remove exports of `_viewCenter` and `_focusedRobotID` from `Swarm.Game.State.Robot`
2023-11-30 21:57:39 +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
Karl Ostmo
e03251cc0b
beekeeping scenario (#1599)
Builds upon #1579

Requires player to constuct beehives to attract bees and make honey, which is then brewed as mead.

## Demo

    scripts/play.sh -i scenarios/Challenges/Ranching/beekeeping.yaml --autoplay

![image](https://github.com/swarm-game/swarm/assets/261693/f8c5c898-d865-4fe7-954d-c9e5b5f9a5c8)

Map:
![map](https://github.com/swarm-game/swarm/assets/261693/9c288edb-e71f-4a59-bd32-e1ecfdb1b60e)

## References

Mead hall inspiration: https://cartographyassets.com/assets/13507/the-mead-hall-of-the-clan-ulfgar-50-x-50/

![Mead-Hal-v1-No-Light-or-Shadow-with-grid-copy-scaled](https://github.com/swarm-game/swarm/assets/261693/a2d276f1-a522-499e-9a4b-7ce1df754107)
2023-11-28 03:39:28 +00:00
Karl Ostmo
44c2e607b3
Use a nonempty list for unchainFun (#1656)
Use a nonempty list for `unchainFun`
2023-11-22 21:57:42 +00:00