Class SimulationEngine


  • public final class SimulationEngine
    extends java.lang.Object
    Generic Old School RuneScape simulation engine designed for high-frequency decision search.
    • Constructor Detail

      • SimulationEngine

        public SimulationEngine()
    • Method Detail

      • createState

        public SimulationState createState​(SimulationSnapshot snapshot)
        Creates a fresh mutable simulation state from an immutable snapshot.
        Parameters:
        snapshot - immutable simulation input.
        Returns:
        mutable state for stepping and branching.
      • simulateTickCopy

        public SimulationState simulateTickCopy​(SimulationState state,
                                                SimulationAction playerAction)
        Copies the provided state and simulates a single tick on the copy.
        Parameters:
        state - The state to copy
        playerAction - The player action to simulate
        Returns:
        SimulationState the copied simulation state
      • simulateTick

        public SimulationState simulateTick​(SimulationState state,
                                            SimulationAction playerAction)
        Simulates one game tick in-place: apply player action, then move NPCs.
        Parameters:
        state - The current state of the simulation
        playerAction - The player action to simulate
        Returns:
        SimulationState the simulation state after the single tick
      • simulateTicks

        public SimulationState simulateTicks​(SimulationState state,
                                             java.util.List<SimulationAction> playerActions,
                                             int ticks)
        Simulates many ticks using an ordered action list. If actions run out, WAIT is used.
        Parameters:
        state - The current state of the simulation
        playerActions - The list of player action to simulate
        ticks - The number of ticks to simulate
        Returns:
        SimulationState the simulation state after the ticks have been simulated
      • canApplyPlayerAction

        public boolean canApplyPlayerAction​(SimulationState state,
                                            SimulationAction action)
        Returns true when a single player step/run action is currently legal.
        Parameters:
        state - The state of the simulation
        action - The action to simulate
        Returns:
        Boolean true when a single player step/run action is currently legal.
      • hasNpcLineOfSightToPlayer

        public boolean hasNpcLineOfSightToPlayer​(SimulationState state,
                                                 int npcSlot)
        Returns true when the given NPC currently has line of sight to the local simulated player.
        Parameters:
        state - The state of the simulation
        npcSlot - The npc slot to check line of sight for
        Returns:
        Boolean, true when the given NPC currently has line of sight to the local simulated player.
      • countNpcsWithLineOfSightToPlayer

        public int countNpcsWithLineOfSightToPlayer​(SimulationState state)
        Counts currently active NPCs that have line of sight to the player.
        Parameters:
        state - simulation state.
        Returns:
        number of threatening NPCs with current LoS.
      • getNpcLineOfSightTiles

        public java.util.List<net.runelite.api.coords.WorldPoint> getNpcLineOfSightTiles​(SimulationState state,
                                                                                         int npcSlot)
        Returns the line-of-sight tile set for the specified NPC using its configured attack range.
        Parameters:
        state - The state of the simulation
        npcSlot - The npc slot to check line of sight for
        Returns:
        List, the tiles that the NPC has line of sight to
      • getNpcLineOfSightTiles

        public java.util.List<net.runelite.api.coords.WorldPoint> getNpcLineOfSightTiles​(SimulationState state,
                                                                                         int npcSlot,
                                                                                         int range)
        Returns the line-of-sight tile set for the specified NPC using an explicit range override.
        Parameters:
        state - The state of the simulation
        npcSlot - The npc slot to check line of sight for
        range - The range of the NPC (how far it can see)
        Returns:
        List The tiles that the NPC has line of sight to
      • isPlayerTileSafe

        public boolean isPlayerTileSafe​(SimulationState state)
        Parameters:
        state - simulation state.
        Returns:
        true when no active NPC has current line of sight to the player.
      • hasLineOfSight

        public boolean hasLineOfSight​(SimulationState state,
                                      net.runelite.api.coords.WorldPoint source,
                                      int sourceSize,
                                      net.runelite.api.coords.WorldPoint target,
                                      int range,
                                      boolean sourceIsNpc)
        World-point overload for line-of-sight checks.
        Parameters:
        state - simulation state.
        source - source tile.
        sourceSize - source footprint size.
        target - target tile.
        range - max allowed LoS range.
        sourceIsNpc - true when source is an NPC footprint anchor.
        Returns:
        true when LoS exists under range/footprint constraints.
      • predictNpcGreedyPathToPlayer

        public java.util.List<net.runelite.api.coords.WorldPoint> predictNpcGreedyPathToPlayer​(SimulationState state,
                                                                                               int npcSlot,
                                                                                               int maxSteps)
        Predicts the NPC's greedy movement path toward the simulated player without mutating the state.
        Parameters:
        state - The current state of the simulation
        npcSlot - The NPC to predict pathing for
        maxSteps - The maximum number of pathing steps to predict
        Returns:
        List of points for the NPC's greedy path toward the simulated player