Skip to content

Commit

Permalink
let waiting take time for AI monsters; close #42
Browse files Browse the repository at this point in the history
  • Loading branch information
Mikolaj committed Jul 7, 2011
1 parent 5d1700f commit f04d77d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
8 changes: 6 additions & 2 deletions src/StrategyState.hs
Expand Up @@ -25,6 +25,8 @@ import qualified ItemKind
import Item import Item
import qualified Effect import qualified Effect


-- import Debug.Trace

strategy :: Actor -> State -> Perceptions -> Strategy (Action ()) strategy :: Actor -> State -> Perceptions -> Strategy (Action ())
strategy actor strategy actor
oldState@(State { scursor = cursor, oldState@(State { scursor = cursor,
Expand All @@ -34,6 +36,7 @@ strategy actor
lsmell = nsmap, lsmell = nsmap,
lmap = lmap } }) lmap = lmap } })
per = per =
-- trace (show time ++ ": " ++ show actor) $
strategy strategy
where where
Movable { mkind = mk, mloc = me, mdir = mdir, Movable { mkind = mk, mloc = me, mdir = mdir,
Expand Down Expand Up @@ -168,6 +171,7 @@ dirToAction actor tgt allowAttacks dir =
-- perform action -- perform action
tryWith (advanceTime actor) $ tryWith (advanceTime actor) $
-- if the following action aborts, we just advance the time and continue -- if the following action aborts, we just advance the time and continue
-- TODO: ensure time is taken for other aborted actions in this file
moveOrAttack allowAttacks True actor dir moveOrAttack allowAttacks True actor dir


onlyMoves :: (Dir -> Bool) -> Loc -> Strategy Dir -> Strategy Dir onlyMoves :: (Dir -> Bool) -> Loc -> Strategy Dir -> Strategy Dir
Expand All @@ -176,5 +180,5 @@ onlyMoves p l = only (\ x -> p (l `shift` x))
moveRandomly :: Strategy Dir moveRandomly :: Strategy Dir
moveRandomly = liftFrequency $ uniform moves moveRandomly = liftFrequency $ uniform moves


wait :: Strategy (Action ()) wait :: Actor -> Strategy (Action ())
wait = return $ return () wait actor = return $ advanceTime actor
2 changes: 1 addition & 1 deletion src/Turn.hs
Expand Up @@ -109,7 +109,7 @@ handleMonster actor =
-- Run the AI: choses an action from those given by the AI strategy. -- Run the AI: choses an action from those given by the AI strategy.
action <- action <-
liftIO $ rndToIO $ liftIO $ rndToIO $
frequency (head (runStrategy (strategy actor state per .| wait))) frequency (head (runStrategy (strategy actor state per .| wait actor)))
action action
handleMonsters handleMonsters


Expand Down

0 comments on commit f04d77d

Please sign in to comment.