My favorite game is bridge. It’s an excellent test of cooperation and strategy. I’m in a discord chat devoted mostly to the game and folks often share interesting bridge hands with one another. I decided it would be fun to build a program that parsed a simply-formatted bridge hand and produced a plain text bridge diagram.
Here’s a defensive problem that Sir Hugo Drax faced at Blades, defending a contract of 7♣xx.
$ bridge-cli-exe <<< 't987 6543 - 76532 > akqj akqj ak kj9, r/r, imps, s6' Vul: R/R ♠T987 IMPs ♥6543 ♦ ♣76532 Lead: ♠6 ----- ♠AKQJ | N | ♥AKQJ | E| ♦AK | | ♣KJ9 ----- I’d like to focus on an interesting problem I faced when parsing this input. I wanted the user to be able to enter several elements: the layout (the cards), the vulnerability, the type of scoring, and the opening lead, each separated by a comma. However, I wanted these elements to be provided in any order. Furthermore, some of these elements were required while others were optional.
...