-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
better support for structure references
- Loading branch information
Showing
11 changed files
with
143 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
data/scenarios/Testing/_Validation/2164-recursive-structure.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
version: 1 | ||
name: Structure placement (recursive references) | ||
description: | | ||
Recursive structure references are not allowed. | ||
robots: | ||
- name: base | ||
loc: [2, 2] | ||
dir: east | ||
known: [] | ||
world: | ||
structures: | ||
- name: bigbox | ||
structure: | ||
structures: | ||
- name: bitpair | ||
structure: | ||
palette: | ||
'.': [stone, tree] | ||
placements: | ||
- src: minibox | ||
map: | | ||
. | ||
- name: minibox | ||
structure: | ||
palette: | ||
'.': [stone] | ||
placements: | ||
- src: bitpair | ||
map: | | ||
. | ||
placements: | ||
- src: smallbox | ||
- src: bitpair | ||
map: "" | ||
- name: smallbox | ||
structure: | ||
palette: | ||
'.': [grass] | ||
map: | | ||
. | ||
placements: | ||
- src: bigbox | ||
map: "" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
{-# LANGUAGE OverloadedStrings #-} | ||
|
||
-- | | ||
-- SPDX-License-Identifier: BSD-3-Clause | ||
-- | ||
-- Graph utilities shared by multiple aspects of scenarios | ||
module Swarm.Util.Graph ( | ||
isAcyclicGraph, | ||
failOnCyclicGraph, | ||
) where | ||
|
||
import Control.Monad (forM_) | ||
import Data.Graph (SCC (..), stronglyConnComp) | ||
import Data.List.NonEmpty qualified as NE | ||
import Data.Maybe (mapMaybe) | ||
import Data.Text (Text) | ||
import Data.Text qualified as T | ||
import Swarm.Util | ||
|
||
isAcyclicGraph :: [SCC a] -> Bool | ||
isAcyclicGraph = | ||
all isAcyclicVertex | ||
where | ||
isAcyclicVertex = \case | ||
AcyclicSCC _ -> True | ||
_ -> False | ||
|
||
getGraphCycles :: [SCC a] -> [[a]] | ||
getGraphCycles = | ||
mapMaybe getCycle | ||
where | ||
getCycle = \case | ||
AcyclicSCC _ -> Nothing | ||
CyclicSCC c -> Just c | ||
|
||
failOnCyclicGraph :: | ||
Ord key => | ||
Text -> | ||
(a -> Text) -> | ||
[(a, key, [key])] -> | ||
Either Text () | ||
failOnCyclicGraph graphType keyFunction gEdges = | ||
forM_ (NE.nonEmpty $ getGraphCycles $ stronglyConnComp gEdges) $ \cycles -> | ||
Left $ | ||
T.unwords | ||
[ graphType | ||
, "graph contains cycles!" | ||
, commaList $ | ||
NE.toList $ | ||
fmap (brackets . T.intercalate " -> " . fmap keyFunction) cycles | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters