Class WorldFreeze

java.lang.Object
privbot.mechanics.WorldFreeze

public final class WorldFreeze extends Object
Notices a world that has stopped changing while the tick counter keeps running: the signature of a death or a disconnect the client never reported (a real fight always moves something). You compute a fingerprint of the room each tick (our tile and HP, each NPC's index, tile, animation and health) and feed it in.

What it proves. observe returns true once the same fingerprint has held while the tick number advanced by at least ticks. A repeated tick number is ignored (it neither counts nor resets), so polling twice within one tick cannot fake a freeze. A tick number that goes backwards starts a fresh watch. It proves the fingerprint was flat, not why; build the fingerprint from things that move in a live fight.

Unreadable. If you cannot read the room, do not call observe: a fingerprint of nothing would look frozen. Call reset() instead.

Thread. Pure and not thread safe: call it from the one thread that handles the game tick.

Lifted from the Inferno Zuk world-freeze check (16 ticks, about 10 seconds).

  • Constructor Summary

    Constructors
    Constructor
    Description
    WorldFreeze(int ticks)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static long
    mix(long hash, int value)
    Folds one value into a fingerprint; order sensitive.
    boolean
    observe(int tick, long fingerprint)
     
    void
    Forget everything; the next observation starts a new watch.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • WorldFreeze

      public WorldFreeze(int ticks)
      Parameters:
      ticks - how many ticks the fingerprint must hold unchanged (Zuk used 16)
  • Method Details

    • observe

      public boolean observe(int tick, long fingerprint)
      Parameters:
      tick - the current game tick (ThreatSnapshot.tick())
      fingerprint - a hash of everything that moves in the room
      Returns:
      true when the fingerprint has been unchanged across ticks advancing ticks
    • reset

      public void reset()
      Forget everything; the next observation starts a new watch.
    • mix

      public static long mix(long hash, int value)
      Folds one value into a fingerprint; order sensitive. Start from any constant.