This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| data Program = Program { | |
| input::[Int], | |
| intCode::[Int], | |
| status::Status, | |
| -- ip: Instruction Pointer | |
| ip::Int, | |
| -- rb: Relative Base | |
| rb::Int, | |
| output::[Int] | |
| } deriving(Show, Eq) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| playGame :: [Int] -> StateT Game IO Int |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| playGame :: [Int] -> StateT Game Identity Int |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | |
| -- |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| mapM print $ gridDisplay displ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| gridDisplay :: Displ -> [[Char]] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| evalState runAmpsLoop $ newAmps intCode phases |