- haskell version of vindinium

This commit is contained in:
weiss
2020-04-19 05:44:41 +02:00
parent 9c39c1c0d5
commit 7dfe85a5fd
36 changed files with 1240 additions and 76 deletions

View File

@@ -0,0 +1,30 @@
module BotRunner
( Bot
, escapedInputInErrorPrefix
, runBot
) where
import Control.Monad
import System.IO
-- A Codingame bot where input and output have been abstracted out.
type Bot = IO String -> (String -> IO ()) -> IO ()
escapedInputInErrorPrefix :: String
escapedInputInErrorPrefix = "#"
-- Run a bot in the Codingame Arena (or IDE).
runBot
:: Bool -- Shall the bots input be echoed on stderr to be able to replay any game result?
-> Bot -- The bot.
-> IO ()
runBot echoInput bot = do
hSetBuffering stdout NoBuffering
bot readLine writeLine
where
readLine = do
line <- getLine
when echoInput $
hPutStrLn stderr (escapedInputInErrorPrefix ++ line)
return line
writeLine = putStrLn