sanity is now float
This commit is contained in:
@@ -9,7 +9,7 @@ import qualified Data.Sequence as S
|
|||||||
main :: IO ()
|
main :: IO ()
|
||||||
main = do
|
main = do
|
||||||
bundle
|
bundle
|
||||||
print $ sim1 (2,4)
|
-- print $ sim1 (2,4)
|
||||||
--test
|
--test
|
||||||
|
|
||||||
test :: IO ()
|
test :: IO ()
|
||||||
@@ -26,7 +26,7 @@ loop1 pos depth acc
|
|||||||
acc' = sim : acc
|
acc' = sim : acc
|
||||||
in loop1 sim (depth - 1) 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))
|
sim1 pos = (\(val, (Explorer _ pos _ _, _)) -> (val, pos)) (simulate board1 (Explorer 0 (0,0) 100 2, S.empty))
|
||||||
|
|
||||||
board1 :: Board
|
board1 :: Board
|
||||||
|
|||||||
@@ -57,16 +57,16 @@ bot readLine writeLine = do
|
|||||||
let param2 = read (input!!6) :: Int
|
let param2 = read (input!!6) :: Int
|
||||||
pure $ if entitytype == "WANDERER"
|
pure $ if entitytype == "WANDERER"
|
||||||
then WandererInput id (x,y) param0 param1 param2
|
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 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 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 explorers = S.drop 1 explorers'
|
||||||
let cmd = case S.lookup 1 explorers' of
|
let cmd = case S.lookup 1 explorers' of
|
||||||
Just hero ->
|
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"
|
then "PLAN"
|
||||||
else (\(_,(Explorer _ pos _ _, w)) -> moveToPos pos) $ simulate board (hero, wanderers)
|
else (\(_,(Explorer _ pos _ _, _)) -> moveToPos pos) $ simulate board (hero, wanderers)
|
||||||
Nothing -> "WAIT"
|
Nothing -> "WAIT"
|
||||||
putStrLn cmd
|
putStrLn cmd
|
||||||
|
|
||||||
|
|||||||
@@ -15,10 +15,10 @@ import Simulation.Lib
|
|||||||
searchDepth = 11
|
searchDepth = 11
|
||||||
|
|
||||||
-- TODO: Check if tailrec
|
-- TODO: Check if tailrec
|
||||||
simulate :: Board -> GameState -> (Int, GameState)
|
simulate :: Board -> GameState -> (Float, GameState)
|
||||||
simulate = simulateMove searchDepth
|
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)
|
simulateMove depth board state@(hero@(Explorer ownId pos sanity plans), enemies)
|
||||||
| depth == 0 =
|
| depth == 0 =
|
||||||
let state' = evalMove board state
|
let state' = evalMove board state
|
||||||
@@ -43,8 +43,8 @@ evalMove board state@(hero@(Explorer id pos sanity plans), enemies) = evalEnemie
|
|||||||
where
|
where
|
||||||
evalSanity :: GameState
|
evalSanity :: GameState
|
||||||
evalSanity
|
evalSanity
|
||||||
| any (< 3) $ fmap (dist pos) (fmap wandererPos enemies) = (Explorer id pos (sanity - 1) plans, enemies)
|
| any (< 3) $ fmap (dist pos) (fmap wandererPos enemies) = (Explorer id pos (sanity - 2) plans, enemies)
|
||||||
| otherwise = (Explorer id pos (sanity - 3) plans, enemies)
|
| otherwise = (Explorer id pos (sanity - 4.5) plans, enemies)
|
||||||
evalEffects :: GameState -> GameState
|
evalEffects :: GameState -> GameState
|
||||||
evalEffects state'@(hero'@(Explorer id' pos' sanity' plans'), enemies')
|
evalEffects state'@(hero'@(Explorer id' pos' sanity' plans'), enemies')
|
||||||
| entity == Empty = (hero', 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
|
-- retuns the evalutaion of the current move
|
||||||
-- executed if maximum depth is reached
|
-- executed if maximum depth is reached
|
||||||
evalGameState :: GameState -> Int
|
evalGameState :: GameState -> Float
|
||||||
evalGameState ((Explorer _ pos sanity plans), enemies) =
|
evalGameState ((Explorer _ pos sanity plans), enemies) =
|
||||||
sanity
|
sanity
|
||||||
-- enemyDist
|
-- enemyDist
|
||||||
|
|||||||
@@ -10,14 +10,14 @@ type Board = S.Seq (S.Seq BoardEntity)
|
|||||||
type Pos = (Int, Int)
|
type Pos = (Int, Int)
|
||||||
|
|
||||||
data EntityInput
|
data EntityInput
|
||||||
= ExplorerInput Int Pos Int Int
|
= ExplorerInput Int Pos Float Int
|
||||||
| WandererInput Int Pos Int Int Int
|
| WandererInput Int Pos Int Int Int
|
||||||
deriving (Show)
|
deriving (Show)
|
||||||
|
|
||||||
data Explorer = Explorer
|
data Explorer = Explorer
|
||||||
{ explorerId :: Int
|
{ explorerId :: Int
|
||||||
, explorerPos :: Pos
|
, explorerPos :: Pos
|
||||||
, explorerSanity :: Int
|
, explorerSanity :: Float
|
||||||
, plansLeft :: Int
|
, plansLeft :: Int
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user