Skip to content

Commit

Permalink
let monsters push through actors if chasing a target
Browse files Browse the repository at this point in the history
  • Loading branch information
Mikolaj committed Apr 8, 2011
1 parent 4c364f8 commit 0c8d8a9
Showing 1 changed file with 15 additions and 14 deletions.
29 changes: 15 additions & 14 deletions src/StrategyState.hs
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -95,44 +95,45 @@ strategy actor
onlySensible = onlyMoves (\ l -> accessibleHere l || openableHere l) me onlySensible = onlyMoves (\ l -> accessibleHere l || openableHere l) me
greedyMonster = niq mk < 5 greedyMonster = niq mk < 5
focusedMonster = niq mk > 10 focusedMonster = niq mk > 10
pushyMonster = not $ nsight mk
smells = smells =
L.map fst $ L.map fst $
L.sortBy (\ (_, s1) (_, s2) -> compare s2 s1) $ L.sortBy (\ (_, s1) (_, s2) -> compare s2 s1) $
L.filter (\ (_, s) -> s > 0) $ L.filter (\ (_, s) -> s > 0) $
L.map (\ x -> (x, nsmap ! (me `shift` x) - time `max` 0)) moves L.map (\ x -> (x, nsmap ! (me `shift` x) - time `max` 0)) moves
fromDir d = dirToAction actor newTgt `liftM` d fromDir allowAttacks d = dirToAction actor newTgt allowAttacks `liftM` d


strategy = strategy =
fromDir (onlyFoe moveFreely) fromDir True (onlyFoe moveFreely)
.| (greedyMonster && lootHere me) .=> actionPickup .| (greedyMonster && lootHere me) .=> actionPickup
.| fromDir (onlySensible moveTowards) .| nsight mk .=> fromDir False moveTowards
.| lootHere me .=> actionPickup .| lootHere me .=> actionPickup
.| fromDir (onlySensible moveAround) .| fromDir True moveAround
actionPickup = return $ actorPickupItem actor actionPickup = return $ actorPickupItem actor
moveTowards = moveTowards =
(if pushyMonster then id else onlyUnoccupied) $ onlySensible $
nsight mk .=> towardsFoe moveFreely onlyUnoccupied (towardsFoe moveFreely)
.| towardsFoe moveFreely
moveAround = moveAround =
(if pushyMonster then id else onlyUnoccupied) $ onlySensible $
nsmell mk .=> foldr (.|) reject (L.map return smells) (if nsight mk then onlyUnoccupied else id) $
.| onlyOpenable moveFreely nsmell mk .=> foldr (.|) reject (L.map return smells)
.| moveFreely .| onlyOpenable moveFreely
.| moveFreely
moveFreely = onlyLoot moveRandomly moveFreely = onlyLoot moveRandomly
.| niq mk > 15 .=> onlyKeepsDir 0 moveRandomly .| niq mk > 15 .=> onlyKeepsDir 0 moveRandomly
.| niq mk > 10 .=> onlyKeepsDir 1 moveRandomly .| niq mk > 10 .=> onlyKeepsDir 1 moveRandomly
.| niq mk > 5 .=> onlyKeepsDir 2 moveRandomly .| niq mk > 5 .=> onlyKeepsDir 2 moveRandomly
.| moveRandomly .| moveRandomly


dirToAction :: Actor -> Target -> Dir -> Action () dirToAction :: Actor -> Target -> Bool -> Dir -> Action ()
dirToAction actor tgt dir = dirToAction actor tgt allowAttacks dir =
assert (dir /= (0,0)) $ do assert (dir /= (0,0)) $ do
-- set new direction -- set new direction
updateAnyActor actor $ \ m -> m { mdir = Just dir, mtarget = tgt } updateAnyActor actor $ \ m -> m { mdir = Just dir, mtarget = tgt }
-- 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
moveOrAttack True True actor dir moveOrAttack allowAttacks True actor dir


onlyMoves :: (Dir -> Bool) -> Loc -> Strategy Dir -> Strategy Dir onlyMoves :: (Dir -> Bool) -> Loc -> Strategy Dir -> Strategy Dir
onlyMoves p l = only (\ x -> p (l `shift` x)) onlyMoves p l = only (\ x -> p (l `shift` x))
Expand Down

0 comments on commit 0c8d8a9

Please sign in to comment.