The making of King Thirteen

Search for a command to run...

No comments yet. Be the first to comment.
An open mind is like a fortress with its gates unbarred and unguarded. This is the story of the Super Castle Game, a js13k game jam entry. Naturally, it begins with the theme of the 2023 edition of the compo: 13th Century. When it dropped, I was com...

An application talking to a language model API has control over the following parameters. Only the Vertex AI PaLM API allows setting Top-K and Top-P at the time of writing. Temperature The temperature (a floating-point number in the range 0.0–1.0) is...

So I was working on something very simple involving a CSV file: import csv with open('file.csv', 'r') as f: reader = csv.reader(f) lines = [ln for ln in reader] And as one would expect, the result of running this code was Error: field large...

Old computer fonts are fascinating. Making a consistent-looking font is a remarkable achievement in its own right, but designing a monospaced font that is readable on a very low-resolution screen, is aesthetically pleasing, and has a distinct persona...

Hey hey people,
I wrote a game recently for a certain coding competition, and thought I'd share the thought process behind it. Let's start with the
King Thirteen is by far the most deliberately designed game I've made. It all began with a very simple proposition: what if the tiles in the game of 2048 were chess knights?
It had to be specifically knights because
This also meant that unlike 2048, the pieces would have to be controlled individually, as knights may have several valid moves in the same general direction.
Which, in turn, led to
The number of free squares on the board is clearly a resource in this game. (The fail state is when the board is full and there are no valid moves.)
If we spawn a new piece after every move, there are two possible outcomes:
This is decidedly unfun, so a mechanic to free up squares was needed. I came up with the following:
This little combo mechanic I'm very happy with. It rewards the player for thinking ahead, and allows for satisfying plays.
However this leads to
Communicating the mid-combo state to the player turned out to be unexpectedly difficult.
Some options I considered were
In the end I didn't really solve this, and instead made the selected piece easily noticeable with a bright outline and a subtle idle animation.
Based on early playtesting, this was sufficient for (attentive) players to figure out the combo mechanic. Clearly there's a lot of room for improvement here.
Another feature that came out of this was the ability to undo the last move. It was added mainly to amend accidental moves, but in turn introduced
When a new piece is spawned, its location is chosen at random. If the player can manipulate said location by repeatedly making and then undoing a move, then this is a disaster! Such strategy trivializes the game, while also being unfathomably boring.
To combat this, the board state includes the internal state of the PRNG (I went with Mulberry32). When the undo button is pressed, both the board and the PRNG are reverted to their previous state.
The entirety of King Thirteen's (pseudo-)random behavior is now deterministic: repeating the same move will always result in the same outcome.
This also survives saving and loading the game: quicksave is done by writing the very data structure that's used for undo to local storage.
I really thought this whole PRNG tangent would be shorter. Oh well.
Now that setting up long combos became the way to play the game, comes
The player might want to leave a specific square empty to set up a combo. However, moving a piece out of the way would often result in another piece immediately taking its place. This contributes to difficulty, but not in a fun way, it's more annoying than anything.
My solution was, when spawning a new piece,
So leaving a square empty on purpose became a viable strategy, as it should be.
At this point I though I was mostly done with the game design. Then I showed an early prototype to friends at work, and after recovering from the terrible terrible placeholder art they unanimously asked,
Why are there only knights though? Where's the rest of the chess pieces?
What followed was the best possible brainstorming session, in which two competing ideas emerged:
One advantage of the first game mode is readability: there are no numeric values attached to the pieces, so the board is less cluttered. I'll probably include this as a separate game mode in the future.
For the compo version, I went with the second option and added progression to the game. It works like this:
Despite the spawn rates, when every threshold is reached for the first time, the new piece is guaranteed to appear. I think this serves to better communicate the progression to the player.
Then finally it was time to add the last piece,
The King is meant to be the antagonist of the game. He's also the only piece that isn't controlled by the player.
Bearing the number XIII to represent the theme of the compo ("triskaidekaphobia"), the crimson figure roams the board unpredictably.
The King resorts to violence only when he is cornered and has nowhere else to go. It's below him to kill commoners otherwise.
If there's no unobstructed path for the King, he will take the highest-value piece in his vicinity. However if you might lose due to the board being full, then the King won't help you by clearing the board; he'll just skip his turn.
I had so much fun programming these little behaviors. The resulting King is a very simple AI, just enough to introduce a bit of chaos to the game.
I'm also reasonably happy with the flavor text:
King Godric XIII, called the Crimson Hand, the Withering Flame, the dreaded King Thirteen rose from his throne.
The whispers of his subjects had grown too loud, too bold. They had forgotten their place.
— Silence!
Clad in blood-red armor, Godric towered over them, an enormous and imposing figure.
— I am fear incarnate! — his roar echoed through the hall. — You will bow before me, or you will burn!
Soon after, swords were drawn, and scarlet splattered the floor.
During the final playtesting, one issue with the King became apparent:
The problem is, if the King had just one opportunity to move, and the spawned piece blocked that move, then the King would instead go into attack mode. This is despite the player's best efforts to leave a path open for the King to go uncontested.
This felt unfair when it happened, so I changed the order of actions: first the player moves, then the King moves, then a new piece spawns. However the new piece will never choose the square that the King has just vacated. (The reason for this is purely aesthetic.)
Ah, and the end goal of the game is to reach the value of 2048. The King's value is 1024. Do with it as you will; regicide is not the only way to win the game, but it sure is satisfying.
Thank you for reading! I hope you enjoyed the game more than this post. If you haven't played it yet, please do, and tell me what you think.
King Thirteen is available on
Any instance of "I" in this text should be read as "myself, with the invaluable help of my friends who are brilliant and I appreciate them very much".
Disappointingly, no LLM was sufficiently harmed in the writing of this post.