Live data from Hacker News

Find Legal Moves in Brass Birmingham with Datalog

blog.pzakrzewski.com

11–20 of 26 posts

Re: Find Legal Moves in Brass Birmingham with Datalog

#11
post #6
post #5

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. 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.

Did you publish the code somewhere?

mai-shogi in GitHub

Re: Find Legal Moves in Brass Birmingham with Datalog

#13
post #12

I've implemented rules of https://en.wikipedia.org/wiki/Whist in prolog https://github.com/scolex/prolog-whist/blob/master/whist.pl some yeas ago as school project. Unfortunately comments are in czech language.

My university has an infamous project of implementing Euchre (another trick-taking game) in C++ in one of the early programming courses. It's a nice fundamental problem for dealing with objects, agents, and logic.

Re: Find Legal Moves in Brass Birmingham with Datalog

#14
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).

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.

[1]: https://nchammas.com/writing/how-not-to-die-hard-with-hypoth...

Re: Find Legal Moves in Brass Birmingham with Datalog

#15
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.

It's all open source and playable at https://ora.kennerspiel.com

Re: Find Legal Moves in Brass Birmingham with Datalog

#17

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.

Did you find a clever/elegant way of detecting tic-tac-toe winning moves? I wrote a simple implementation in Typescript several years ago; I tried some approaches with representing the cells as a 2D array and looping over the rows/columns, but I ended up just using a flat array and hardcoding the sets of cells to check [1]. If memory serves, using a flat/1D array made other parts of the code easier, not just the game logic, though that might have been due to my inexperience; I was just starting to learn React/frontend dev at the time.

[1] https://github.com/DylanSp/tic-tac-toe-react/blob/master/src...

Re: Find Legal Moves in Brass Birmingham with Datalog

#18
post #7
post #3

Earlier quoted context omitted.

I've been playing around with making a version of tic-tac-toe that's interesting to grown-ups. Experimenting with rules a lot as you'll see. (I think 1357 is probably the best but not sure.) https://5-by-5.edjohnsonwilliams.co.uk https://github.com/edjw/5_by_5_tictactoe

That's really cool! Need to find someone to play this with now :) Though the counting seems a bit weird. Two overlapping lines of 5 seems to count as "1 two, 2 five". I also managed to get two overlapping fours to count as "2 two, 2 four". Maybe I just don't understand how it's supposed to work?

Thanks! It’s kind of hard to understand what you mean without screenshots. Also there are so many variations that I’m not sure which rules you’re playing with. My dad is the only person who’s played it apart from me and so far if he finds something he thinks is a counting error it’s actually been counting right and it was a UX thing about the rule-writing
Post reply on HN