Skip to content

Commit

Permalink
Start base with finite supply of basic robot parts (#361)
Browse files Browse the repository at this point in the history
There is no longer a list of "default devices" which can be generated out of thin air.

Closes #35.
  • Loading branch information
byorgey authored Jul 2, 2022
1 parent c98f7b0 commit 754ff5d
Show file tree
Hide file tree
Showing 11 changed files with 46 additions and 27 deletions.
6 changes: 3 additions & 3 deletions TUTORIAL.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,8 @@ build {make "curry"}
The info panel should automatically switch to showing your `logger`
device, with an error message at the bottom saying something like
```
build: this would require installing devices you don't have:
workbench
build: You do not have required devices, please obtain:
- workbench
```
This is telling you that in order to `build` a robot which has the right
capabilities to run this program, you would need to
Expand Down Expand Up @@ -189,7 +189,7 @@ Now let's use them:
```
build { turn left; m4; m }
```
This should build a robot that moves toward the green mass to the west.
This should build a robot that moves toward the west.
The base is still turned north, so the robot needs to turn left
to be oriented to the west. Once you have a compass to install on
the robot, you will be able to `turn west` directly.
Expand Down
8 changes: 4 additions & 4 deletions data/entities.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -613,13 +613,12 @@
capabilities: [grab, harvest]
properties: [portable]

- name: plasma cutter
- name: toolkit
display:
attr: device
char: 'P'
char: 'Ѣ'
description:
- "A plasma cutter uses a jet of hot plasma to cut through metal like
butter. Used via the 'salvage' command to cut apart old robots."
- "A toolkit can be used, via the 'salvage' command, to take apart old robots."
- "'salvage' takes no arguments. It looks for an inactive
robot (one which is not currently running a program) in the
current cell. If an inactive robot is found, its log (if any) is
Expand All @@ -637,6 +636,7 @@
- An extremely efficient solar panel, capable of generating sufficient power
from ambient starlight alone. A robot powered by one of these can operate any time,
including on cloudy days and at night.
capabilities: [power]
properties: [portable]

- name: drill
Expand Down
9 changes: 9 additions & 0 deletions data/recipes.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,15 @@
out:
- [1, metal drill]

- in:
- [1, box]
- [2, board]
- [4, copper pipe]
- [2, iron plate]
- [2, rubber]
out:
- [1, toolkit]

- in:
- [2, small motor]
- [8, iron plate]
Expand Down
2 changes: 1 addition & 1 deletion data/scenarios/Challenges/drill_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ robots:
devices:
- logger
- grabber
- plasma cutter
- toolkit
- 3D printer
inventory:
- [2, metal drill]
Expand Down
3 changes: 3 additions & 0 deletions data/scenarios/Tutorials/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ robots:
inventory:
- [10, logger]
- [10, compass]
- [10, solar panel]
- [10, grabber]
- [10, treads]
world:
default: [blank, none]
palette:
Expand Down
5 changes: 4 additions & 1 deletion data/scenarios/Tutorials/crash.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,10 @@ robots:
- [10, logger]
- [10, compass]
- [10, scanner]
- [10, plasma cutter]
- [10, toolkit]
- [10, solar panel]
- [10, treads]
- [10, grabber]
- name: secret
loc: [3, 0]
dir: [0, 0]
Expand Down
3 changes: 2 additions & 1 deletion data/scenarios/Tutorials/install.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ robots:
- compass
- grabber
inventory:
- [1, logger]
- [10, solar panel]
- [10, logger]
world:
default: [blank, none]
palette:
Expand Down
2 changes: 2 additions & 0 deletions data/scenarios/Tutorials/scan.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ robots:
- [10, logger]
- [10, compass]
- [10, scanner]
- [10, treads]
- [10, solar panel]
world:
default: [blank, none]
palette:
Expand Down
8 changes: 8 additions & 0 deletions data/scenarios/classic.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,16 @@ robots:
- grabber
- life support system
- logger
- toolkit
- solar panel
- workbench
inventory:
- [5, 3D printer]
- [100, treads]
- [70, grabber]
- [100, solar panel]
- [50, scanner]
- [5, toolkit]
world:
seed: null
offset: true
20 changes: 5 additions & 15 deletions src/Swarm/Game/Step.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1248,26 +1248,16 @@ execConst c vs s k = do
-- hopefully without duplicating too much code.
[VDelay cmd e] -> do
r <- get @Robot
em <- use entityMap
creative <- use creativeMode

pid <- use robotID

let -- Standard devices that are always installed.
-- XXX in the future, make a way to build these and just start the base
-- out with a large supply of each?
stdDeviceList =
["treads", "grabber", "solar panel", "scanner", "plasma cutter"]
stdDevices = S.fromList $ mapMaybe (`lookupEntityName` em) stdDeviceList
addStdDevs i = foldr insert i stdDevices

deviceSets <- checkRequiredDevices (addStdDevs $ r ^. robotInventory) cmd "You" FixByObtain
deviceSets <- checkRequiredDevices (r ^. robotInventory) cmd "You" FixByObtain

let devices =
stdDevices
`S.union` if creative -- if given a choice between required devices giving same capability
then S.unions deviceSets -- give them all in creative
else S.unions $ map (S.take 1) deviceSets -- give first one otherwise
if creative -- if given a choice between required devices giving same capability
then S.unions deviceSets -- give them all in creative
else S.unions $ map (S.take 1) deviceSets -- give first one otherwise

-- Pick a random display name.
displayName <- randomName
Expand Down Expand Up @@ -1295,7 +1285,7 @@ execConst c vs s k = do
-- Remove from the inventory any devices which were installed on the new robot,
-- if not in creative mode.
unless creative $
forM_ (devices `S.difference` stdDevices) $ \d ->
forM_ devices $ \d ->
robotInventory %= delete d

-- Flag the world for a redraw and return the name of the newly constructed robot.
Expand Down
7 changes: 5 additions & 2 deletions src/Swarm/Language/Capability.hs
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,15 @@ import Data.Data (Data)
import Data.Yaml
import GHC.Generics (Generic)

import Data.Bifunctor (first)
import Swarm.Language.Context
import Swarm.Language.Syntax

-- | Various capabilities which robots can have.
data Capability
= -- | Execute the 'Move' command
= -- | Be powered, i.e. execute anything at all
CPower
| -- | Execute the 'Move' command
CMove
| -- | Execute the 'Turn' command
--
Expand Down Expand Up @@ -141,7 +144,7 @@ type CapCtx = Ctx (Set Capability)
-- be safe in the sense that a robot with the indicated capabilities
-- will always be able to run the given program.
requiredCaps :: CapCtx -> Term -> (Set Capability, CapCtx)
requiredCaps ctx tm = case tm of
requiredCaps ctx tm = first (S.insert CPower) $ case tm of
-- First, at the top level, we have to keep track of the
-- capabilities needed by variables bound with the 'TDef' command.

Expand Down

0 comments on commit 754ff5d

Please sign in to comment.