Inspiration

I wanted to create a story that is not scripted. Most mystery games face a tradeoff between: scripted stories or long and loaded branched stories-ultimately scripted also. Generative AI can respond freely but may quietly change the culprit, evidence, or timeline as the conversation develops.

The King’s Judgment is an AI-powered social deduction game set inside a royal court. Each player receives private knowledge, enters the same unfolding case, and must defend themselves, question others, expose contradictions, and persuade the king before judgment is passed.

Players are not restricted to predefined dialogue options. They can type an accusation, offer an alibi, ask another character a question, remain silent, joke, lie, or say something completely unexpected. GPT‑5.6 interprets the action and allows the court to respond dynamically.

However, improvisation does not override reality. When the match begins, the culprit, motive, timeline, private roles, and canonical evidence are locked. GPT‑5.6 can improvise how the mystery is performed, but it cannot randomly rewrite the underlying story as the game progresses.

What it does

A match proceeds through an eight-round court inquiry:

  1. Players privately receive their identities, biographies, knowledge, and objectives.
  2. The court introduces the crime and the accused.
  3. Players submit free-form testimony, questions, accusations, and defenses.
  4. GPT‑5.6 generates context-aware responses from the king and other characters.
  5. The game engine records testimony, evidence, and contradictions.
  6. Players decide what to reveal and whom to accuse.
  7. The king reaches a judgment.
  8. The locked truth is revealed and compared with the players’ conclusions.

The prototype includes multiple reusable case templates, solo play, multiplayer gameplay, private role information, evidence tracking, contradiction tracking, judgment, and a complete truth-reveal sequence.

How I built it

I built the project with Codex and GPT‑5.6 during OpenAI Build Week.

Codex helped transform the initial game concept into a working web prototype: defining the game-state model, implementing the eight-round loop, creating the user interface, developing the evidence and contradiction systems, adding multiplayer state synchronization, integrating the OpenAI API, writing tests, diagnosing failures, and preparing the deployed application.

The architecture deliberately separates two layers:

Deterministic truth layer

This layer controls:

  • culprit and motive;
  • canonical timeline;
  • private player roles;
  • valid evidence;
  • round progression;
  • contradiction records;
  • votes and judgment;
  • final truth reveal.

Generative performance layer

GPT‑5.6 controls:

  • contextual dialogue;
  • character reactions;
  • follow-up questions;
  • interpretation of free-form player actions;
  • the dramatic presentation of established facts.

Conceptually:

[

\text{Game State}_{t+1}

\text{Deterministic Engine} \left( \text{Game State}_t, \text{Validated AI Output} \right) ]

The model can propose dialogue and reactions, but only the deterministic engine can change canonical game state.

OpenAI requests run through a server-side endpoint. The API key is never delivered to the browser, and structured model responses are validated before entering the game. If live generation fails, the application can fall back gracefully without corrupting the match.

Challenges

Allowing improvisation without allowing narrative cheating

The hardest design problem was giving GPT‑5.6 enough freedom to respond naturally while preventing it from inventing a convenient new solution. The answer was to treat the model as an actor and game master—not as the database of truth.

Distinguishing free-form input from real AI interaction

An early prototype accepted arbitrary text but produced responses based primarily on the current round. Inputs such as “hi,” “hola mi amigos,” and nonsense could receive essentially the same canned response.

That exposed an important distinction: a text box does not automatically create an interactive AI experience.

I moved the interaction into a live, server-side GPT‑5.6 path that considers the player’s actual statement, previous testimony, revealed evidence, character identity, and current phase.

Protecting private information

Social deduction depends on information asymmetry. Hidden roles and case truth cannot simply be trusted to each player’s browser. The application therefore separates shared public events from private player information and server-authoritative truth.

Making multiplayer usable across separate devices

The intended experience is not pass-and-play. Players should be able to join the same room from their own computers, privately read their roles, submit their own responses, and observe synchronized public events without exposing their information to the other players.

Implementing room membership, private views, shared progression, synchronization, and reconnection while preserving the existing game loop was one of the largest extensions to the original prototype.

Maintaining a reliable playable experience

Generative systems can fail, time out, or return malformed output. The project uses schema validation, bounded requests, deterministic state transitions, and fallback behavior so a model failure does not rewrite the mystery or destroy the match.

What I learned

The central lesson was that the strongest use of generative AI is not necessarily giving it control over everything.

For this game, the more useful architecture is:

[ \text{Fixed Truth} + \text{Flexible Expression} ]

Traditional game logic protects fairness and continuity. GPT‑5.6 gives players the freedom to say almost anything and still receive a meaningful response.

I also learned how effectively Codex can turn a product idea into a complete vertical slice. It did more than generate isolated code: it helped reason through architecture, expose weaknesses in the original interaction model, implement corrections, verify behavior, and move the project toward a deployable multiplayer experience.

What’s next

The current prototype proves the core interaction: a reusable mystery can remain logically stable while every playthrough develops differently through player choices and AI-generated responses.

Future development could include:

  • additional settings and case families;
  • voice-based testimony;
  • richer character relationships;
  • spectator and moderator modes;
  • longer multi-chapter investigations;
  • AI-generated visual scene transitions;
  • persistent player histories and rankings;
  • larger social-deduction rooms.

The long-term vision is a story game that feels authored and coherent, but responds as freely as a live human game master.

Built With

Share this project:

Updates