Last active
August 29, 2015 14:00
-
-
Save NobbZ/11303420 to your computer and use it in GitHub Desktop.
Quick and dirty skelleton
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
| module Main (main) where | |
| import Control.Monad (unless) | |
| import Prelude hiding (Left, Right) | |
| import System.IO (BufferMode (NoBuffering), hSetBuffering, isEOF, | |
| stdout) | |
| type Stone = Int | |
| data Direction = Up | |
| | Right | |
| | Down | |
| | Left | |
| -- Main, was sonst? | |
| main :: IO () | |
| main = do | |
| hSetBuffering stdout NoBuffering -- stdout nicht Buffern! | |
| processInput respond -- Springe in Hauptschleife und rufe dort | |
| -- immer `respond` auf. | |
| -- Hauptschleife, liest die Eingabezeile und kümmert sich um die Ausgabe | |
| processInput :: (String -> Char) -> IO () | |
| processInput f = do | |
| finished <- isEOF | |
| unless finished $ do | |
| getLine >>= putChar . f | |
| processInput f | |
| ------------------------------------------------------------------------------- | |
| ------------------------------------------------------------------------------- | |
| respond :: String -> Char | |
| respond = dirToKey . makeMove . parseBoard | |
| dirToKey :: Direction -> Char | |
| dirToKey Up = 'n' | |
| dirToKey Down = 's' | |
| dirToKey Left = 'w' | |
| dirToKey Right = 'e' | |
| parseBoard :: String -> [[Stone]] | |
| parseBoard input = read (modifiedInput) :: [[Stone]] | |
| where | |
| modifiedInput = '[': (tail . init) input ++ "]" | |
| ------------------------------------------------------------------------------- | |
| ------------------------------------------------------------------------------- | |
| makeMove :: [[Stone]] -> Direction | |
| makeMove d = Up |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment