sanity is now float

This commit is contained in:
weiss
2020-04-28 15:28:38 +02:00
parent 6710080467
commit e296f4aa71
4 changed files with 12 additions and 12 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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
}