Chronomancer

1st Place HackNotts 2025

Github Repository • Original Devpost

Chronomancer is an event-sequencing strategy game that I co-developed with Amber in 24 hours at HackNotts 2025. The game is built on the satisfiability of an acyclic, non-linear timeline; every decision adds a constraint, and the aim is to avoid inducing modal collapse by creating a time paradox (such as scheduling the execution of the gnome king before his birthday party, which you have already solemnly promised he will attend.).

The player takes on the role of a medieval timelord, and is endlessly petitioned by the kingdoms subjects to schedule events anywhere in history: the past, the present or the future. For each ledger, the timelord may either accept or deny the request.

Kingdoms are conjured from real locations using a variety of sources (e.g. Google Places, Directions and Routes APIs) to find notable locations and the roads between them, projected them onto a unit circle, and carved them up between three rival factions using k-means clustering. Thus, the local chippy may becomes a goblin outpost, or troll dungeon.

Non-Linear Time

Since the game is played from every point in time, there is no notion of the ‘present’ - the game only knows that some events must happen before others, but many pairs of events have no fixed order at all, and it is up to the player to stop the whole history from unravelling (i.e. paradox).

Let \(\mathcal{E}\) denote a set of events, and \(\mathcal{C}\) a set of characters, each loyal to one of the three factions. Each event \(\epsilon \in \mathcal{E}\) may have

  1. a set of participants \(\mathcal{P}(\epsilon) \subseteq \mathcal{C}\), the characters who must turn up,
  2. a set of victims \(\mathcal{K}(\epsilon) \subseteq \mathcal{C}\), the characters who will not be leaving, and
  3. a set of successors \(\mathcal{S}(\epsilon) \subseteq \mathcal{E}\), the events that \(\epsilon\) must happen before.

