So I've been thinking about writing a Board Game Construction Set. It's a pretty insane idea, essentially I want to write a framework for playing board games. The graphical portion is trivial: display the tableaux and pieces, etc. Even defining where the movement squares are and where the decks and discard piles are is simple: about as complex as building an HTML image map. The insane part is coming up with a "rules language" by which a game designer can describe how a game is to be played.
I make no distinction between "card" games and "board" games; card games are simply board games where the board layout is so simple you can visualize it on a tabletop. With a properly constructed BGCS, it should be possible to create games like Monopoly, Poker, Risk, or Chess. It should even be possible to create a game like Magic: The Gathering (MTG).
My suspicion is that custom components of each game can be written in a scripting language such as Ruby, and then the rules can be written out in a general format. If a game has a custom rule, code can be written to enable that rule, then the rule language can manipulate that rule. For example, consider the notion of "tapped" cards in MTG. The MTG cards could simply have a boolean state added to them called "tapped", and the card draw code could rotate the card in position on the table whenever it is tapped. The custom code could then define a "tap" command which can be enabled by the card if it has a tap rule.
Board games have a lot of common components: pieces, cards, tokens, dice, money. Dice are pretty straightforward. Cards are pretty complicated but in the end have some common actions and collections. Cards can be played, drawn, discarded, and in some games removed from play, but in the end you really just have decks and tableaus: draw piles, discard piles, "graveyards" and "removed from play" are just decks. Hands are decks that can be viewed and sorted by a player, while other players can see only how many cards are in that hand. Tableaus are areas on the table where cards can be placed, face up or face down, and either the custom code or the rules determine how they affect play.
Board games have a lot of common rules: how many can play, how to set up, how to determine play order and who goes first, steps that must be performed during your turn, and the conditions that end the game and determine the winner.
The rules language must either be aware of the objects in the game or be able to declare them outright. For example, a checkers game the language would probably just be aware that there are black and red pieces and black and red kings, while the rules language for Monopoly might start out aware of the concept of a "player token", but extend it to create the Shoe, the Terrier, the Plane, the Car, etc.
MTG would need both. Special rules for the core game would add properties like Banding and Flying, and actions like Tap/Untap, Attack, and Interrupt. Special rules for expansions would add new abilities like Rage and Shadow. But the rules language itself would also be taxed to the limit, defining the abilities and rules associated with each card in the deck.
The problem, then, is how to specify the rules language. Ideally I'd like something that looks close enough to English to be written by non-programmers. The idea being that once rules were written for MTG, a card designer should be able to create new cards by adding the card stats (color, type, power, life, casting cost, image file, flavor text) and then adding the rules for that card. In a VERY ideal situation, the rules language for the card would actually be readable by the game players.
In my head I keep envisioning simple rules like "Tap: Do 1 damage to target creature" where the engine has been customized to understand "Tap:" enables the tap command, "target creature" starts the "select_target_creature" code, and "Do ([\d]+) damage" invokes the damage code for that creature, allows players to Interrupt the action or play an Instant, then checks the target creature for the death condition.
knows that "Tap:" means "Add the command 'Tap' to the card UI" but the sentence "Do 1 damage to target creature" ALSO gets parsed out so that "target creature" invokes the UI code to select a creature in play, and "Do 1 damage" gets parsed out by the damage code (defender allowed to play an interrupt, card must be evaluated for death condition). Or more internal rules like "Creature: on death: place card in graveyard" or "White deck: draw: place top card in hand".
The more I think about this the more I think that making a generic rule language is NP-holycrap. Perhaps I should just be content to write a framework in the code, and then code rules for that game in the code?