File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 44-- version. It's up to you to figure out if the result is better than the
55-- input, and if you should re-run optimizations to find new occurrences of
66-- patterns.
7+ --
8+ -- WARNING: For now, these functions assume that there is only one nanobot!
79module Optimizations where
810
11+ import Control.Monad (forM )
12+
913import Trace
1014
15+ import Debug.Trace
16+
17+ -- | Returns all possible optimizations of a given command sequence.
18+ optimize :: [Command ] -> [[Command ]]
19+ optimize [] = []
20+ optimize cmds = go [cmds] [cmds]
21+ where
22+ go :: [[Command ]] -> [[Command ]] -> [[Command ]]
23+ go [] optimized = optimized
24+ go (t: stack) optimized =
25+ let
26+ new = map (\ f -> f t) optimizers
27+ new' = filter (/= t) new
28+ in go (new' ++ stack) (new' ++ optimized)
29+
30+ optimizers :: [[Command ] -> [Command ]]
31+ optimizers = [splitLMove, mergeSMoves]
32+
1133-- | Turns [LMove a b, Wait] into [SMove a, SMove b]
1234--
1335-- The latter consumes 4 less energy points than the former.
You can’t perform that action at this time.
0 commit comments