Skip to content

Instantly share code, notes, and snippets.

data Program = Program {
input::[Int],
intCode::[Int],
status::Status,
-- ip: Instruction Pointer
ip::Int,
-- rb: Relative Base
rb::Int,
output::[Int]
} deriving(Show, Eq)
maybePos :: Int -> Maybe Int
maybePos x
| x < 0 = Nothing
| otherwise = Just x
thing :: Int -> [Int]
thing x = case maybePos x of
Nothing -> []
Just posX -> [posX]
import Control.Monad.State.Lazy (state, StateT)
import Control.Monad.IO.Class (liftIO)
import System.Console.ANSI (cursorUp)
playGame :: [Int] -> StateT Game IO Int
playGame inp = do
liveData <- stepGame inp
game <- get
--
data LiveData = LiveData {
-- x-coordinate of the ball - xb
xb::Int,
-- x-coordinate of the paddle - xp
xp::Int,
-- Game score - sc
sc::Int
} deriving(Show)
stepGame' :: [Int] -> Game -> (LiveData, Game)
import qualified Intcode as IC
import qualified Data.HashMap.Strict as HM
data Game = Game {
gameProg :: IC.Program,
gameDisplay :: Displ
} deriving(Show)
type Displ = HM.HashMap Tile Tid
type Tile = (Int, Int)