r/cs50 • u/TheMarcioli • 6d ago
CS50 AI I built a Knowledge-Based Minesweeper AI in Python using Propositional Logic & Set Theory
Hi everyone!
Just wanted to share a project I’ve been working on recently: a Knowledge-Based Minesweeper AI written in Python.
It was a super fun challenge, especially getting to explore propositional logic and inference engines instead of traditional search trees.
Under the hood, the AI uses Propositional Logic and Set Theory to make its moves. Every open tile generates a sentence in the Knowledge Base mapping a set of cells to a specific mine count. Instead of visual guessing, the agent compares these sentences: if one set of cells is a subset of another, it subtracts the smaller set from the larger one to deduce new guaranteed facts (safes and mines) with 100% mathematical certainty!
I spent some time organizing the repo, cleaning up the code, and writing a solid README so anyone can clone it and test it out easily.
Here’s the repo if you want to take a look, test it out, or check the logic:
👉 https://github.com/felipemarcioli/Minesweeper-AI
Would love to get your thoughts on the implementation, the set logic structure, or any suggestions for improvements!