From 365a0e4ee2ec213c514d7d9ac10cb8111c2d1f76 Mon Sep 17 00:00:00 2001 From: Karl Ostmo Date: Tue, 13 Aug 2024 14:01:48 -0700 Subject: [PATCH] WIP: fails tests --- .../Topography/Structure/Recognition/Prep.hs | 14 +++++++++++--- .../Topography/Structure/Recognition/Type.hs | 1 + 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/swarm-topography/Swarm/Game/Scenario/Topography/Structure/Recognition/Prep.hs b/src/swarm-topography/Swarm/Game/Scenario/Topography/Structure/Recognition/Prep.hs index 66624a89c..84b6db93b 100644 --- a/src/swarm-topography/Swarm/Game/Scenario/Topography/Structure/Recognition/Prep.hs +++ b/src/swarm-topography/Swarm/Game/Scenario/Topography/Structure/Recognition/Prep.hs @@ -126,10 +126,18 @@ trimRow :: SymbolSequence a -> TrimmedRowContent a trimRow xs = TrimmedRowContent { fullRow = xs - , trimmed = xs - , leftDrops = 0 - , rightDrops = 0 + , trimmed = reverse remainingMiddleReversed + , leftDrops = nullPrefixLength + , rightDrops = nullSuffixLength } + where + (nullPrefixLength, remainingTail) = countDrops xs + (nullSuffixLength, remainingMiddleReversed) = countDrops $ reverse remainingTail + + countDrops s = + (length nulls, remainder) + where + (nulls, remainder) = span null s -- * Util diff --git a/src/swarm-topography/Swarm/Game/Scenario/Topography/Structure/Recognition/Type.hs b/src/swarm-topography/Swarm/Game/Scenario/Topography/Structure/Recognition/Type.hs index ab8a4128a..aaeac8437 100644 --- a/src/swarm-topography/Swarm/Game/Scenario/Topography/Structure/Recognition/Type.hs +++ b/src/swarm-topography/Swarm/Game/Scenario/Topography/Structure/Recognition/Type.hs @@ -143,6 +143,7 @@ data TrimmedRowContent a = TrimmedRowContent , leftDrops :: Int , rightDrops :: Int } + deriving (Show, Generic, ToJSON) -- | This wrapper facilitates naming the original structure -- (i.e. the "payload" for recognition)