Skip to content

PHochmann/Cluedo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Cluedo Solver (Ultimate Detective mode)

Language: C Build Test

Interactive Cluedo (Clue) assistant written in C23.

This project serves as an exercise to implement my own SAT solver. It models game knowledge as an CNF, solves it with a custom CDCL SAT solver, and recommends the next move to reduce uncertainty about the envelope.

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚               β”‚ A  B  C β”‚
β”œβ•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β”Όβ•β•β•β•β•β•β•β•β•β”€
β”‚ Mustard       β”‚ Y  X  X β”‚
β”‚ Plum          β”‚ X  X  ? β”‚
β”‚ Green         β”‚ X       β”‚
β”‚ Peacock       β”‚ X       β”‚
β”‚ Scarlett      β”‚ X       β”‚
β”‚ White         β”‚ X       β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ Candlestick   β”‚ Y  X  X β”‚
β”‚ Dagger        β”‚ Y  X  X β”‚
β”‚ Pipe          β”‚ X  ?  ? β”‚
β”‚ Revolver      β”‚ X       β”‚
β”‚ Rope          β”‚         β”‚
β”‚ Wrench        β”‚ Y  X  X β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ Kitchen       β”‚ X  ?  ? β”‚
β”‚ Ballroom      β”‚ Y  X  X β”‚
β”‚ Conservatory  β”‚ X       β”‚
β”‚ Billiard Room β”‚ X       β”‚
β”‚ Library       β”‚ X       β”‚
β”‚ Study         β”‚ X       β”‚
β”‚ Hall          β”‚ X       β”‚
β”‚ Lounge        β”‚ Y  X  X β”‚
β”‚ Dining Room   β”‚ X       β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Legend:

  • Y: literal is true in all satisfying assignments
  • X: literal is false in all satisfying assignments
  • ?: card appeared in a positively answered guess but is still SAT-undecided
  • blank: currently undecided by SAT and did not appear in a guess yet

Overview

This application implements a knowledge base of the rules of Cluedo and the information entered in each round, encoded as boolean formulas. A SAT solver is used to deduce who committed the murder, with what weapon, and in which room. The next move is calculated to give as much information about the envelope content as possible.

The solver targets Ultimate Detective mode from the 2023 digital release, which differs from classic rules:

  • All players publicly answer yes/no for each shown suspect/weapon/room triple
  • A key token can be used to ask a targeted private card question
  • Players move directly between rooms; reachable rooms depend on a 1-3 dice roll

Solver and knowledge base design

Variables encode ownership: literal $x_{p,c}$ means player $p$ (including envelope as pseudo-player) owns card $c$.

Initial model constraints:

  1. Each card is owned by exactly one player (including envelope)
  2. Envelope contains exactly one suspect, one weapon, one room
  3. Each player holds exactly $n$ cards

Per-turn updates:

  1. Guess feedback adds clauses
  2. Key-token questions add clauses
  3. Failed accusations add clauses

SAT internals:

  • CDCL core with learned clauses from 1st UIP conflict cuts
  • Two-Watched-Literals for Boolean constraint propagation
  • Cardinality constraints encoded with auxiliary variables (Sinz encoding)
  • Temporary clauses for SAT calls under assumptions inside recommendation logic
  • Naive variable ordering (no heuristics yet)

Recommendation strategy

The recommender samples five candidate suspect/weapon/room triples and computes, for each candidate, the average number of possible envelope triples after all feedback outcomes (computationally expensive). The candidate with the lowest average remaining envelope possibilities is recommended.

Literature

Project Structure

  • src/:
    • main.c - Game loop
    • sat.c - SAT solver implementation
    • kb.c - Encodes rules and information as boolean formulas in CNF
    • recommender.c - Next move recommendation
    • sheet.c - Prints the sheet
    • cards.c - Utility for card names
    • parsing.c - Utility for parsing with readline
    • util/ - Table printing (older code of mine, currently not well-maintained)

How to use it

Simply invoke:

make

Generates executable at ./bin/release/Cluedo. Alternative targets are: debug, format, clean, check, install-hooks

Requirements:

  • C compiler with C23 support
  • GNU readline (libreadline-dev)
  • Make

Limitations

  • Only Ultimate Detective mode is supported.
  • The SAT solver currently uses no variable-ordering heuristics.
  • The SAT solver currently does not delete learned clauses which slows it down on large problems

License

This project is released into the public domain. You are free to use, modify, and distribute it without restriction.

About

CDCL SAT solver implementation for interactive Cluedo inference.

Topics

Resources

Stars

Watchers

Forks

Contributors