The Master's Shadow Master Malacor in 'The Master's Shadow' is a rule-bound autonomous AI using Ant-Colony Optimisation (ACO) to pursue players, with deterministic behavior governed by pheromone-based pathfinding and dynamic strategies based on player actions and trace levels. The Master AI — Ant-Colony Optimisation Master Malacor is not a game-over timer or an omniscient threat. He is a rule-bound autonomous agent running on the same deterministic Clockwork Dark engine as the player, subject to the same world friction : every action is a legal engine call move to node , resolve skill check , craft item , forage/rest , governed so he cannot cheat or hallucinate outcomes. He spends Food, Energy and Mana, is slowed by hazardous nodes, and can be outlasted if he burns resources recklessly. His edge is better starting knowledge and stats ; the player’s counter is that this knowledge is imperfect and corruptible . The ACO model Ant-Colony Optimisation ACO is a swarm metaheuristic: artificial ants lay pheromone on good paths, pheromone evaporates to allow adaptation, and each next-step choice combines pheromone τ, weight alpha with a heuristic η, weight beta via seeded roulette-wheel selection. ACO gives the Master and crowds a memory of good routes that A alone lacks, and adapts naturally to changing traps, trace and reputation. Hex adaptation: pheromone is stored per directed edge between cube-coordinate hexes the 6 neighbours . Heuristic η = 1 / movement cost , where movement cost already folds in terrain, traps, trace and reputation. All random choices are seeded with game seed + state hash , so ACO is fully deterministic. See World & Flow Fields https://github.com/nihilistau/the-masters-shadow/blob/master/design/okf/world-and-flowfields.md for the hybrid: ACO is the strategic layer that emits a temporary flow field, blended weight ~0.7 with the global flow field; flow fields + local steering handle cheap real-time crowd movement. Recommended parameters per context : Context | ants | iters | alpha | beta | evap | Q | | Master Bloodhound pursuit | 15 | 25 | 1.2 | 2.5 | 0.08 | 1.0 | | Master Architect planning | 25 | 40 | 1.0 | 2.0 | 0.12 | 0.8 | | Loyalist patrol swarms | 10 | 15 | 0.8 | 3.0 | 0.15 | 0.6 | | Rebel groups | 12 | 20 | 1.0 | 1.8 | 0.10 | 0.7 | | Monster swarms | 8 | 12 | 1.5 | 1.5 | 0.20 | 0.5 | Tracking vectors The Master maintains an internal world model from state flags, imperfect and degrading with time/distance: - Sympathy Trace primary . Black spells Drain Life , Shadow Step , Bind , Summon Familiar , heavy Black ingredients Nightshade , Mandrake Root , Sympathy Ash and failed Black alchemy add trace. Trace decays ~1–3 per node moved faster with White magic, rain, Shimmering Lake . Bands drive behaviour: Trace | Master behaviour | Player-visible | Counters | | Low 0–20 | Normal patrol / Architect | none | — | | Med 21–50 | Bloodhound chance ↑ | raven cries, scorched nodes | Grey masking, Decoy, weather | | High 51–80 | Locks onto path, faster | dead NPCs, stripped nodes on trail | White trace-purge, false trails | | Critical 81+ | Aggressive pursuit, trackers | projection appears, Loyalists converge | Shadow Cloak + high Grey, sabotage | - Last-known position + path history from Raven Familiar, Loyalist Trackers, direct sight . Grey magic — Invisibility , Muffle , Decoy , high Concealment , Shadow Cloak — breaks or falsifies it. - Reputation & world flags secondary : Loyalist reputation drives patrol/trap density; bribed NPCs may feed him false intel; helping/harming key characters sets persistent readable flags. Pursuit strategies The Master switches mode dynamically on trace, resources, last-known position, and predicted intent: Bloodhound reactive . Trigger: medium+ trace, recent sighting, or obvious Black magic. Runs the player’s exact recent path, spends Mana on Haste , strips resources behind them, prioritises closing distance. Countered by Haste , false trails, weather Sudden Storm doubles all costs , or leading him into monster nodes. Architect predictive . Trigger: low trace but the player is heading to a chokepoint Boundary Gate, Rebel Encampment, Smuggler’s Cove or is patterned. Diverges ahead , lays snares, bribes guards Gorn, Vex, Captain Thorne , sets ambushes. Countered by breaking patterns, varying routes, counter-intel Divination Mirror , or sabotaging his forward assets. Opportunistic / Idle. Casts about the strongest scent when neither loud nor cleanly predictable; Idle covers forage/rest. He can switch mid-chase if trace spikes or he loses the trail. Learning: memory decay & protection The Master keeps a separate pheromone map of the player observed spell chains, escape routes, alchemy habits, trap responses that steers strategy, trap placement and spell priority. It is a learning but fallible memory that decays under pressure, so the player must keep adapting. Decay base rate = 0.06 slower than player-side magical pheromone; he is disciplined . Multipliers: Ritual Clock 1.0 + stage 0.35 ; player trace 1.0 + trace/120 ; low Mana ×1.3; recent failed counter ×1.2; heavy recent Grey ×1.4; strong Water-Spirit reputation ×1.15; time-since-observed up to ×1.8. Capped at 0.28; floor 0.005. Protection else Grey trivialises him : Ritual-Clock hardening 1.0 − stage 0.12 , up to ~36% slower late , extra ×0.7 on recently-used patterns, importance weighting, resource-based resilience stronger 60% Mana , and active tools — Trace-Burn , Clarity Projection , Pheromone Anchor , surveillance agents. Targeted Memory Fog he may detect and reinforce against , a cat-and-mouse mini-game. Player disruptor — Memory Fog Grey . Applies a decay boost 0.18 + grey level 0.03 ×1.5 targeted to his player-model over 4–8 nodes 10–12 with alchemy ; ~+0.5 clock at stage ≥2; recent-use penalty ×0.5 within 8 turns to stop spam. Net arc: early memory strong and teaching; mid older observations erode, he can be re-fooled; late desperation clock both accelerates his forgetting and hardens his prized recent counters, so he grows more brute-force and predictable — windows for skilled play. The unified ACO loop player + Master ACO also drives spell-sequence selection for both sides. Each “ant” runs a short simulated cast chain ≤4 spells ; transition probability P = τ^alpha · η^beta · clock pressure^gamma · reputation mod^delta , normalised uniform fallback if none viable . The heuristic scores Mana efficiency, trace delta heavy penalty for Black when trace 60–70; small reward for controlled Black when low , affinity match, alchemy synergy potions as temporary pheromone boosters , and tactical context near-traps favours Haste/Shadow Step/Decoy ; low health favours Mend/Ward ; density favours Bind/Sleep . Successful chains deposit pheromone, so tactics that work become reliable — but also predictable. Ritual-Clock tuning ramps parameters by stage: alpha 1.0→1.5, beta 2.5→3.5, evaporation 0.10→0.30, with rising Black penalty and survival bias. The Master’s loop uses higher alpha 1.4–1.6, leans on learned patterns , aggressive elitist reinforcement, and grows more efficient and less exploratory as the clock advances. Phase carry-over. Phase 1 https://github.com/nihilistau/the-masters-shadow/blob/master/design/okf/phases.md choices seed Phase 2 pheromone: reputation flags become initial pheromone biases; Grey progress → stronger stealth-pair pheromone and better decoys; heavy Black → higher starting trace; ritual sabotage → lower starting clock and persistent low-cost corridors. In the build The design is realised, though the shipped C++ core is a deliberately lean, deterministic subset of the sprawling design above — not the full multi-map ACO/LLM stack. src/ai/master ai.hpp / master ai.cpp — MasterBrain . A single scent pheromone map unordered map