Wednesday, June 22, 2022

The Cure for Card (and Dice) Game Amnesia

It seems that whenever I have a deck of cards, a group and some time I immediately forget every card game I've ever played. This fact, combined with some upcoming travel had me looking for a fresh solution to remembering the names of, and rules to, interesting card games.

Before I started working on a solution to this problem, I decided to expand the challenge a bit. I picked up a 10 pack of dice for $1.99 with then intention of adding dice games to my repertoire.

Code It

I eventually settled on a simple plan. Rather than build a comprehensive list of games, I focused on just a few, about 5 card games and 5 dice games. From there, I created a cheat sheet for each game to simplify remembering the rules and game play. You can find version 1.0 of this effort over at: github.com/benjisimon/offline-games.

Each game has its own Markdown file that captures the rules, scoring and links to How To Play resources on the web. I created two PHP scripts to work with these files. One script converts the Markdown file to a portable HTML file, while the other creates a top level index for browsing the games.

The Markdown files try to be consistent in how they describe game play. The hope is that the terse and consistent nature of each file will make it easy to bring myself and others up to speed on how a game is played. Looking at what I've created, you'll see that some of the files are fairly detailed, while others are little more than learn more links.

Keep in mind that the point of the cheat sheets is to give me a quick reminder as to how the game is played; not to be a comprehensive guide to the rules.

Once you grab the github repository, you can run make to generate the relevant HTML files.

$ make
(cd scripts/lib ; composer install)
Installing dependencies from lock file (including require-dev)
Verifying lock file contents can be installed on current platform.
Package operations: 1 install, 0 updates, 0 removals
  - Installing michelf/php-markdown (1.9.1): Extracting archive
Generating autoload files
mkdir -p games/card/
php -f scripts/mkhtml.php srcs/card/Ninety_Eight.md > games/card/Ninety_Eight.html
mkdir -p games/card/
php -f scripts/mkhtml.php srcs/card/Golf.md > games/card/Golf.html
mkdir -p games/dice/
php -f scripts/mkhtml.php srcs/dice/Bunco.md > games/dice/Bunco.html
mkdir -p games/dice/
php -f scripts/mkhtml.php srcs/dice/Ship_Captain_Crew.md > games/dice/Ship_Captain_Crew.html
mkdir -p games/dice/
php -f scripts/mkhtml.php srcs/dice/Ducks_in_a_Bucket.md > games/dice/Ducks_in_a_Bucket.html
mkdir -p games/card/
php -f scripts/mkhtml.php srcs/card/Horse_Race.md > games/card/Horse_Race.html
mkdir -p games/card/
php -f scripts/mkhtml.php srcs/card/Rummy.md > games/card/Rummy.html
mkdir -p games/card/
php -f scripts/mkhtml.php srcs/card/Casino.md > games/card/Casino.html
mkdir -p games/dice/
php -f scripts/mkhtml.php srcs/dice/Farkle.md > games/dice/Farkle.html
mkdir -p games/card/
php -f scripts/mkhtml.php srcs/card/Coup.md > games/card/Coup.html
mkdir -p games/card/
php -f scripts/mkhtml.php srcs/card/Cribbage.md > games/card/Cribbage.html
mkdir -p games/card/
php -f scripts/mkhtml.php srcs/card/Slapjack.md > games/card/Slapjack.html
mkdir -p games/card/
php -f scripts/mkhtml.php srcs/card/The_Mind.md > games/card/The_Mind.html
php -f scripts/mkindex.php > index.html

Serve It

Because the HTML files are all self contained, you can open them up in any web browser, including your phone's. You can also serve up the files via a simple web server. On my desktop I can browse the games using PHP's built in web server:

$ php -S localhost:9001
[Tue Jun 21 15:35:46 2022] PHP 7.4.27 Development Server (http://localhost:9001) started

More than a little surprisingly, I can do the same thing under Termux and proot on my Galaxy S22 Ultra. Again, I'm using PHP's built in web server:

A less geeky Android solution is to install the Simple HTTP Server app on your phone, and serve up the content that way:

The most practical way I've found to access the game files on my phone is to open up the games directory in My Files and select the Add To Home screen option. Once this is done, a short cut is added to my home screen that gives me one click access.

Problem Solved. Maybe.

I'm far from convinced that I've actually solved the problem I set out to.

On one hand, curating a limited set of games was clearly a good idea. And writing up the cheat sheets is very much in line with the adage that if you want to truly understand something, teach it to others.

The Markdown, PHP and Make solution was fun to work out. Learning that I can run php -S localhost:9000 under Termux / proot and access that content via my phone's browser is downright mind blowing.

On the other hand, I'm not convinced that my game write-ups are of any more useful than existing web content. In fact, I fear that my cheat sheets will end up being both incomplete and hard to understand. And I'm pretty sure I could replace nearly this entire project with a simple Google Sheet that included a list of games and links to existing How To Play videos and web pages.

Still, I'm glad I've got this iteration of Offline Games built out and I'm psyched to field test it over the next couple of months.

Casino anyone? How about a round of Ship, Captain and Crew?

No comments:

Post a Comment