I Like Programming

Board Game Abstraction

How would you model a board game in a sql database?  I’ve been overthinking this.  I’d probably have a Game model to keep track of whose turn it is, with a lot of Pieces associated with it.  But that’s obvious.

To be totally generic, a Piece could consist of string:kind, string:space, and string:color.  But what if you were playing a game like chess with a 2D board?  You could name the space something like 2-2.  What if the piece has meta information like rank and class?  You could encode it in the kind, like fire-2.  Why bother using data types other than string if you’re just going to fetch all pieces and assemble the board whenever you compute a move?

Or is there a reason to query on meta information and board positions?  Would you optimize your game logic by not constructing the whole board each time?  Should you create a new model for the kind of piece that exists in each game, like a monopoly piece which moves around the board linearly versus a checkers piece which traverses in two dimensions and can be kinged?  Do you want many small tables or few large ones?