Skip to content

Commit

Permalink
Run data files (#730)
Browse files Browse the repository at this point in the history
- add fallback to the swarm data directory when the run file is not found
  • Loading branch information
xsebek authored Oct 6, 2022
1 parent 11b8ac7 commit 49c4405
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 40 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# Revision history for swarm

## **?.?.?.?** - ????-??-??

A bugfixing release for a few minor bugs that plagued the first release:

- fallback to to the swarm data directory when the `run` file is not found
- this caused the move tutorial to be unplayable because it tried to execute
`run "data/scenarios/Tutorials/move_system.sw"`
but now it should be fixed


## **0.1.0.0** - 2022-10-06

First Swarm release! Swarm already has:
Expand Down
2 changes: 1 addition & 1 deletion data/scenarios/Challenges/Mazes/loopy_maze.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ objectives:
return (not b)
} { return false }
solution: |
run "data/scenarios/Challenges/Mazes/loopy_maze_sol.sw"
run "scenarios/Challenges/Mazes/loopy_maze_sol.sw"
robots:
- name: base
dir: [0,1]
Expand Down
8 changes: 4 additions & 4 deletions data/scenarios/Challenges/hanoi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ objectives:
z <- ishere "blocked three";
return (x && y && z)
solution: |
run "data/scenarios/Challenges/hanoi-solution.sw"
run "scenarios/Challenges/hanoi-solution.sw"
robots:
- name: base
dir: [0,-1]
Expand Down Expand Up @@ -62,7 +62,7 @@ robots:
// 1. place noth of me is NOT empty
// then
// - lock X
run "data/scenarios/Challenges/hanoi-invariant.sw"
run "scenarios/Challenges/hanoi-invariant.sw"
- name: increasing
dir: [0,0]
system: true
Expand All @@ -79,7 +79,7 @@ robots:
// - place "OK"
// else
// - try to grab "OK"
run "data/scenarios/Challenges/hanoi-increasing.sw"
run "scenarios/Challenges/hanoi-increasing.sw"
- name: count
dir: [0,0]
system: true
Expand All @@ -94,7 +94,7 @@ robots:
// count all entities placed in columns
// the final count should be either 2 or 3
// place "two" or "three" at x=0 y=-6
run "data/scenarios/Challenges/hanoi-count.sw"
run "scenarios/Challenges/hanoi-count.sw"
entities:
- name: bottom tee
display:
Expand Down
4 changes: 2 additions & 2 deletions data/scenarios/Tutorials/crash.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ entities:
- If you have this, you win!
properties: [known, portable]
solution: |
run "data/scenarios/Tutorials/crash-solution.sw"
run "scenarios/Tutorials/crash-solution.sw"
robots:
- name: base
dir: [0,1]
Expand Down Expand Up @@ -66,7 +66,7 @@ robots:
invisible: true
system: true
program: |
run "data/scenarios/Tutorials/crash-secret.sw"
run "scenarios/Tutorials/crash-secret.sw"
known: [water, tree, mountain]
world:
default: [blank]
Expand Down
4 changes: 2 additions & 2 deletions data/scenarios/Tutorials/farming.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ objectives:
condition: |
try {as base {has "curry"}} {return false}
solution: |
run "data/scenarios/Tutorials/farming.sw";
run "data/scenarios/Tutorials/make_curry.sw";
run "scenarios/Tutorials/farming.sw";
run "scenarios/Tutorials/make_curry.sw";
robots:
- name: base
display:
Expand Down
58 changes: 29 additions & 29 deletions data/scenarios/Tutorials/move.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -213,35 +213,35 @@ robots:
system: true
display:
invisible: true
program: run "data/scenarios/Tutorials/move_system.sw"
program: run "scenarios/Tutorials/move_system.sw"
- name: 2P horizontal wall
system: true
display:
invisible: true
program: run "data/scenarios/Tutorials/move_system.sw"
program: run "scenarios/Tutorials/move_system.sw"
- name: 3P horizontal wall
system: true
display:
invisible: true
program: run "data/scenarios/Tutorials/move_system.sw"
program: run "scenarios/Tutorials/move_system.sw"
#################
## VERTICAL ##
#################
- name: 1P vertical wall
system: true
display:
invisible: true
program: run "data/scenarios/Tutorials/move_system.sw"
program: run "scenarios/Tutorials/move_system.sw"
- name: 2P vertical wall
system: true
display:
invisible: true
program: run "data/scenarios/Tutorials/move_system.sw"
program: run "scenarios/Tutorials/move_system.sw"
- name: 3P vertical wall
system: true
display:
invisible: true
program: run "data/scenarios/Tutorials/move_system.sw"
program: run "scenarios/Tutorials/move_system.sw"
#################
## CORNERS ##
#################
Expand All @@ -259,71 +259,71 @@ robots:
system: true
display:
invisible: true
program: run "data/scenarios/Tutorials/move_system.sw"
program: run "scenarios/Tutorials/move_system.sw"
- name: 2P lower left corner
system: true
display:
invisible: true
program: run "data/scenarios/Tutorials/move_system.sw"
program: run "scenarios/Tutorials/move_system.sw"
- name: 3P lower left corner
system: true
display:
invisible: true
program: run "data/scenarios/Tutorials/move_system.sw"
program: run "scenarios/Tutorials/move_system.sw"
#########
## B ##
#########
- name: 1P lower right corner
system: true
display:
invisible: true
program: run "data/scenarios/Tutorials/move_system.sw"
program: run "scenarios/Tutorials/move_system.sw"
- name: 2P lower right corner
system: true
display:
invisible: true
program: run "data/scenarios/Tutorials/move_system.sw"
program: run "scenarios/Tutorials/move_system.sw"
- name: 3P lower right corner
system: true
display:
invisible: true
program: run "data/scenarios/Tutorials/move_system.sw"
program: run "scenarios/Tutorials/move_system.sw"
#########
## C ##
#########
- name: 1P upper right corner
system: true
display:
invisible: true
program: run "data/scenarios/Tutorials/move_system.sw"
program: run "scenarios/Tutorials/move_system.sw"
- name: 2P upper right corner
system: true
display:
invisible: true
program: run "data/scenarios/Tutorials/move_system.sw"
program: run "scenarios/Tutorials/move_system.sw"
- name: 3P upper right corner
system: true
display:
invisible: true
program: run "data/scenarios/Tutorials/move_system.sw"
program: run "scenarios/Tutorials/move_system.sw"
#########
## D ##
#########
- name: 1P upper left corner
system: true
display:
invisible: true
program: run "data/scenarios/Tutorials/move_system.sw"
program: run "scenarios/Tutorials/move_system.sw"
- name: 2P upper left corner
system: true
display:
invisible: true
program: run "data/scenarios/Tutorials/move_system.sw"
program: run "scenarios/Tutorials/move_system.sw"
- name: 3P upper left corner
system: true
display:
invisible: true
program: run "data/scenarios/Tutorials/move_system.sw"
program: run "scenarios/Tutorials/move_system.sw"
#################
## SEPARATORS ##
#################
Expand All @@ -332,34 +332,34 @@ robots:
system: true
display:
invisible: true
program: run "data/scenarios/Tutorials/move_system.sw"
program: run "scenarios/Tutorials/move_system.sw"
- name: 1S up and horizontal wall
system: true
display:
invisible: true
program: run "data/scenarios/Tutorials/move_system.sw"
program: run "scenarios/Tutorials/move_system.sw"
# 2
- name: 2S left and vertical wall
system: true
display:
invisible: true
program: run "data/scenarios/Tutorials/move_system.sw"
program: run "scenarios/Tutorials/move_system.sw"
- name: 2S up and horizontal wall
system: true
display:
invisible: true
program: run "data/scenarios/Tutorials/move_system.sw"
program: run "scenarios/Tutorials/move_system.sw"
# 3
- name: 3S left and vertical wall
system: true
display:
invisible: true
program: run "data/scenarios/Tutorials/move_system.sw"
program: run "scenarios/Tutorials/move_system.sw"
- name: 3S down and horizontal wall
system: true
display:
invisible: true
program: run "data/scenarios/Tutorials/move_system.sw"
program: run "scenarios/Tutorials/move_system.sw"
#################
## GATES ##
#################
Expand All @@ -376,30 +376,30 @@ robots:
system: true
display:
invisible: true
program: run "data/scenarios/Tutorials/move_system.sw"
program: run "scenarios/Tutorials/move_system.sw"
- name: 3G
system: true
display:
invisible: true
program: run "data/scenarios/Tutorials/move_system.sw"
program: run "scenarios/Tutorials/move_system.sw"
#################
## GARDENERS ##
#################
- name: 1P flower
system: true
display:
invisible: true
program: run "data/scenarios/Tutorials/move_system.sw"
program: run "scenarios/Tutorials/move_system.sw"
- name: 2P flower
system: true
display:
invisible: true
program: run "data/scenarios/Tutorials/move_system.sw"
program: run "scenarios/Tutorials/move_system.sw"
- name: 3P flower
system: true
display:
invisible: true
program: run "data/scenarios/Tutorials/move_system.sw"
program: run "scenarios/Tutorials/move_system.sw"
entities:
- name: Win
display:
Expand Down
7 changes: 5 additions & 2 deletions src/Swarm/Game/Step.hs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ import Data.List qualified as L
import Data.List.NonEmpty (NonEmpty ((:|)))
import Data.List.NonEmpty qualified as NE
import Data.Map qualified as M
import Data.Maybe (fromMaybe, isNothing, listToMaybe)
import Data.Maybe (catMaybes, fromMaybe, isNothing, listToMaybe)
import Data.Sequence qualified as Seq
import Data.Set (Set)
import Data.Set qualified as S
Expand Down Expand Up @@ -1418,7 +1418,10 @@ execConst c vs s k = do
-- "./path/to/file.sw" and "./path/to/file"
Run -> case vs of
[VText fileName] -> do
mf <- sendIO $ mapM readFileMay [into fileName, into $ fileName <> ".sw"]
let filePath = into @String fileName
sData <- sendIO $ getDataFileNameSafe filePath
sDataSW <- sendIO $ getDataFileNameSafe (filePath <> ".sw")
mf <- sendIO $ mapM readFileMay $ [filePath, filePath <> ".sw"] <> catMaybes [sData, sDataSW]

f <- msum mf `isJustOrFail` ["File not found:", fileName]

Expand Down

0 comments on commit 49c4405

Please sign in to comment.