← Back to geotechnicalengr.com Personal Project

Kings Corner

A card game you play against the computer. I built it to learn how to structure a tested rules engine and a computer opponent.

The Problem

Most of my projects so far have been small tools wrapped around a form and a data file. I wanted to build something with real rules and an opponent: a game where correctness is checkable and the computer has to make decisions. Kings Corner, a card game I grew up playing, fit — it has just enough rules to get tricky.

The Approach

I built the rules engine first, with no screen attached: a set of pure functions that deal a game, list the legal moves, and apply one. It's covered by automated tests, including a thousand computer-versus-computer games run to completion to catch rules that deadlock or crash. Only then did I build the table, the card graphics (all drawn in code, no image files), and the computer opponent, which plays through the same legal-move list a person does.

The opponent has two levels: an easy one that plays randomly, and a normal one that follows a simple priority list — kings to corners first, then the highest cards it can place. Measured over two thousand games, normal beats easy about 87% of the time. It's plain HTML, CSS, and JavaScript with no frameworks and no build step, and a game in progress survives a refresh or a locked phone.

Kings Corner on a phone: eight pile slots around a central draw pile, the computer's seven cards across the top, and the player's hand along the bottom

A fresh deal on a phone. Kings go to the empty corners; everything else builds down in alternating colors.

Kings Corner on a desktop browser, with the same board plus a move log on the right

The same game on desktop, with a move log beside the board.

The Result

A finished, tested game that plays well on a phone, and a clear lesson in why building the rules first pays off: the opponent, the interface, and the tests all stood on one small engine I trusted.