LambdaHack-0.11.0.1: A game engine library for tactical squad ASCII roguelike dungeon crawlers

Safe Haskell | None
Language | Haskell2010

Game.LambdaHack.Client.BfsM

Description

Breadth first search and related algorithms using the client monad.

Synopsis

- invalidateBfsAid :: MonadClient m => ActorId -> m ()
- invalidateBfsPathAid :: MonadClient m => ActorId -> m ()
- invalidateBfsLid :: MonadClient m => LevelId -> m ()
- invalidateBfsPathLid :: MonadClient m => Actor -> m ()
- invalidateBfsAll :: MonadClient m => m ()
- invalidateBfsPathAll :: MonadClient m => m ()
- createBfs :: MonadClientRead m => Bool -> Word8 -> ActorId -> m (Array BfsDistance)
- getCacheBfsAndPath :: MonadClient m => ActorId -> Point -> m (Array BfsDistance, Maybe AndPath)
- getCacheBfs :: MonadClient m => ActorId -> m (Array BfsDistance)
- getCachePath :: MonadClient m => ActorId -> Point -> m (Maybe AndPath)
- createPath :: MonadClient m => ActorId -> Target -> m TgtAndPath
- condBFS :: MonadClientRead m => ActorId -> m (Bool, Word8)
- furthestKnown :: MonadClient m => ActorId -> m Point
- closestUnknown :: MonadClient m => ActorId -> m (Maybe Point)
- closestSmell :: MonadClient m => ActorId -> m [(Int, (Point, Time))]
- data FleeViaStairsOrEscape
  - = ViaStairs
  - | ViaStairsUp
  - | ViaStairsDown
  - | ViaEscape
  - | ViaExit
  - | ViaNothing
  - | ViaAnything
- embedBenefit :: MonadClientRead m => FleeViaStairsOrEscape -> ActorId -> [(Point, ItemBag)] -> m [(Double, (Point, ItemBag))]
- closestTriggers :: MonadClient m => FleeViaStairsOrEscape -> ActorId -> m [(Int, (Point, (Point, ItemBag)))]
- condEnoughGearM :: MonadClientRead m => ActorId -> m Bool
- closestItems :: MonadClient m => ActorId -> m [(Int, (Point, ItemBag))]
- closestFoes :: MonadClient m => [(ActorId, Actor)] -> ActorId -> m [(Int, (ActorId, Actor))]
- closestStashes :: MonadClient m => ActorId -> m [(Int, (FactionId, Point))]
- oursExploringAssocs :: FactionId -> State -> [(ActorId, Actor)]
- closestHideout :: MonadClient m => ActorId -> m (Maybe (Point, Int))
- unexploredDepth :: MonadClientRead m => Bool -> LevelId -> m Bool
- updatePathFromBfs :: MonadClient m => Bool -> BfsAndPath -> ActorId -> Point -> m (Array BfsDistance, Maybe AndPath)

# Documentation

invalidateBfsAid :: MonadClient m => ActorId -> m () Source #

invalidateBfsPathAid :: MonadClient m => ActorId -> m () Source #

invalidateBfsLid :: MonadClient m => LevelId -> m () Source #

invalidateBfsPathLid :: MonadClient m => Actor -> m () Source #

invalidateBfsAll :: MonadClient m => m () Source #

invalidateBfsPathAll :: MonadClient m => m () Source #

createBfs :: MonadClientRead m => Bool -> Word8 -> ActorId -> m (Array BfsDistance) Source #

getCacheBfsAndPath :: MonadClient m => ActorId -> Point -> m (Array BfsDistance, Maybe AndPath) Source #

Get cached BFS array and path or, if not stored, generate and store first.

getCacheBfs :: MonadClient m => ActorId -> m (Array BfsDistance) Source #

Get cached BFS array or, if not stored, generate and store first.

getCachePath :: MonadClient m => ActorId -> Point -> m (Maybe AndPath) Source #

Get cached BFS path or, if not stored, generate and store first.

createPath :: MonadClient m => ActorId -> Target -> m TgtAndPath Source #

condBFS :: MonadClientRead m => ActorId -> m (Bool, Word8) Source #

furthestKnown :: MonadClient m => ActorId -> m Point Source #

Furthest (wrt paths) known position.

closestUnknown :: MonadClient m => ActorId -> m (Maybe Point) Source #

Closest reachable unknown tile position, if any.