We write \(\epsilon \prec \epsilon'\) to mean that \(\epsilon\) must happen before \(\epsilon'\), which holds whenever \(\epsilon' \in \mathcal{S}(\epsilon)\). Precedence is transitive, so for any three events \(\epsilon_i, \epsilon_j, \epsilon_k \in \mathcal{E}\) such that \(\epsilon_i \prec \epsilon_j \prec \epsilon_k\), we also have \(\epsilon_i \prec \epsilon_k\). That is, if the coronation is before the feast, and the feast is before the food poisoning, then the coronation is before the food poisoning.

Using this, a timeline may be defined as the pair \((\mathcal{E}, \prec)\). Two events \(\epsilon\) and \(\epsilon'\) are concurrent if neither \(\epsilon \prec \epsilon'\) nor \(\epsilon' \prec \epsilon\). Concurrent events may happen in either order, and this is where the non-linearity (and most of the trouble) comes from. The only structural requirement on a timeline is that it is acyclic, since no event, however magical, can happen before itself.

\[\forall \epsilon \in \mathcal{E}.\;\; \epsilon \not\prec \epsilon\]

In order to visualise the timeline, we convert \((\mathcal{E}, \prec)\) into an interval order. Each event is given an interval from its earliest to its latest possible position in a topological ordering, and the intervals are packed into tracks. In the UI, these are drawn around a circular, clock-like dial, loosely inspired by medieval horologes, so that the player can see which events are pinned in place and which are still free to wander.

Starting with an empty set of events, each turn the player is handed a ledger: a petition from a member of the kingdom asking for a new event \(n \notin \mathcal{E}\) to be scheduled. Ledgers are generated symbolically first. We pick an event type (a catastrophe, ceremony, miracle or auxiliary event), the participants \(\mathcal{P}(n)\) from a single faction, and the victims \(\mathcal{K}(n)\), where catastrophes, being catastrophes, usually kill someone. We then choose an existing event \(b \in \mathcal{E}\) for \(n\) to happen before, so that \(\mathcal{S}(n) = \{b\}\). If some event \(a\) has \(b \in \mathcal{S}(a)\), then \(n\) is usually wedged in between them, and otherwise \(n\) is simply placed before \(b\).

\[\mathcal{S}'(a) = \begin{cases} \big(\mathcal{S}(a) \setminus \{b\}\big) \cup \{n\} & \text{(transitive insertion)} \\ \mathcal{S}(a) & \text{(flat insertion)} \end{cases}\]

Accepting the ledger adds \(n\) to \(\mathcal{E}\) and updates the successors. Transitive insertion removes \(b\) from the successors of \(a\), but nothing is lost, as \(a \prec b\) still holds by transitivity, since \(a \prec n \prec b\).

Only once the symbolic event exists do we ask a language model to dress it up in a cloak and a funny hat. The model is given the event type, its participants, its victims and its successors, and is asked to write a short name and a one or two sentence request in a suitably medieval tone. This keeps the narrative grounded: the language model never decides what happens, only how it is described, so however florid the petition, it corresponds exactly to a constraint the solver understands.

Whenever the player accepts a ledger, the whole timeline is encoded into a first-order logic and handed to the Z3 Theorem Prover. Z3 is a satisfiability checker, which means it can search for a series of assignments of events to times such that all constraints are satisfied; if no such assignment exists, then the player has created a paradox, the kingdom folds in on itself, and the game is over.

Fix a time horizon \(T \in \mathbb{N}\) and let \(\mathbb{T} = \{0, \dots, T\}\). A schedule is a function \(\sigma : \mathcal{E} \to \mathbb{T}\), and we write \(t_\epsilon = \sigma(\epsilon)\) for the time at which \(\epsilon\) happens. A life assignment is a function \(\lambda : \mathcal{C} \times \mathbb{T} \to \mathbb{B}\), and we write \(\heartsuit_c(\tau) = \lambda(c, \tau)\), a little heart that keeps beating for as long as \(c\) is alive at time \(\tau\). Checking a timeline \((\mathcal{E}, \prec)\) is then a constraint satisfaction problem: find a schedule and a life assignment such that every one of the following holds.

\[\begin{aligned} & \text{find} && \sigma, \lambda \\ & \text{s.t.} && \epsilon \prec \epsilon' \implies t_\epsilon < t_{\epsilon'} && \forall\, (\epsilon, \epsilon') \in \mathcal{E} \times \mathcal{E} && (1) \\ & && \heartsuit_c(0) && \forall\, c \in \mathcal{C} && (2) \\ & && \heartsuit_c(\tau + 1) \implies \heartsuit_c(\tau) && \forall\, c \in \mathcal{C},\; \tau < T && (3) \\ & && c \in \mathcal{K}(\epsilon) \wedge \tau \geq t_\epsilon \implies \neg\, \heartsuit_c(\tau) && \forall\, \epsilon \in \mathcal{E},\; c \in \mathcal{C},\; \tau \in \mathbb{T} && (4) \\ & && c \in \mathcal{K}(\epsilon) \wedge \tau < t_\epsilon \implies \heartsuit_c(\tau) && \forall\, \epsilon \in \mathcal{E},\; c \in \mathcal{C},\; \tau \in \mathbb{T} && (5) \\ & && c \in \mathcal{P}(\epsilon) \setminus \mathcal{K}(\epsilon) \implies \heartsuit_c(t_\epsilon) && \forall\, \epsilon \in \mathcal{E},\; c \in \mathcal{C} && (6) \\ & && c \in \mathcal{K}(\epsilon) \wedge c \in \mathcal{K}(\epsilon') \implies \epsilon = \epsilon' && \forall\, (\epsilon, \epsilon') \in \mathcal{E} \times \mathcal{E},\; c \in \mathcal{C} && (7) \end{aligned}\]

Constraint (1) turns precedence into a strict ordering on times. It also forbids cycles, since by transitivity a cycle gives \(\epsilon \prec \epsilon\), which would require \(t_\epsilon < t_\epsilon\), and not even a timelord can manage that. Constraints (2) and (3) say that characters start alive, and once dead they stay dead (there are no necromancers in this kingdom), so being alive at some time implies having been alive at every earlier time.

Constraints (4) and (5) say that an event kills its victims from the moment it happens, and that they must have been alive up until then, since you cannot assassinate someone who has already been eaten by a troll. Constraint (6) says that every other participant must be alive when the event takes place, as ghosts are not permitted at ceremonies. Finally, constraint (7) says that no character may be killed by more than one event, however unpopular they are.

If the constraints are satisfiable, the model returned by Z3 is a witness \((\sigma, \lambda)\): one concrete, paradox-free history of the kingdom. Returning to the unfortunate gnome king \(k\), suppose his birthday party \(p\) has \(k \in \mathcal{P}(p)\), and the player accepts a ledger for his execution \(x\) with \(k \in \mathcal{K}(x)\) and \(x \prec p\). Then (1) gives \(t_x < t_p\), so (4) gives \(\neg\, \heartsuit_k(t_p)\), whilst (6) insists on \(\heartsuit_k(t_p)\). The constraints are unsatisfiable, the cake goes uneaten, and the kingdom collapses into paradox.

Since \(\mathbb{T}\) is finite, each \(\heartsuit_c(\tau)\) is just a Boolean variable, and a term like \(\heartsuit_c(t_\epsilon)\) unrolls into \(\bigwedge_{\tau \in \mathbb{T}} \big( \tau = t_\epsilon \Rightarrow \heartsuit_c(\tau) \big)\). What remains is quantifier-free linear integer arithmetic, which is decidable, so the oracle always gives a definite answer. With \(T = 1000\) this means a thousand Boolean variables per character, one for every moment of their (possibly short) lives. It is not the most efficient encoding, but it was quick to write at 4am during a 24-hour hackathon, and Z3 handles it comfortably at the size of a game.