rosshamish / catanlog

machine-parsable, human-readable file format for describing a game of Catan
GNU General Public License v3.0
17 stars 1 forks source link

Suggestion: Unifying buy/play patterns #1

Closed antoinne85 closed 8 years ago

antoinne85 commented 8 years ago

Currently the pattern for buying things and playing development cards look like the following, respectively player buys item, does_something_with_it player plays dev card: card_name, does_something_with_it

Concrete examples being: blue buys settlement, builds at (8 NW) blue plays dev card: road builder, builds at (9 W) and (10 E)

It might simplify the reading and parsing if they looked more similar.

You might consider: player action item_name, extra_information

Which would make it read more like: blue buys road, builds at (8 NW) blue plays road builder, builds at (9 W) and (10 E)

To a human it reads almost the same, but parsing it can be simplified a little.

Now the simple parser (read: not one using syntax trees and other fanciness) can split on ','. Everything before the comma is what the user did and everything after is information about precisely how they did it.

Before the comma always has three parts. player is always the player action is always "buy" or "build" (or other action names as they become necessary)

The action you see informs what you should expect to see in the third slot. If it's "buy" you should expect a settlement, city, road, etc. if it's "plays" you should expect a development card.

Once you know what to expect, you can look at item_name. Once you've seen the item name you will know how to parse what's on the other side of the comma.

Just a thought. If you don't like it, it's not a big deal. It's not as if it's unparseable now. Neat project, though.

rosshamish commented 8 years ago

Yeah, I think this is a great idea. The only issue I can see is that the knight, monopoly, and victory point dev cards won't have a comma to split on. But that's fine - the parser can look for the comma after having parsed "plays" and then "item_name". So we'll end up with the following:

$color buys (road | settlement | city), builds at $location
$color plays (knight | monopoly | year of plenty | road builder | victory point)[, does_something_depending_on_card]

Note: currently, the knight syntax includes the robber move + steal on the same line, but I think the robber move + steal should be on its own line in the log (to better match the other case of "roll a 7, move robber, steal", which has the move+steal on its own line)

Changes will need to be made in

Feel free to submit a PR with some or all of these changes - otherwise I'll get to this soon.

Thanks for the issue!

rosshamish commented 8 years ago

This has been addressed and the change has been made. Usage documentation in README.md is updated as well. Thanks @antoinne85!