Note: some of these tiles are behind suspect tiles and they are chosen in preference to more distant directly accessible unknown tiles. This is in principle OK, but in dungeons with few hidden doors AI is at a disadvantage (and with many hidden doors, it fares as well as a human that deduced the dungeon properties). Changing Bfs to accomodate all dungeon styles would be complex and would slow down the engine.

If the level has inaccessible open areas (at least from the stairs AI used) the level will be nevertheless here finally labeled as explored, to enable transition to other levels. We should generally avoid such levels, because digging and/or trying to find other stairs leading to disconnected areas is not KISS so we don't do this in AI, so AI is at a disadvantage.

If the closest unknown is more than 126 tiles away from the targeting actor, the level will marked as explored. We could complicate the code and not mark if the unknown is too far as opposed to inaccessible, but then if it is both too distant and inaccessible, AI would be permanently stuck on such levels. To cope with this, escapes need to be placed on open or small levels, or in dispersed enough that they don't appear in such potentially unexplored potions of caves. Other than that, this is rather harmless and hard to exploit, so let it be. The principled way to fix this would be to extend BFS to `Word16`, but then it takes too long to compute on maze levels, so we'd need to optimize hard for JS.

closestSmell :: MonadClient m => ActorId -> m [(Int, (Point, Time))] Source #

Finds smells closest to the actor, except under the actor, because actors consume smell only moving over them, not standing. Of the closest, prefers the newest smell.

data FleeViaStairsOrEscape Source #

Constructors

ViaStairs |
ViaStairsUp |
ViaStairsDown |
ViaEscape |
ViaExit |
ViaNothing |
ViaAnything |

#### Instances

Instances details

Show FleeViaStairsOrEscape Source # |
Instance details Defined in Game.LambdaHack.Client.BfsM Methods showsPrec :: Int -> FleeViaStairsOrEscape -> ShowS Source # show :: FleeViaStairsOrEscape -> String Source # showList :: [FleeViaStairsOrEscape] -> ShowS Source #
Eq FleeViaStairsOrEscape Source # |
Instance details Defined in Game.LambdaHack.Client.BfsM Methods (==) :: FleeViaStairsOrEscape -> FleeViaStairsOrEscape -> Bool Source # (/=) :: FleeViaStairsOrEscape -> FleeViaStairsOrEscape -> Bool Source #

embedBenefit :: MonadClientRead m => FleeViaStairsOrEscape -> ActorId -> [(Point, ItemBag)] -> m [(Double, (Point, ItemBag))] Source #

closestTriggers :: MonadClient m => FleeViaStairsOrEscape -> ActorId -> m [(Int, (Point, (Point, ItemBag)))] Source #

Closest (wrt paths) AI-triggerable tiles with embedded items. In AI, the level the actor is on is either explored or the actor already has a weapon equipped, so no need to explore further, he tries to find enemies on other levels, but before that, he triggers other tiles in hope of some loot or beneficial effect to enter next level with.

condEnoughGearM :: MonadClientRead m => ActorId -> m Bool Source #

Check whether the actor has enough gear to go look for enemies. We assume weapons in equipment are better than any among organs or at least provide some essential diversity. Disabled if, due to doctrine, actors follow leader and so would repeatedly move towards and away from stairs at leader change, depending on current leader's gear. Number of items of a single kind is ignored, because variety is needed.

closestItems :: MonadClient m => ActorId -> m [(Int, (Point, ItemBag))] Source #

Closest (wrt paths) items.

closestFoes :: MonadClient m => [(ActorId, Actor)] -> ActorId -> m [(Int, (ActorId, Actor))] Source #

Closest (wrt paths) enemy actors.

closestStashes :: MonadClient m => ActorId -> m [(Int, (FactionId, Point))] Source #

Closest (wrt paths) enemy or our unguarded stash locations. If it's ours, we want to guard it, it enemy, loot it. Neutral and friendly stashes not chased to avoid loops of bloodless takeovers.

oursExploringAssocs :: FactionId -> State -> [(ActorId, Actor)] Source #

closestHideout :: MonadClient m => ActorId -> m (Maybe (Point, Int)) Source #

Find the nearest walkable position in dark, if any. Deterministic, to let all friends gather up and defend in the same shelter. Ignore position underfoot.

unexploredDepth :: MonadClientRead m => Bool -> LevelId -> m Bool Source #

updatePathFromBfs :: MonadClient m => Bool -> BfsAndPath -> ActorId -> Point -> m (Array BfsDistance, Maybe AndPath) Source #