Skip to content

Commit

Permalink
sow command
Browse files Browse the repository at this point in the history
  • Loading branch information
kostmo committed May 4, 2024
1 parent c2c1866 commit e3038e7
Show file tree
Hide file tree
Showing 16 changed files with 435 additions and 45 deletions.
3 changes: 2 additions & 1 deletion data/scenarios/Testing/00-ORDER.txt
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,5 @@ Achievements
1747-volume-command.yaml
1777-capability-cost.yaml
1775-custom-terrain.yaml
1642-biomes.yaml
1642-biomes.yaml
1533-sow-command.yaml
186 changes: 186 additions & 0 deletions data/scenarios/Testing/1533-sow-command.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,186 @@
version: 1
name: Sow command and spread
seed: 0
description: |
Demonstrate `sow` command and spreading growth with biome restrictions.
creative: false
attrs:
- name: clay
fg: "#444444"
bg: "#c2b280"
- name: wheat
fg: "#444444"
bg: "#F5DEB3"
- name: barley
fg: "#444444"
bg: "#F6E9B1"
- name: maize
fg: "#444444"
bg: "#FBEC5D"
- name: mint
bg: "#3EB489"
terrains:
- name: clay
attr: clay
description: |
Sandy soil
objectives:
- id: harvested
goal:
- |
Plant and harvest crops
condition: |
return false
solution: |
def doN = \n. \f. if (n > 0) {f; doN (n - 1) f} {}; end;
doN 6 move;
harvest;
doN 13 move;
turn right;
harvest;
doN 6 move;
sow "mint";
turn right;
doN 13 move;
sow "barley";
turn left;
doN 7 move;
sow "barley";
turn left;
doN 13 move;
sow "kudzu";
doN 6 move;
robots:
- name: base
dir: east
devices:
- branch predictor
- calculator
- comparator
- dictionary
- harvester
- logger
- seed spreader
- treads
inventory:
- [1, mint]
- [1, barley]
- [1, kudzu]
entities:
- name: wheat
display:
char: 'w'
attr: wheat
description:
- Grain
properties: [known, pickable, growable]
growth:
duration: [20, 30]
spread:
radius: 2
density: 0.3
biomes: [dirt, clay]
- name: barley
display:
char: 'b'
attr: barley
description:
- Grain
properties: [known, pickable, growable]
growth:
duration: [30, 50]
spread:
radius: 2
density: 0.3
biomes: [dirt, clay]
- name: corn
display:
char: 'c'
attr: maize
description:
- Animal feed
properties: [known, pickable, growable]
growth:
duration: [30, 60]
spread:
radius: 3
density: 0.1
biomes: [dirt, clay]
- name: kudzu
display:
char: 'k'
attr: plant
description:
- Dense, impassable plant.
properties: [known, unwalkable, growable]
growth:
duration: [30, 50]
spread:
radius: 1
density: 3
biomes: [dirt, clay]
- name: mint
display:
char: 'm'
attr: mint
description:
- Invasive
properties: [known, pickable, growable]
growth:
duration: [10, 50]
spread:
radius: 2
density: 0.6
biomes: [dirt, clay]
- name: seed spreader
display:
char: 's'
description:
- A handheld pouch with a manual crank to broadcast seeds evenly within a small radius
properties: [known]
capabilities: [sow]
known: [flower]
world:
default: [blank]
palette:
'.': [grass]
'B': [grass, null, base]
'd': [dirt]
'c': [clay]
'C': [dirt, corn]
'W': [clay, wheat]
upperleft: [-1, 1]
map: |
..........................
.ddddddddddd..ccccccccccc.
.ddddddddddd..ccccccccccc.
BdddddCddddd..cccccWccccc.
.ddddddddddd..ccccccccccc.
.ddddddddddd..ccccccccccc.
..........................
.ccccccccccc..ddddddddddd.
.ccccccccccc..ddddddddddd.
.ccccccccccc..ddddddddddd.
.ccccccccccc..ddddddddddd.
.ccccccccccc..ddddddddddd.
..........................
..........................
.ddddddddddd..ccccccccccc.
.ddddddddddd..ccccccccccc.
.ddddddddddd..ccccccccccc.
.ddddddddddd..ccccccccccc.
.ddddddddddd..ccccccccccc.
..........................
..........................
..........................
.ccccccccccc..ddddddddddd.
.ccccccccccc..ddddddddddd.
.ccccccccccc..ddddddddddd.
.ccccccccccc..ddddddddddd.
.ccccccccccc..ddddddddddd.
..........................
5 changes: 5 additions & 0 deletions data/schema/display.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@
"default": false,
"type": "boolean",
"description": "Whether the entity or robot should be invisible. Invisible entities and robots are not drawn, but can still be interacted with in otherwise normal ways. System robots are by default invisible."
},
"inheritable": {
"default": true,
"type": "boolean",
"description": "Whether robot children inherit this display."
}
}
}
42 changes: 34 additions & 8 deletions data/schema/entity.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,18 +55,44 @@
},
"growth": {
"default": null,
"type": "array",
"items": [

"oneOf": [
{
"name": "minimum",
"type": "number"
"$ref": "range.json",
"description": "For growable entities, a 2-tuple of integers specifying the minimum and maximum amount of time taken for one growth stage. The actual time for one growth stage will be chosen uniformly at random from this range; it takes two growth stages for an entity to be fully grown."
},
{
"name": "maximum",
"type": "number"
"type": "object",
"additionalProperties": false,
"properties": {
"mature": {
"default": null,
"type": "string",
"description": "The name of the entity which will be planted by the `sow` command."
},
"spread": {
"default": null,
"type": "object",
"additionalProperties": false,
"properties": {
"radius": {
"default": 1,
"type": "number",
"description": "Manhattan distance within which the entity may spread"
},
"density": {
"default": 0,
"type": "number",
"description": "Density within the range to seed"
}
}
},
"duration": {
"$ref": "range.json"
}
}
}
],
"description": "For growable entities, a 2-tuple of integers specifying the minimum and maximum amount of time taken for one growth stage. The actual time for one growth stage will be chosen uniformly at random from this range; it takes two growth stages for an entity to be fully grown."
]
},
"combustion": {
"type": "object",
Expand Down
1 change: 1 addition & 0 deletions editors/emacs/swarm-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
"turn"
"grab"
"harvest"
"sow"
"ignite"
"place"
"ping"
Expand Down
2 changes: 1 addition & 1 deletion editors/vim/swarm.vim
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
syn keyword Keyword def end let in require
syn keyword Builtins self parent base if inl inr case fst snd force undefined fail not format chars split charat tochar key
syn keyword Command noop wait selfdestruct move backup volume path push stride turn grab harvest ignite place ping give equip unequip make has equipped count drill use build salvage reprogram say listen log view appear create halt time scout whereami waypoint structure floorplan hastag tagmembers detect resonate density sniff chirp watch surveil heading blocked scan upload ishere isempty meet meetall whoami setname random run return try swap atomic instant installkeyhandler teleport as robotnamed robotnumbered knows
syn keyword Command noop wait selfdestruct move backup volume path push stride turn grab harvest sow ignite place ping give equip unequip make has equipped count drill use build salvage reprogram say listen log view appear create halt time scout whereami waypoint structure floorplan hastag tagmembers detect resonate density sniff chirp watch surveil heading blocked scan upload ishere isempty meet meetall whoami setname random run return try swap atomic instant installkeyhandler teleport as robotnamed robotnumbered knows
syn keyword Direction east north west south down forward left back right
syn keyword Type int text dir bool cmd void unit actor

Expand Down
2 changes: 1 addition & 1 deletion editors/vscode/syntaxes/swarm.tmLanguage.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
},
{
"name": "keyword.other",
"match": "\\b(?i)(self|parent|base|if|inl|inr|case|fst|snd|force|undefined|fail|not|format|chars|split|charat|tochar|key|noop|wait|selfdestruct|move|backup|volume|path|push|stride|turn|grab|harvest|ignite|place|ping|give|equip|unequip|make|has|equipped|count|drill|use|build|salvage|reprogram|say|listen|log|view|appear|create|halt|time|scout|whereami|waypoint|structure|floorplan|hastag|tagmembers|detect|resonate|density|sniff|chirp|watch|surveil|heading|blocked|scan|upload|ishere|isempty|meet|meetall|whoami|setname|random|run|return|try|swap|atomic|instant|installkeyhandler|teleport|as|robotnamed|robotnumbered|knows)\\b"
"match": "\\b(?i)(self|parent|base|if|inl|inr|case|fst|snd|force|undefined|fail|not|format|chars|split|charat|tochar|key|noop|wait|selfdestruct|move|backup|volume|path|push|stride|turn|grab|harvest|sow|ignite|place|ping|give|equip|unequip|make|has|equipped|count|drill|use|build|salvage|reprogram|say|listen|log|view|appear|create|halt|time|scout|whereami|waypoint|structure|floorplan|hastag|tagmembers|detect|resonate|density|sniff|chirp|watch|surveil|heading|blocked|scan|upload|ishere|isempty|meet|meetall|whoami|setname|random|run|return|try|swap|atomic|instant|installkeyhandler|teleport|as|robotnamed|robotnumbered|knows)\\b"
}
]
},
Expand Down
24 changes: 12 additions & 12 deletions src/swarm-engine/Swarm/Game/Step/Combustion.hs
Original file line number Diff line number Diff line change
Expand Up @@ -120,18 +120,6 @@ addCombustionBot inputEntity combustibility ts loc = do
where
Combustibility _ durationRange maybeCombustionProduct = combustibility

-- Triggers the ignition of the entity underfoot with some delay.
ignitionProgram :: Integer -> ProcessedTerm
ignitionProgram waitTime =
[tmQ|
wait $int:waitTime;
try {
ignite down;
noop;
} {};
selfdestruct
|]

-- | A system program for a "combustion robot", to burn an entity
-- after it is ignited.
--
Expand Down Expand Up @@ -228,3 +216,15 @@ addIgnitionBot ignitionDelay inputEntity ts loc =
False
emptyExceptions
ts

-- Triggers the ignition of the entity underfoot with some delay.
ignitionProgram :: Integer -> ProcessedTerm
ignitionProgram waitTime =
[tmQ|
wait $int:waitTime;
try {
ignite down;
noop;
} {};
selfdestruct
|]
Loading

0 comments on commit e3038e7

Please sign in to comment.