From 71847c879a2071a74193d3365dd58de2899d2103 Mon Sep 17 00:00:00 2001 From: Karl Ostmo Date: Tue, 17 Sep 2024 08:03:23 -0700 Subject: [PATCH] add datastructure --- src/swarm-scenario/Swarm/Game/Display.hs | 35 ++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/src/swarm-scenario/Swarm/Game/Display.hs b/src/swarm-scenario/Swarm/Game/Display.hs index c671cdb2b..2afae5b52 100644 --- a/src/swarm-scenario/Swarm/Game/Display.hs +++ b/src/swarm-scenario/Swarm/Game/Display.hs @@ -84,6 +84,41 @@ data ChildInheritance | DefaultDisplay deriving (Eq, Ord, Show, Generic, Hashable) +data Presence + = -- | present + X + | -- | absent + O + +data Neighbors a = Neighbors + { e :: a + , w :: a + , n :: a + , s :: a + } + +-- | For a center cell that itself is a boundary, +-- what should it be rendered as, given certain +-- neighbor combinations? +getBoundaryDisplay :: Neighbors Presence -> Maybe Char +getBoundaryDisplay = \case + Neighbors {e = O, w = O, n = O, s = O} -> Nothing + Neighbors {e = X, w = X, n = O, s = O} -> Just '─' + Neighbors {e = X, w = O, n = O, s = O} -> Just '─' + Neighbors {e = O, w = X, n = O, s = O} -> Just '─' + Neighbors {e = O, w = O, n = X, s = X} -> Just '│' + Neighbors {e = O, w = O, n = O, s = X} -> Just '│' + Neighbors {e = O, w = O, n = X, s = O} -> Just '│' + Neighbors {e = X, w = X, n = X, s = X} -> Just '┼' + Neighbors {e = O, w = X, n = O, s = X} -> Just '┐' + Neighbors {e = X, w = O, n = O, s = X} -> Just '┌' + Neighbors {e = O, w = X, n = X, s = O} -> Just '┘' + Neighbors {e = X, w = O, n = X, s = O} -> Just '└' + Neighbors {e = O, w = X, n = X, s = X} -> Just '┤' + Neighbors {e = X, w = O, n = X, s = X} -> Just '├' + Neighbors {e = X, w = X, n = X, s = O} -> Just '┴' + Neighbors {e = X, w = X, n = O, s = X} -> Just '┬' + -- | A record explaining how to display an entity in the TUI. data Display = Display { _defaultChar :: Char