I've become a big fan of datalog and souffle. We wrote a territory assignment application for a large healthcare organization with multiple overlapping marketing teams, where each team defines territories with various geographic and account attributes such that there's a hierarchy of precedence for the territory that should be assigned to each account.<p>The datalog application that replaced an existing imperative solution is so much easier to understand and maintain.<p>Souffle generates c++ from the datalog program. We use SWIG to compile the c++ code into a Go application. So we have a Go application that deals with getting data in and out, and all of the business logic is defined in datalog.
This is pretty neat, and it reminds me of my experiment solving the water jug problem from Die Hard 3 using Hypothesis [1] (a Python library for property-based testing).<p>Though I doubt Hypothesis's stateful testing capabilities can replicate all the capabilities of Datalog (or its elegance for this kind of logic problem), I think you could port the author's expression of the game rules to Hypothesis pretty straightforwardly.<p>[1]: <a href="https://nchammas.com/writing/how-not-to-die-hard-with-hypothesis" rel="nofollow noreferrer">https://nchammas.com/writing/how-not-to-die-hard-with-hypoth...</a>
I've implemented rules of <a href="https://en.wikipedia.org/wiki/Whist" rel="nofollow noreferrer">https://en.wikipedia.org/wiki/Whist</a> in prolog <a href="https://github.com/scolex/prolog-whist/blob/master/whist.pl">https://github.com/scolex/prolog-whist/blob/master/whist.pl</a> some yeas ago as school project. Unfortunately comments are in czech language.
Aside from the article, I do really like the idea of implementing board game rules as a coding exercise. The only one I’ve ever been confronted with was tic tac toe, and I remember really having fun with the detecting winning moves part.
> Have you ever tried expressing board game rules in code? Does it sound a bit tedious?<p>I expressed the logical rules of Go, which are already phrased in a concise yet mathematically rigorous way, pretty much directly into Haskell [1], which was more fun than tedium.<p>[1] <a href="https://tromp.github.io/go/SimpleGo.hs.txt" rel="nofollow noreferrer">https://tromp.github.io/go/SimpleGo.hs.txt</a>
That was an issue I encountered when writing the logic for Shogi so that I could build my own engine.
Writing Python to express the logical dependencies was surprisingly unintuitive.<p>My original attempt was clunky and I rewrote the logic from scratch 2 or 3 times until I could bear look at the code and not wince.
I implemented the rules of Ora et Labora. Every card's ability is some fun puzzle of enumerating all the legal ways to play it. Some are simple like "go here and you get an amount of sheep", others are "you can convert an amount peat to coal here" so if you have 5 coal, you can offer 0, 1, 2, 3, 4, or 5 peat as input. The more fun problems are like "convert 3 different resources into 6 of any one type of basic resource" or "convert four to bread for 0.5 energy each" and wood is worth 1 energy, peat 2, and coal 3 energy. Lots of fun combinatorics.<p>It's all open source and playable at <a href="https://ora.kennerspiel.com" rel="nofollow noreferrer">https://ora.kennerspiel.com</a>