Commit Graph

1000 Commits

Author SHA1 Message Date
Brent Yorgey
00b4e55115
New atomic syntax for blocks to be executed atomically (#553)
Provide a new `atomic` construct; when a robot is executing `atomic c` it is guaranteed that no other robots will execute any commands while the robot is executing `c`.  Maybe this isn't all that plausible physically, but I guess we can imagine that the base is in communication with all robots and implements some kind of global lock mechanism.

- Closes #479. `grabif`, `harvestif`, and `placeif` can all be implemented simply in terms of `atomic`.  For example:

    ```
    def grabif : string -> cmd bool = \thing.
      atomic (
        b <- ishere thing;
        if b {grab; return true} {return false}
      )
    end
    ```

    ```
    def placeif : string -> cmd bool = \thing.
      atomic (
        res <- scan down;
        if (res == inl ()) {place thing; return true} {return false}
      )
    end
    ```

- The argument to an `atomic` block must have type `cmd a` for some type `a`.
- `atomic` blocks have some restrictions to ensure they can't run for a long time:
    - No `def`, `let`, or lambdas are allowed
    - Variables can only be referenced if they are bound locally or have a "simple type" (= sums and products of base types; no `cmd`, `delay`, or function types)
    - Taken together, these ensure that computations can't be duplicated, and any variables referenced must contain simple data values which have already been evaluated, which means that an argument to `atomic` will have an execution time no more than linear in its length.
- `atomic` blocks also can't be nested, just because that seems weird and I don't know what the purpose would be
- `atomic` blocks may contain at most one "external" command which normally requires a tick to execute.  Allowing *e.g.* multiple `move` commands in an `atomic` block would be problematic: it would either mean that robots could use `atomic` blocks as a way to execute faster than normal, or that we would have to freeze other robots for multiple ticks while some robot executed its atomic block.  But typically, we want to do some kind of sensing command (which is an internal command that doesn't require a tick) + some external command.
- Relatedly, also refactored the notion of external/internal commands so that information is now stored in the `ConstInfo` record.  This means from now on we will be required to declare whether each new constant is internal or external; we hadn't been keeping up with the old definition of `takesTick` at all.
- Add the `rubber band` device which allows doing `atomic`, and make a recipe for it (`rubber` + `strange loop`).
    - This is a fairly simple recipe, but being able to do `atomic` early can be helpful for setting up automatic resource production pipelines.
2022-07-17 03:24:12 +00:00
Ondřej Šebek
31cb848330
List system robots when cheating (#546)
- show system robots when the `--cheat` flag was used and creative mode is on
- do not limit the distance to 32 when in creative mode
2022-07-15 12:15:30 +00:00
Brent Yorgey
c096f71354
Set replStatus to REPLWorking when running a file via --run (#554)
Fixes #333.
2022-07-15 10:38:31 +00:00
Tristan de Cacqueray
cf6693b2e5
Add a few more JSON instances (#494)
- part of #347
2022-07-11 01:58:21 +00:00
Brent Yorgey
eb205e61a9
Add require directive (#533)
Add new special syntactic forms `require <string literal>` to require a device to be installed, and `require <int literal> <string literal>` to require a certain number of a given entity in the inventory.

- Replace `Set Capability` with a new `Requirements` type which records various types of requirement.
- Refactor requirements checking into a new function `checkRequirements` which also does device set minimization (#508).  
- `reprogram` will now install extra devices or transfer extra inventory as necessary.
- Add a bunch of tests.
- Add new `installed` command, similar to `has`, which checks whether a given device is installed.

Closes #201.
Closes #508.
2022-07-05 22:36:06 +00:00
Brent Yorgey
f6917e3295
don't tab complete when there are no identifier chars typed (#543)
When the prompt was blank, it didn't tab complete; however, when there
were any characters typed at all, it found the "last word" (all
identifier characters at the end) and tried to match on it.  However,
if there were no identifier chars, the resulting empty "last word"
matched everything.

This fix now has a special case to check whether the `lastWord` is
blank, which also takes care of the original special case when the
prompt is completely empty.

Fixes #518.
2022-07-05 02:47:21 +00:00
Brent Yorgey
da4e0cec6c remove --flag=swarm:ci from feedback.yaml
Fixes #528.  I was being silly. No user will pass `--flag=swarm:ci`
when building with `stack`; I was doing so locally to get `-Werror` but
there's no particular reason I need to do that.
2022-07-04 21:33:04 -05:00
Ondřej Šebek
f2ad1322c9
Generate command table (#531)
Generate table for [Commands Cheat Sheet](https://github.com/swarm-game/swarm/wiki/Commands-Cheat-Sheet) Wiki.

- part of #344
2022-07-04 08:47:55 +00:00
Noah Yorgey
45755c47d3
Fix tab (#541)
a little thing related to tab completion. (#501)
2022-07-03 21:12:56 +00:00
lsmor
285ffba5a6
when pressed ^c restore repl (#535)
* when pressed ^c restore repl

* Restyled by fourmolu (#536)

Co-authored-by: Restyled.io <commits@restyled.io>

Co-authored-by: restyled-io[bot] <32688539+restyled-io[bot]@users.noreply.github.com>
Co-authored-by: Restyled.io <commits@restyled.io>
2022-07-03 20:35:37 +02:00
Brent Yorgey
754ff5d5c6
Start base with finite supply of basic robot parts (#361)
There is no longer a list of "default devices" which can be generated out of thin air.

Closes #35.
2022-07-02 01:00:33 +00:00
Brent Yorgey
c98f7b0442
Fix capitalization error in key 2022-07-01 17:36:48 -05:00
Brent Yorgey
880f922aa2 a few spelling fixes 2022-07-01 17:08:12 -05:00
Ondřej Šebek
3872c11509
Generate editor keywords (#526)
- part of #344
2022-07-01 18:44:09 +00:00
Brent Yorgey
ef6cba021b
make issue #508 test fail (as expected) (#522)
Just tweak the description for the GPS device so its hash changes, and
hence the order of the `GPS` and `Tardis` entities in a `Set Entity`
of devices that provide the `senseloc` capability.  When `GPS` comes
first, it will be chosen to provide the capability instead of
`Tardis`.
2022-07-01 09:14:16 +00:00
Ondřej Šebek
8652440607
Make GHC2021 extensions default (#520)
- closes #419
2022-07-01 09:07:41 +00:00
Brent Yorgey
43a5279265
Add new harvest command + harvester device (#503)
Make a new `harvester` device + `harvest` command.  The recipe for a `harvester` is 2 `board` + 2 `wooden gear` + 1 `box`, hence it can be made completely out of 3 `tree`s. (3 trees make 12 `board`s; 6 `board`s are for the `box`, 4 are to make the 2 `wooden gear`s).

The `harvester` device provides the `harvest` and `grab` capabilities, hence it supports both the `harvest` and `grab` commands. 
The `harvest` command now does exactly what the `grab` command used to do; the `grab` command works identically except that it never leaves behind a growing seed. 

As an aside, I am actually not sure what happens if you try to `build` a robot that uses both `grab` and `harvest` (but none of the other capabilities provided by a `grabber`).  Is the capability analysis smart enough to realize that it should just install a `harvester`, or might it end up installing both a `harvester` and a `grabber` unnecessarily?

Closes #490 (I split out another part of that issue into #502).  @xsebek , I know in #490 you expressed an objection to adding a `harvester` device so I'm curious what you think about this.
2022-06-30 20:36:50 +00:00
Brent Yorgey
1e40abc8d9
Tab completion (#501)
- Tab no longer cycles between panels (closes #316).  Now that we have keyboard shortcuts *and* you can click to move the panel focus, that seems sufficient.
- Basic REPL tab completion (closes #207).  Currently tries to complete against all reserved words and all in-scope names. Cycles through multiple completions when hitting Tab repeatedly.
2022-06-30 18:54:55 +00:00
Ondřej Šebek
b7136c7b10
Add scenario entites to game entity map (#515)
- fixes #509
2022-06-30 15:50:31 +00:00
Ondřej Šebek
3e2c0f486b Test logs for errors in every tick 2022-06-30 17:25:55 +02:00
Ondřej Šebek
f3ddf5aab9 Test installing devices with same capabilities 2022-06-30 17:25:55 +02:00
Ondřej Šebek
f1f776ed73
Let robots wait 1 without going to queue (#485)
- closes #475
2022-06-30 12:43:17 +00:00
Brent Yorgey
74ad23e322
More devices + recipes (#507)
- `I/O cable` device (idea: for communicating with adjacent robots; still need to design some commands to go with it)
- recipe for `grabber` device
- add `flash memory` recipe, adjust recipe for `counter`.  Closes #498 .
- add `3D printer` recipe.  Closes #496 .
- Progress towards #116 :
    - add `paper` and `PhD thesis` entities.
    - add `printer` device and recipe.
- Add recipe for `dictionary`.
2022-06-30 01:48:19 +00:00
Brent Yorgey
9e6dd964c0
Give the option to go immediately to the next challenge after completing one (#499)
- Always have `uiMenu` store the current menu; while playing, it represents the menu we should return to if we quit
- Get rid of `uiPrevMenu` which is thus no longer needed
- `NoMenu` is now only used to represent the scenario when we started via command-line options and thus should not return to a menu when we quit
- Add `uiPlaying` to denote whether we are playing the game or displaying a menu (`NoMenu` used to be used for this purpose)
- Only advance to the next scenario in the menu when actually completing the previous one.  For example if we start a scenario then quit before completing it, the menu will still be highlighting the same scenario.  But if we complete a scenario and then quit to the menu, the next one will be highlighted.
- Closes #355.  As [explained in a comment there](https://github.com/swarm-game/swarm/issues/355#issuecomment-1166343849), I think true "meta-scenarios" as originally described are needlessly complex. This PR gives us something that should be good enough: scenarios that have win conditions, placed in the same folder, can now be played sequentially without ever returning to the menu in between.
2022-06-28 16:20:23 +00:00
Brent Yorgey
68e53b595e
fix the way win conditions are checked (#505)
- Put the robot doing the checking in the robot map so it (or other
  robots) are able to look it up.  Fixes #504.
- Execute the win condition check *hypothetically*, in a copy of the
  game state which is discarded afterwards.  I kind of can't believe
  we weren't already doing this.  It used to be possible for the win
  condition check to actually modify the world! Thankfully none of
  the current tests actually used this evil power.
2022-06-28 14:23:21 +00:00
Brent Yorgey
c19a2b8745 bit (1) should also grow faster 2022-06-27 13:37:39 -05:00
Brent Yorgey
47a1168163 make bits grow faster
See discussion at #481.
2022-06-27 13:36:10 -05:00
Brent Yorgey
1505e9dc25
get rid of numeric prefixes on scenario files, use 00-ORDER.txt (#492)
Closes #463.
2022-06-25 22:33:55 +00:00
Tristan de Cacqueray
15b758ba70
Add branch filter to reduce CI cost (#488)
The action presently runs twice because both `on` conditions matche
every contributions. With this change, the push action only triggers
for the final push to the main branch, and the pull_requeste action
only triggers for PR made for the main branch.

That also means restyled PR should not trigger CI as they are made
for non main branches.
2022-06-25 21:07:03 +00:00
Tristan de Cacqueray
d40e068ad9
Display missing ingredients when making a recipe (#489)
Fixes #425
2022-06-25 20:10:33 +00:00
Tristan de Cacqueray
807c7ffeaf
Add robots list view (#483)
This change adds a new dialog to list the robots and their status.
2022-06-25 12:38:51 +00:00
Tristan de Cacqueray
d8a6ede787
Mark missing ingredients in the recipe list (#487)
This change improves the recipes list by marking which ingredients are missing from the focusedRobot.
2022-06-25 03:06:53 +00:00
Tristan de Cacqueray
c40b150103
Add available commands help (#458)
This change adds a new help panel with the list of recently acquired commands. The panels currently shows `command name :: command type signature`, for each newly available command.

Fixes https://github.com/swarm-game/swarm/issues/436
2022-06-24 23:48:11 +00:00
Ondřej Šebek
9b6eaef37b
Add generator for recipe dependencies (#476)
- add `generate` subparser to the executable
- create a generator for a Graphviz entity dependencies graph
- part of #344 

You can interactively test this with:
```bash
$ cabal run swarm:swarm -- generate recipes \
 | sed -n '/^digraph/,$p' > docs/recipes.dot
$ xdot docs/recipes.dot
```
2022-06-24 21:50:32 +00:00
Tristan de Cacqueray
b1cc6bd414
Make ctrl-q works inside modal (#482)
This change enables using <kbd>CTRL</kbd><kbd>q</kbd> to close a visible modal.
2022-06-24 20:21:17 +00:00
Brent Yorgey
d6344ef0f7
fix FUnionEnv stack leak (#473)
When adding an `FUnionEnv` frame to the stack, if there is already
another `FUnionEnv` frame present, combine them into a single
`FUnionEnv` instead of pushing another one.

Fixes #468.
2022-06-24 02:58:07 +00:00
Brent Yorgey
0813a1cad4
Tweaks to the REPL (#471)
- Reset REPL state when starting a new game.
- Change creative mode cheat shortcut to `^V`, so `^K` can again be used in the REPL to delete everything from the cursor position to the end of the line.
2022-06-23 16:24:34 +00:00
Brent Yorgey
5276be0eac
Tweaks to mines (#472)
- Give all mines priority 11 so they display on top of robots
- Make drilled mines known by adding them to the inventory with count 0
2022-06-23 13:09:20 +00:00
Ondřej Šebek
e85bf806c2
Retire raise command (#407)
- remove `raise` command
- rename `error` to `fail` - should suggest both that it is:
  - recoverable - can be caught with `try`
  - pure - `fail: string -> a` - so it can be used outside `cmd`

---

The problem with `raise` was that it was merely a specialized version of `error` (which was not limited to `cmd a`):
```
let raised: string -> cmd a = error in raised "ha"
```
I noticed this while making the list for #26.

On a meta-level, it also conflicts with the `raise` Haskell function we use to throw an error when a command (like `build`) fails.
2022-06-23 11:25:23 +00:00
Ondřej Šebek
8d07b667a9 Remove Goal entity mention
- remove mention of goal entity
- mention known entity
- explain yeilds and its limits
2022-06-23 08:45:06 +02:00
Ondřej Šebek
12344cd723
Add a few tutorial challenges (#411)
Start designing the tutorial (via challenges) so that we can figure out which new features are necessary.
2022-06-22 20:58:22 +00:00
Ondřej Šebek
a170379c93
Fix reprogram requiring wrong inventory (#464)
- fix the mistake introduces in #373
2022-06-22 15:13:49 +00:00
Tristan de Cacqueray
92c1d86cec
Add available recipes help (#441)
This change adds a new help panel with the list of recently acquired recipes.

Fixes #436
2022-06-22 14:27:45 +00:00
Brent Yorgey
7b9d8421cc
add goal field to scenarios (#450)
If there is a goal, immediately pop up a dialog with the goal, then
allow showing it any time afterwards with ^G.

See #356.
2022-06-22 12:47:14 +00:00
lsmor
23817a51ba
Find in repl (#439)
This PR solves #85. It's still a little bit rough since it only shows the last entry in history with the given text.

The solution if found is making the prompt a sum type. This allow to handle reple events differently depending on which mode the repl is. I've found this more difficult to implement than expected. The main problems I've found are 

- `UIState` is a huge data type. Maybe putting al repl-related stuff within the same record could improve things a little bit
- I think we can define a more complex Lenses, like `promptUpdateL` which can handle many parts of the logic. I think this is better than having a huge `handleREPLEvent` function.

 All of this would imply a big refactor tough.
2022-06-22 11:48:17 +00:00
Ondřej Šebek
077d208b7e
Return the obtained entity in grab (#461)
When grabbing entities that have `yield` property, I want to use what I obtained.
But `t <- grab` would give me "wavy water" instead of "water".

I noticed this because of our hack with known entities, which also use yield (#387).
2022-06-22 10:23:50 +00:00
Brent Yorgey
222a453b3b base should face the same way in classic & creative modes 2022-06-21 11:19:03 -05:00
Tristan de Cacqueray
7c9e46d033
Fix modal toggle to unpause the game (#452)
And also enable modal view toggle using the same key.

* Unpause the game after quitting a modal with Esc
* Handle FKey event before `uiModal` event to enable toggle through Fkey
2022-06-20 16:13:22 -05:00
Tristan de Cacqueray
7f4db06422
Handle mouse click event for robot inventory (#448)
This change makes inventory click select the inventory item.

Fixes #446
2022-06-20 19:16:44 +00:00
Brent Yorgey
8b8c16a71b
switch from U+2591 Light Shade to U+2592 Medium Shade (#449)
Some terminals (*e.g.* `gnome-terminal`) use the character to decide
how dark or light the color should be, rather than showing the
character itself (like *e.g.* `rxvt-unicode`).  Light Shade looks OK
in terminals that display the actual character, but too dark in
terminals that use it as a brightness hint.  Medium Shade seems to
look good (at least, IMO) in both.

See https://github.com/swarm-game/swarm/issues/196#issuecomment-1147298159 .
2022-06-20 17:56:55 +00:00