From d46c9867dedc0805454b3d23244959013a6d6c1b Mon Sep 17 00:00:00 2001 From: Karl Ostmo Date: Thu, 31 Aug 2023 16:15:15 -0700 Subject: [PATCH] track total commands and steps --- src/Swarm/Game/Robot.hs | 16 +++++++++++++++- src/Swarm/Game/Step.hs | 7 ++++++- src/Swarm/TUI/View.hs | 4 ++++ 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/src/Swarm/Game/Robot.hs b/src/Swarm/Game/Robot.hs index 968c279c7a..fa8f20bdd2 100644 --- a/src/Swarm/Game/Robot.hs +++ b/src/Swarm/Game/Robot.hs @@ -62,6 +62,8 @@ module Swarm.Game.Robot ( activityCounts, tickStepBudget, tangibleCommandCount, + anyCommandCount, + lifetimeStepCount, -- ** Creation & instantiation mkRobot, @@ -172,6 +174,8 @@ data RobotPhase data ActivityCounts = ActivityCounts { _tickStepBudget :: Int , _tangibleCommandCount :: Int + , _anyCommandCount :: Int + , _lifetimeStepCount :: Int } deriving (Eq, Show, Generic, FromJSON, ToJSON) @@ -218,9 +222,17 @@ makeLensesNoSigs ''ActivityCounts -- can tell when the counter increments. tickStepBudget :: Lens' ActivityCounts Int --- | Total number of commands executed over robot's lifetime +-- | Total number of tangible commands executed over robot's lifetime tangibleCommandCount :: Lens' ActivityCounts Int +-- | Total number of commands executed over robot's lifetime +anyCommandCount :: Lens' ActivityCounts Int + +-- | Total number of CESK steps executed over robot's lifetime. +-- This could be thought of as "CPU cycles" consumed, and is labeled +-- as "cycles" in the F2 dialog in the UI. +lifetimeStepCount :: Lens' ActivityCounts Int + -- | With a robot template, we may or may not have a location. With a -- concrete robot we must have a location. type family RobotLocation (phase :: RobotPhase) :: Data.Kind.Type where @@ -508,6 +520,8 @@ mkRobot rid pid name descr loc dir disp m devs inv sys heavy ts = ActivityCounts { _tickStepBudget = 0 , _tangibleCommandCount = 0 + , _anyCommandCount = 0 + , _lifetimeStepCount = 0 } , _runningAtomic = False } diff --git a/src/Swarm/Game/Step.hs b/src/Swarm/Game/Step.hs index 308d0814bf..f094b4cc1b 100644 --- a/src/Swarm/Game/Step.hs +++ b/src/Swarm/Game/Step.hs @@ -523,7 +523,10 @@ stepRobot :: (Has (State GameState) sig m, Has (Lift IO) sig m) => Robot -> m Ro stepRobot r = do (r', cesk') <- runState (r & activityCounts . tickStepBudget -~ 1) (stepCESK (r ^. machine)) -- sendIO $ appendFile "out.txt" (prettyString cesk' ++ "\n") - return $ r' & machine .~ cesk' + return $ + r' + & machine .~ cesk' + & activityCounts . lifetimeStepCount +~ 1 -- | replace some entity in the world with another entity updateWorld :: @@ -1003,6 +1006,8 @@ execConst c vs s k = do when (isTangible c) $ activityCounts . tangibleCommandCount %= (+ 1) + activityCounts . anyCommandCount %= (+ 1) + -- Now proceed to actually carry out the operation. case c of Noop -> return $ Out VUnit s k diff --git a/src/Swarm/TUI/View.hs b/src/Swarm/TUI/View.hs index afb771f0c2..6d9ce002f0 100644 --- a/src/Swarm/TUI/View.hs +++ b/src/Swarm/TUI/View.hs @@ -628,6 +628,8 @@ robotsListWidget s = hCenter table , "Inventory" , "Status" , "Actions" + , "Commands" + , "Cycles" , "Log" ] headers = withAttr robotAttr . txt <$> applyWhen cheat ("ID" :) headings @@ -642,6 +644,8 @@ robotsListWidget s = hCenter table , padRight (Pad 1) (str $ show rInvCount) , statusWidget , str $ show $ robot ^. activityCounts . tangibleCommandCount + , str $ show $ robot ^. activityCounts . anyCommandCount + , str $ show $ robot ^. activityCounts . lifetimeStepCount , txt rLog ] idWidget = str $ show $ robot ^. robotID