diff --git a/haskell/code-of-kutulu/app/Main.hs b/haskell/code-of-kutulu/app/Main.hs index 45d3999..d992a35 100644 --- a/haskell/code-of-kutulu/app/Main.hs +++ b/haskell/code-of-kutulu/app/Main.hs @@ -9,7 +9,7 @@ import qualified Data.Sequence as S main :: IO () main = do bundle - print $ sim1 (2,4) + -- print $ sim1 (2,4) --test test :: IO () @@ -26,7 +26,7 @@ loop1 pos depth acc acc' = sim : acc in loop1 sim (depth - 1) acc' -sim1 :: Pos -> (Int, Pos) +sim1 :: Pos -> (Float, Pos) sim1 pos = (\(val, (Explorer _ pos _ _, _)) -> (val, pos)) (simulate board1 (Explorer 0 (0,0) 100 2, S.empty)) board1 :: Board diff --git a/haskell/code-of-kutulu/src/Player.hs b/haskell/code-of-kutulu/src/Player.hs index 15ca915..e2c36cc 100644 --- a/haskell/code-of-kutulu/src/Player.hs +++ b/haskell/code-of-kutulu/src/Player.hs @@ -57,16 +57,16 @@ bot readLine writeLine = do let param2 = read (input!!6) :: Int pure $ if entitytype == "WANDERER" then WandererInput id (x,y) param0 param1 param2 - else ExplorerInput id (x,y) param0 param1 + else ExplorerInput id (x,y) (fromIntegral param0) param1 let explorers' = fmap (\(ExplorerInput a b c d) -> Explorer a b c d) $ S.filter isExplorer entities let wanderers = fmap (\(WandererInput a b c d e) -> Wanderer a b c d e) $ S.filter (not . isExplorer) entities let explorers = S.drop 1 explorers' let cmd = case S.lookup 1 explorers' of Just hero -> - if (all (> 6) $ fmap ((dist $ explorerPos hero) . wandererPos) wanderers) && plansLeft hero > 0 && explorerSanity hero `div` plansLeft hero < 100 + if (all (> 6) $ fmap ((dist $ explorerPos hero) . wandererPos) wanderers) && plansLeft hero > 0 && explorerSanity hero / (fromIntegral $ plansLeft hero) < 100 then "PLAN" - else (\(_,(Explorer _ pos _ _, w)) -> moveToPos pos) $ simulate board (hero, wanderers) + else (\(_,(Explorer _ pos _ _, _)) -> moveToPos pos) $ simulate board (hero, wanderers) Nothing -> "WAIT" putStrLn cmd diff --git a/haskell/code-of-kutulu/src/Simulation/Board.hs b/haskell/code-of-kutulu/src/Simulation/Board.hs index c9cd60e..b3aa4d4 100644 --- a/haskell/code-of-kutulu/src/Simulation/Board.hs +++ b/haskell/code-of-kutulu/src/Simulation/Board.hs @@ -15,10 +15,10 @@ import Simulation.Lib searchDepth = 11 -- TODO: Check if tailrec -simulate :: Board -> GameState -> (Int, GameState) +simulate :: Board -> GameState -> (Float, GameState) simulate = simulateMove searchDepth -simulateMove :: Int -> Board -> GameState -> (Int, GameState) +simulateMove :: Int -> Board -> GameState -> (Float, GameState) simulateMove depth board state@(hero@(Explorer ownId pos sanity plans), enemies) | depth == 0 = let state' = evalMove board state @@ -43,8 +43,8 @@ evalMove board state@(hero@(Explorer id pos sanity plans), enemies) = evalEnemie where evalSanity :: GameState evalSanity - | any (< 3) $ fmap (dist pos) (fmap wandererPos enemies) = (Explorer id pos (sanity - 1) plans, enemies) - | otherwise = (Explorer id pos (sanity - 3) plans, enemies) + | any (< 3) $ fmap (dist pos) (fmap wandererPos enemies) = (Explorer id pos (sanity - 2) plans, enemies) + | otherwise = (Explorer id pos (sanity - 4.5) plans, enemies) evalEffects :: GameState -> GameState evalEffects state'@(hero'@(Explorer id' pos' sanity' plans'), enemies') | entity == Empty = (hero', enemies') @@ -64,7 +64,7 @@ evalMove board state@(hero@(Explorer id pos sanity plans), enemies) = evalEnemie -- retuns the evalutaion of the current move -- executed if maximum depth is reached -evalGameState :: GameState -> Int +evalGameState :: GameState -> Float evalGameState ((Explorer _ pos sanity plans), enemies) = sanity -- enemyDist diff --git a/haskell/code-of-kutulu/src/Simulation/Data.hs b/haskell/code-of-kutulu/src/Simulation/Data.hs index ce3b1db..6554739 100644 --- a/haskell/code-of-kutulu/src/Simulation/Data.hs +++ b/haskell/code-of-kutulu/src/Simulation/Data.hs @@ -10,14 +10,14 @@ type Board = S.Seq (S.Seq BoardEntity) type Pos = (Int, Int) data EntityInput - = ExplorerInput Int Pos Int Int + = ExplorerInput Int Pos Float Int | WandererInput Int Pos Int Int Int deriving (Show) data Explorer = Explorer { explorerId :: Int , explorerPos :: Pos - , explorerSanity :: Int + , explorerSanity :: Float , plansLeft :: Int }