Future Arimaa grand masters at practice, this Sunday morning boardgaming session.
Tag: board games
Note #24701
D20 with Advantage
Dungeons & Dragons players spend a lot of time rolling 20-sided polyhedral dice, known as D20s.
In general, they’re looking to roll as high as possible to successfully stab a wyvern, jump a chasm, pick a lock, charm a Duke1, or whatever.
Roll with advantage
Sometimes, a player gets to roll with advantage. In this case, the player rolls two dice, and takes the higher roll. This really boosts their chances of not-getting a low roll. Do you know by how much?
I dreamed about this very question last night. And then, still in my dream, I came up with the answer2. I woke up thinking about it3 and checked my working.
The chance of getting a “natural 1” result on a D20 is 1 in 20… but when you roll with advantage, that goes down to 1 in 400: a huge improvement! The chance of rolling a 10 or 11 (2 in 20 chance of one or the other) remains the same. And the chance of a “crit” – 20 – goes up from 1 in 20 when rolling a single D20 to 39 in 400 – almost 10% – when rolling with advantage.
You can see that in the table above: the headers along the top and left are the natural rolls, the intersections are the resulting values – the higher of the two.
The nice thing about the table above (which again: was how I visualised the question in my dream!) is it really helps to visualise why these numbers are what they are. The general formula for calculating the chance of a given number when rolling D20 with advantage is ( n2 – (n-1)2 ) / 400. That is, the square of the number you’re looking for, minus the square of the number one less than that, over 400 (the total number of permutations)4.
Why roll two dice when one massive one will do?
Knowing the probability matrix, it’s theoretically possible to construct a “D20 with Advantage” die5. Such a tool would have 400 sides (one 1, three 2s, five 3s… and thirty-nine 20s). Rolling-with-advantage would be a single roll.
This is probably a totally academic exercise. The only conceivable reason I can think of would be if you were implementing a computer system on which generating random numbers was computationally-expensive, but memory was cheap: under this circumstance, you could pre-generate a 400-item array of possible results and randomly select from it.
But if anybody’s got a 3D printer capable of making a large tetrahectogon (yes, that’s what you call a 400-sided polygon – you learned something today!), I’d love to see an “Advantage D20” in the flesh. Or if you’d just like to implement a 3D model for Dice Box that’d be fine too!
Footnotes
1 Or throw a fireball, recall an anecdote, navigate a rainforest, survive a poisoning, sneak past a troll, swim through a magical swamp, hold on to a speeding aurochs, disarm a tripwire, fire a crossbow, mix a potion, appeal to one among a pantheon of gods, beat the inn’s landlord at an arm-wrestling match, seduce a duergar guard, persuade a talking squirrel to spy on some bandits, hold open a heavy door, determine the nature of a curse, follow a trail of blood, find a long-lost tome, win a drinking competition, pickpocket a sleeping ogre, bury a magic sword so deep that nobody will ever find it, pilot a spacefaring rowboat, interpret a forgotten language, notice an imminent ambush, telepathically commune with a distant friend, accurately copy-out an ancient manuscript, perform a religious ritual, find the secret button under the wizard’s desk, survive the blistering cold, entertain a gang of street urchins, push through a force field, resist mind control, and then compose a ballad celebrating your adventure.
2 I don’t know what it says about me as a human being that sometimes I dream in mathematics, but it perhaps shouldn’t be surprising given I’m nerdy enough to have previously recorded instances of dreaming in (a) Perl, and (b) Nethack (terminal mode).
3 When I woke up I also found that I had One Jump from Disney’s Aladdin stuck in my head, but I’m not sure that’s relevant to the discussion of probability; however, it might still be a reasonable indicator of my mental state in general.
4 An alternative formula which is easier to read but harder to explain would be ( 2(n – 1) + 1 ) / 400.
5 Or a “D20 with Disadvantage”: the table’s basically the inverse of the advantage one – i.e. 1 in 400 chance of a 20 through to 39 in 400 chance of a 1.
Multi-Phase Maps in FoundryVTT
FoundryVTT is a fantastic Web-based environment for tabletop roleplaying adventures1 and something I particularly enjoy is the freedom for virtually-unlimited scripting. Following a demonstration to a fellow DM at work last week I promised to throw together a quick tutorial into scripting simple multi-phase maps using Foundry.2
Why multi-phase maps?
You might use a multi-phase map to:
- Allow the development and expansion of a siege camp outside the fortress where the heroes are holed-up.3
- Rotate through day and night cycles or different times of day, perhaps with different things to interact with in each.4
- Gradually flood a sewer with rising water… increasing the range of the monster that dwells within.5
- Re-arrange parts of the dungeon when the characters flip certain switches, opening new paths… and closing others.
I’ll use the map above to create a simple linear flow, powered by a macro in the hotbar. Obviously, more-complex scenarios are available, and combining this approach with a plugin like Monk’s Active Tile Triggers can even be used to make the map appear to dynamically change in response to the movement or actions of player characters!
Setting the scene
Create a scene, using the final state of the map as the background. Then, in reverse-order, add the previous states as tiles above it.
Make a note of the X-position that your tiles are in when they’re where they supposed to be: we’ll “move” the tiles off to the side when they’re hidden, to prevent their ghostly half-hidden forms getting in your way as game master. We’ll also use this X-position to detect which tiles have already been moved/hidden.
Also make note of each tile’s ID, so your script can reference them. It’s easiest to do this as you go along. When you’re ready to write your macro, reverse the list, because we’ll be hiding each tile in the opposite order from the order you placed them.
Writing the script
Next, create a new script macro, e.g. by clicking an empty slot in the macro bar. When you activate this script, the map will move forward one phase (or, if it’s at the end, it’ll reset).
Here’s the code you’ll need – the 👈 emoji identifies the places you’ll need to modify the code, specifically:
-
const revealed_tiles_default_x = 250
should refer to the X-position of your tiles when they’re in the correct position. -
const revealed_tiles_modified_x = 2825
should refer to the X-position they’ll appear at “off to the right” of your scene. To determine this, just move one tile right until it’s sufficiently out of the way of the battlemap and then check what it’s X-position is! Or just take the default X-position, add the width of your map in pixels, and then add a tiny bit more. -
const revealed_tiles = [ ... ]
is a list of the tile IDs of each tile what will be hidden, in turn. In my example there are five of them (the sixth and final image being the scene background).
const revealed_tiles_default_x = 250; // 👈 X-position of tiles when displayed const revealed_tiles_modified_x = 2825; // 👈 X-position of tiles when not displayed const revealed_tiles = [ '2xG7S8Yqk4x1eAdr', // 👈 list of tile IDs in order that they should be hidden 'SjNQDBImHvrjAHWX', // (top to bottom) 'tuYg4FvLgIla1l21', 'auX4sj64PWmkAteR', 'yAL4YP0I4Cv4Sevt', ].map(t=>canvas.tiles.get(t)); /*************************************************************************************************/ // Get the topmost tile that is still visible: const next_revealed_tile_to_move = revealed_tiles.find(t=> t.position.x == revealed_tiles_default_x ); // If there are NO still-visible tiles, we must need to reset the map: if( ! next_revealed_tile_to_move ) { // To reset the map, we go through each tile and put it back where it belongs - for(tile of revealed_tiles){ canvas.scene.updateEmbeddedDocuments("Tile", [ { _id: tile.id, x: revealed_tiles_default_x, hidden: false } ]); } } else { // Otherwise, hide the topmost visible tile (and move it off to the side to help the GM) - canvas.scene.updateEmbeddedDocuments("Tile", [ { _id: next_revealed_tile_to_move.id, x: revealed_tiles_modified_x, hidden: true } ]); }
I hope that the rest of the code is moderately self-explanatory for anybody with a little JavaScript experience, but if you’re just following this kind of simple, linear case then you don’t need to modify it anyway. But to summarise, what it does is:
- Finds the first listed tile that isn’t yet hidden (by comparing its X-position to the pre-set X-position).
- If there aren’t any such tiles, we must have hidden them all already, so perform a reset: to do this – iterate through each tile and set its X-position to the pre-set X-position, and un-hide it.
- Otherwise, move the first not-hidden tile to the alternative X-position and hide it.
I hope you have fun with scripting your own multi-phase maps. Just don’t get so caught-up in your awesome scenes that you fail to give the players any agency!
Footnotes
1 Also, it’s on sale at 20% off this week to celebrate its fourth anniversary. Just sayin’.
2 I can neither confirm nor deny that a multi-phase map might be in the near future of The Levellers‘ adventure…
3 AtraxianBear has a great series of maps inspired by the 1683 siege of Vienna by the Ottomans that could be a great starting point for a “gradually advancing siege” map.
4 If you’re using Dungeon Alchemist as part of your mapmaking process you can just export orthographic or perspective outputs with different times of day and your party’s regular inn can be appropriately lit for any time of day, even if the party decides to just “wait at this table until nightfall”.
5 Balatro made a stunning map with rising water as a key feature: there’s a preview available.
Let Your Players Lead The Way
I’ve been GMing/DMing/facilitating1 roleplaying games for nearby 30 years, but I only recently began to feel like I was getting to be good at it.
The secret skill that was hardest for me to learn? A willingness to surrender control to the players.
Karma, Drama, Fortune
I could write a lot about the way I interpret the K/D/F model, but for today here’s a quick primer:
The K/D/F model describes the relationship between three forces: Karma (player choices), Drama (story needs) and Fortune (luck, e.g. dice rolls). For example,
- When the lich king comes to the region to provide a villainous plot hook, that’s Drama. Nobody had to do anything and no dice were rolled. The story demanded a “big bad” and so – within the limitations of the setting – one turned up.
- When his lucky critical hit kills an ally of the adventurers, that’s Fortune. That battle could have gone a different way, but the dice were on the villain’s side and he was able to harm the players. When we don’t know which way something will go, and it matters, we hit the dice.
- When one of the heroes comes up with a clever way to use a magical artefact from a previous quest to defeat him, that’s Karma. It was a clever plan, and the players were rewarded for their smart choices by being able to vanquish the evil thing.
- And elsewhere on their quest they probably saw many other resolutions. Each of those may have leaned more-heavily on one or another of the three pillars, or balanced between them equally.
Disbalancing drama
For most of my many years of gamemastering, I saw my role as being the sole provider the “drama” part of the K/D/F model. The story comes from me, the choices and dice rolls come from the players, right?
Nope, I was wrong. That approach creates an inevitable trend, whether large or small, towards railroading: “forcing” players down a particular path.
A gamemaster with an inflexible and excessively concrete idea of the direction that a story must go will find that they become unable to see the narrative through any other lens. In extreme examples, the players are deprotagonised and the adventure just becomes a series of set pieces, connected by the gamemaster’s idea of how things should play out. I’ve seen this happen. I’ve even caused it to happen, sometimes.2
A catalogue of failures
I’ve railroaded players to some degree or another on an embarrassing number of occasions.
In the spirit of learning from my mistakes, here are three examples of me being a Bad GM.
Quantum Ogre
Scenario: In a short-lived high fantasy GURPS campaign, I wanted the party to meet a band of gypsies and have their fortune told, in order to foreshadow other parts of the story yet to come.
What I did: I pulled a quantum ogre (magician’s choice) on them: whether they travelled by road, or water, or hacked their way through the forest, they were always going to meet the gypsies: their choice of route didn’t really matter.
Why that was wrong: I’d elevated the value of the encounter I’d planned higher than the importance of player agency. The more effort it took to write something, the more I felt the need to ensure it happened!
Two things I could’ve done: Reassessed the importance of the encounter. Found other ways to foreshadow the plot that didn’t undermine player choices, and been more-flexible about my set pieces.
Fudging
Scenario: In a Spirit of the Century one-shot an antagonist needed to kidnap a NPC from aboard an oceanbound ship. To my surprise – with some very lucky rolls – the players foiled the plot!
What I did: I used a fudge – an exploit based on the fact that in most games the gamemaster controls both the plot and the hidden variables of the game mechanics – to facilitate the antagonist kidnapping a different NPC, and adapted the story to this new reality.
Why that was wrong: It made the players feel like their choices didn’t matter. I justified it to myself by it being a one-shot, but that undermines the lesson: I could’ve done better.
Two things I could’ve done: Used the failed attack as a precursor to a later renewed offensive by a villain who’s now got a personal interest in seeing the party fail. Moved towards a different story, perhaps to a different element of the antagonist’s plan.
Ex Machina
Scenario: In a long-running Warhammer Fantasy Roleplay (1st edition!) campaign, a series of bad choices and terrible luck left the party trapped and unable to survive the onslaught of a literal army of bloodthirsty orcs.
What I did: I whipped out a deus spiritus ex machina, having a friendly ghost NPC
basically solve for them a useful puzzle they’d been struggling with, allowing them to escape alive (albeit with the quest truly failed).
Why that was wrong: It deprotagonised the adventurers, making them unimportant in their own stories. At the time, I felt that by saving the party I was “saving” the game, but instead I was undermining its value.
Two things I could’ve done: TPK: sometimes it’s the right thing to allow everybody to die! Pivot the plot to facilitate their capture (e.g. the arch-nemesis can’t solve the puzzle either and wants to coerce them into helping), leading to new challenges and interesting moral choices.
Those examples are perhaps extreme, but I’m pretty sure I’ve set up my fair share of lesser sins too. Like chokepoints that strongly encourage a particular direction: do that enough and you train your players to wait until they identify the chokepoint before they take action! Or being less invested in players’ plans if those plans deviate from what I anticipated, and having a convenient in-party NPC prompting players with what they ought to do next. Ugh.3
The good news is, of course, that we’ve all always got the opportunity for growth and self-improvement.
The self-improvement path
I’ve gotten better at this in general over the years, but when I took over from Simon at DMing for The Levellers in July, I decided that I was going to try to push myself harder than ever to avoid railroading. Simon was always especially good at promoting player freedom and autonomy, and I wanted to use this inspiration as a vehicle to improve my own gamemastering.
What does that look like within the framework of an established campaign?
Well: I ensure there are clues (usually three of them!) to point the players in the “right” direction. And I’ll be on hand to give “nudges” if they’re truly stuck for what to do next, typically by providing a “recap” of the things they’ve previously identified as hooks that are worth following-up (including both the primary plotline and any other avenues they’ve openly discussed investigating).
But that’s the limit to how I allow Drama to control the direction of the story. Almost everything else lies in the hands of Karma and Fortune.
Needless to say, opening up the possibility space for my players makes gamemastering harder4! But… not by as much as I expected. Extra prep-work was necessary, especially at the outset, in order to make sure that the world I was inheriting/building upon was believable and internally-consistent (while ensuring that if a player decided to “just keep walking East” they wouldn’t fall off the edge of the world). But mostly, the work did itself.
Because here’s the thing I learned: so long as you’re willing to take what your players come up with and run with it, they’ll help make the story more compelling. Possibly without even realising it.5
The Levellers are a pretty special group. No matter what the situation, they can always be relied upon to come up with a plan that wasn’t anywhere on their DM‘s radar. When they needed to cross a chasm over their choice of one of two bridges, each guarded by a different variety of enemy, I anticipated a few of the obvious options on each (fighting, magic, persuasion and intimidation, bribery…) but a moment later they were talking about having their druid wildshape into something easy-to-carry while everybody else did a group-spider climb expedition down the chasm edge and along the underside of a bridge. That’s thinking outside the box!
But the real magic has come when the party, through their explorations, have unlocked entirely new elements of the story.
Player-driven content
In our campaign, virtually all of the inhabitants of a city have inadvertently sold their immortal souls to a Archduchess of Hell by allowing, over generations, their declaration of loyalty to their city to become twisted away from their gods and towards their mortal leader, who sold them on in exchange for a sweet afterlife deal. The knights of the city were especially-impacted, as the oath they swore upon promised their unending loyalty in this life as well. When the fiendish pact was made, these knights were immediately possessed by evil forces, transforming into horrendous creatures (who served to harass the party for some time).
But there’s a hole in this plot7. As-written, at least one knight avoided fiendish possession and lived to tell the tale! The player characters noticed this and latched on, so I ran with it. Why might the survivor knights be different from those who became part of the armies of darkness? Was there something different about their swearing-in ceremony? Maybe the reasons are different for different survivors?I didn’t have answers to these questions to begin with, but the players were moving towards investigating, so I provided some. This also opened up an entire new possible “soft” quest hook related to the reason for the discrepancy. So just like that, a plothole is discovered and investigated by a player, and that results in further opportunities for adventure.
As it happens, the party didn’t even go down that route at all and instead pushed-on in their existing primary direction, but the option remains. All thanks to player curiosity, there’s a possible small quest that’s never been written down or published, and is unique to our group and the party’s interests. And that’s awesome.
In Conclusion
I’m not the best GM in the world. I’m not even the best GM I know. But I’m getting better all the time; learning lessons like how to release the reins a little bit and see where my players can take our adventures.
And for those lessons, I’m grateful to those same players.
Footnotes
1 I’m using the terms GM, DM, and facilitator interchangeably, and damned if I’m writing them all out every single time.
2 A gamemaster giving all of the narrative power to any one of the three elements of K/D/F breaks the game, but in different ways. 100% karma and what you’ve got is a storytelling game, not a roleplaying game: which is fine if that’s what everybody at the table thinks they’re playing: otherwise not. 100% drama gives you a recital, not a jam session: the gamemaster might as well just be writing a book. 100% fortune leads to unrealistic chaos: with no rules to the world (either from the plot or from the consequences of actions) you’re just imagining all possible outcomes in your universe and picking one at random. There’s a balance, and where it sits might vary from group to group, but 100% commitment to a single element almost always breaks things.
3 A the “lesser sins” I mention show, the edges of what construes railroading and what’s merely “a linear quest” is a grey area, and where the line should be drawn varies from group to group. When I’m running a roleplaying session for my primary-school-aged kids, for example, I’m much more-tolerant of giving heavy-handed nudges at a high-level to help them stay focussed on what their next major objective was… but I try harder than ever to encourage diverse and flexible problem-solving ideas within individual scenes, where childish imagination can really make for memorable moments. One time, a tabaxi warrior, on fire, was falling down the outside of a tower… but his player insisted that he could shout a warning through the windows he passed before landing in flawless catlike fashion (albeit mildly singed). My adult players would be rolling athletics checks to avoid injury, but my kids? They can get away with adding details like that by fiat. Different audience, see?
4 A recent session took place after a hiatus, and I wasn’t confident that – with the benefit of a few months’ thinking-time – the party would continue with the plan they were executing before the break. And they didn’t! I’d tried to prep for a few other eventualities in the anticipation of what they might do and… I guessed wrong. So, for the first time in recorded history, our session ended early. Is that the end of the world? Nope.
5 Want a really radical approach to player-driven plot development? Take a look at this video by Zee Bashew, which I’m totally borrowing from next time I start running a new campaign.
6 You know what I miss? Feelies. That’s probably why I try to provide so many “props”, whether physical or digital, in my adventures.
7 The plothole isn’t even my fault, for once: it’s functionally broken as-delivered in the source book, although that matters little because we’ve gone so-far outside the original source material now we’re on a whole different adventure, possibly to reconvene later on.
Fedicard
[Bloganuary] Playtime
This post is part of my attempt at Bloganuary 2024. Today’s prompt is:
Do you play in your daily life? What says “playtime” to you?
How do I play? Let me count the ways!
RPGs
I’m involved in no fewer than three different RPG campaigns (DMing the one for The Levellers) right now, plus periodic one-shots. I love a good roleplaying game, especially one that puts character-building and storytelling above rules-lawyering and munchkinery, specifically because that kind of collaborative, imaginative experience feels more like the kind of thing we call “play” when done it’s done by children!
Videogames
I don’t feel like I get remotely as much videogaming time as I used to, and in theory I’ve become more-selective about exactly what I spend my time on1.
Board Games
Similarly, I don’t feel like I get as much time to grind through my oversized board games collection as I used to2, but that’s improving as the kids get older and can be roped-into a wider diversity of games3.
Escape Rooms
I love a good escape room, and I can’t wait until the kids are old enough for (more of) them too so I’ve an excuse to do more of them. When we’re not playing conventional escape rooms, Ruth and I can sometimes be found playing board game-style boxed “kit” ones (which have very variable quality, in my experience) and we’ve recently tried a little Escape Academy.
GNSS Activities
I’m sure everybody knows I do a modest amount of geocaching and geohashing.4
They’re not the only satnav-based activities I do at least partially “for fun” though! I contribute to OpenStreetMap, often through the “gamified” experience of the StreetComplete app, and I’m very slowly creeping up the leader board at OpenBenches. Are these “play”? Sure, maybe.
And all of the above is merely the structured kinds of play I engage in. Playing “let’s pretend”-style games with the kids (even when they make it really, really weird) adds a whole extra aspect. Also there’s the increasingly-rare murder mystery parties we sometimes hold: does that count as roleplaying, or some other kind of play?
Suffice to say, there’s plenty of play in my life, it’s quite varied and diverse, and there is, if anything, not enough of it!
Footnotes
1 I say that, and yet somehow Steam tells me that one of my most-played games this year was Starfield, which was… meh? Apparently compelling enough that I’ve “ascended” twice, but in hindsight I wish I hadn’t bothered.
2 Someday my group and I will finish Pandemic Legacy: Season 2 so we can get started on Season 0 which has sat unplayed on my shelves since I got it… oooh… two or three years ago‽
3 This Christmas, I got each of them their first “legacy” game: Zombie Kids for the younger one, My City for the elder. They both seem pretty good.
4 Geocaching is where you use military satellite networks to find lost tupperware. Geohashing uses the same technology but what you find is a whole lot of nothing. I don’t think I can explain why I find the latter more-compelling.
Paul Labyrinth
This is a repost promoting content originally published elsewhere. See more things Dan's reposted.
Known Leaders is an open-source program that combines WikiData with a random generator to come up with almost-invariably inaccurate but sometimes hilarious facts. Jim Kang came up with it during Recurse Center‘s Never Graduate Week. Go have a play, or read more about how and why he made it.
Have Fun with Missions, Visions, and Values
I just spent a lightweight week in Rome with fellow members of Automattic‘s Team Fire.
Among our goals for the week was an attempt to strengthen the definition of who are team are, what we work on, and how and why we do so. That’s basically a team-level identity, mission, vision, and values, right?
Fellow Automattician Ben Dwyer recently wrote about his experience of using a deck of Dixit cards to help his team refine their values in a fun and engaging way. I own a Dixit set, so we decided to give it a go too.
Normally when you play Dixit, you select a card from your hand – each shows a unique piece of artwork – and try to describe it in a way that’s precise enough that some of the other players will later be able to pick it out of a line-up, but ambiguous enough that not all the other players will. It’s a delicate balancing act. Even when our old Geek Night was in full swing we didn’t used to play it often because our well-established group’s cornucopia of in-jokes and references made it trivially easy to “target” your descriptions at specific players1, but it’s still a solid icebreaker activity.
Perhaps it was the fantasy artwork that inspired us or maybe it just says something about how my team sees themselves, but what we came up with had a certain… swords-and-sorcery… even Dungeons & Dragons… feel to it.
Ou team’s new identity isn’t finalised, but I love the fact that we’ve been able to inject a bit of fun and whimsy into it. At our last draft, my team looks to be defined as comprising:
- Gareth, level 62 Pathfinder, leading the way through the wilds
- Bero, Level 5 Battlesmith, currently lost in the void
- Dan (me!), Level 5 Arcane Trickster, breaking locks and stealing treasure
- Cem, Level 4 Dragonslayer, smashing doors and bugs alike
- Lae, Level 7 Pirate, seabound rogue with eyes on the horizon
- Kyle, Level 5 Apprentice Bard, master of words and magic
- Simran, Level 6 Apprentice Code Witch, weaving spells from nature
I think that’s pretty awesome.
Sisyphus: The Board Game (Digital Edition)
I’m off work sick today: it’s just a cold, but it’s had a damn good go at wrecking my lungs and I feel pretty lousy. You know how when you’ve got too much of a brain-fog to trust yourself with production systems but you still want to write code (or is that just me?), so this morning I threw together a really, really stupid project which you can play online here.
It’s inspired by a toot by Mason”Tailsteak” Williams (whom I’ve mentioned before once or twice). At first I thought I’d try to calculate the odds of winning at his proposed game, or how many times one might expect to play before winning, but I haven’t the brainpower for that in my snot-addled brain. So instead I threw together a terrible, terrible digital implementation.
Go play it if, like me, you’ve got nothing smarter that your brain can be doing today.
Beating Children at Mastermind [Video]
This post is also available as an article. So if you'd rather read a conventional blog post of this content, you can!
This video accompanies a blog post of the same title. The content is basically the same – if you prefer videos, watch this video. If you prefer blog posts, go read the blog post. You might also like to play with my Mastermind solver or view the source code.
Beating Children at Mastermind
This post is also available as a video. If you'd prefer to watch/listen to me talk about this topic, give it a look.
This blog post is also available as a video. Would you prefer to watch/listen to me tell you about how I’ve implemented a tool to help me beat the kids when we play Mastermind?
I swear that I used to be good at Mastermind when I was a kid. But now, when it’s my turn to break the code that one of our kids has chosen, I fail more often than I succeed. That’s no good!
Mastermind and me
Maybe it’s because I’m distracted; multitasking doesn’t help problem-solving. Or it’s because we’re “Super” Mastermind, which differs from the one I had as a child in that eight (not six) peg colours are available and secret codes are permitted to have duplicate peg colours. These changes increase the possible permutations from 360 to 4,096, but the number of guesses allowed only goes up from 8 to 10. That’s hard.
Or maybe it’s just that I’ve gotten lazy and I’m now more-likely to try to “solve” a puzzle using a computer to try to crack a code using my brain alone. See for example my efforts to determine the hardest hangman words and make an adverserial hangman game, to generate solvable puzzles for my lock puzzle game, to cheat at online jigsaws, or to balance my D&D-themed Wordle clone.
Hey, that’s an idea. Let’s crack the code… by writing some code!
Representing a search space
The search space for Super Mastermind isn’t enormous, and it lends itself to some highly-efficient computerised storage.
There are 8 different colours of peg. We can express these colours as a number between 0 and 7, in three bits of binary, like this:
Decimal | Binary | Colour |
---|---|---|
0
|
000
|
Red |
1
|
001
|
Orange |
2
|
010
|
Yellow |
3
|
011
|
Green |
4
|
100
|
Blue |
5
|
101
|
Pink |
6
|
110
|
Purple |
7
|
111
|
White |
There are four pegs in a row, so we can express any given combination of coloured pegs as a 12-bit binary number. E.g. 100 110 111 010
would represent the
permutation blue (100
), purple (110
), white (111
), yellow (010
). The total search space, therefore, is the range of numbers from
000000000000
through 111111111111
… that is: decimal 0 through 4,095:
Decimal | Binary | Colours |
---|---|---|
0
|
000000000000
|
Red, red, red, red |
1
|
000000000001
|
Red, red, red, orange |
2
|
000000000010
|
Red, red, red, yellow |
………… | ||
4092
|
|
White, white, white, blue |
4093
|
|
White, white, white, pink |
4094
|
|
White, white, white, purple |
4095
|
|
White, white, white, white |
Whenever we make a guess, we get feedback in the form of two variables: each peg that is in the right place is a bull; each that represents a peg in the secret code but isn’t in the right place is a cow (the names come from Mastermind’s precursor, Bulls & Cows). Four bulls would be an immediate win (lucky!), any other combination of bulls and cows is still valuable information. Even a zero-score guess is valuable- potentially very valuable! – because it tells the player that none of the pegs they’ve guessed appear in the secret code.
Solving with Javascript
The latest versions of Javascript support binary literals and bitwise operations, so we can encode and decode between arrays of four coloured pegs (numbers 0-7) and the number 0-4,095
representing the guess as shown below. Decoding uses an AND bitmask to filter to the requisite digits then divides by the order of magnitude. Encoding is just a reduce
function that bitshift-concatenates the numbers together.
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 |
/** * Decode a candidate into four peg values by using binary bitwise operations. */ function decodeCandidate(candidate){ return [ (candidate & 0b111000000000) / 0b001000000000, (candidate & 0b000111000000) / 0b000001000000, (candidate & 0b000000111000) / 0b000000001000, (candidate & 0b000000000111) / 0b000000000001 ]; } /** * Given an array of four integers (0-7) to represent the pegs, in order, returns a single-number * candidate representation. */ function encodeCandidate(pegs) { return pegs.reduce((a, b)=>(a << 3) + b); } |
With this, we can simply:
- Produce a list of candidate solutions (an array containing numbers 0 through 4,095).
- Choose one candidate, use it as a guess, and ask the code-maker how it scores.
- Eliminate from the candidate solutions list all solutions that would not score the same number of bulls and cows for the guess that was made.
- Repeat from step #2 until you win.
Step 3’s the most important one there. Given a function getScore( solution, guess )
which returns an array of [ bulls, cows ]
a given guess
would
score if faced with a specific solution
, that code would look like this (I’m convined there must be a more-performant way to eliminate candidates from the list with XOR
bitmasks, but I haven’t worked out what it is yet):
164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 |
/** * Given a guess (array of four integers from 0-7 to represent the pegs, in order) and the number * of bulls (number of pegs in the guess that are in the right place) and cows (number of pegs in the * guess that are correct but in the wrong place), eliminates from the candidates array all guesses * invalidated by this result. Return true if successful, false otherwise. */ function eliminateCandidates(guess, bulls, cows){ const newCandidatesList = data.candidates.filter(candidate=>{ const score = getScore(candidate, guess); return (score[0] == bulls) && (score[1] == cows); }); if(newCandidatesList.length == 0) { alert('That response would reduce the candidate list to zero.'); return false; } data.candidates = newCandidatesList; chooseNextGuess(); return true; } |
I continued in this fashion to write a full solution (source code). It uses ReefJS for component rendering and state management, and you can try it for yourself right in your web browser. If you play against the online version I mentioned you’ll need to transpose the colours in your head: the physical version I play with the kids has pink and purple pegs, but the online one replaces these with brown and black.
Testing the solution
Let’s try it out against the online version:
As expected, my code works well-enough to win the game every time I’ve tried, both against computerised and in-person opponents. So – unless you’ve been actively thinking about the specifics of the algorithm I’ve employed – it might surprise you to discover that… my solution is very-much a suboptimal one!
My solution is suboptimal
A couple of games in, the suboptimality of my solution became pretty visible. Sure, it still won every game, but it was a blunt instrument, and anybody who’s seriously thought about games like this can tell you why. You know how when you play e.g. Wordle (but not in “hard mode”) you sometimes want to type in a word that can’t possibly be the solution because it’s the best way to rule in (or out) certain key letters? This kind of strategic search space bisection reduces the mean number of guesses you need to solve the puzzle, and the same’s true in Mastermind. But because my solver will only propose guesses from the list of candidate solutions, it can’t make this kind of improvement.
Search space bisection is also used in my adverserial hangman game, but in this case the aim is to split the search space in such a way that no matter what guess a player makes, they always find themselves in the larger remaining portion of the search space, to maximise the number of guesses they have to make. Y’know, because it’s evil.
There are mathematically-derived heuristics to optimise Mastermind strategy. The first of these came from none other than Donald Knuth (legend of computer science, mathematics, and pipe organs) back in 1977. His solution, published at probably the height of the game’s popularity in the amazingly-named Journal of Recreational Mathematics, guarantees a solution to the six-colour version of the game within five guesses. Ville [2013] solved an optimal solution for a seven-colour variant, but demonstrated how rapidly the tree of possible moves grows and the need for early pruning – even with powerful modern computers – to conserve memory. It’s a very enjoyable and readable paper.
But for my purposes, it’s unnecessary. My solver routinely wins within six, maybe seven guesses, and by nonchalantly glancing at my phone in-between my guesses I can now reliably guess our children’s codes quickly and easily. In the end, that’s what this was all about.
Printing Maps from Dungeondraft
I really love Dungeondraft, an RPG battle map generator. It’s got great compatibility with online platforms like Foundry VTT and Roll20, but if you’re looking to make maps for tabletop play, there’s a few tips I can share:
Planning and designing
Dungeondraft has (or can be extended with) features to support light levels and shadow-casting obstructions, openable doors and windows, line-of sight etc… great to have when you’re building for Internet-enabled tabletops, but pointless when you’re planning to print out your map! Instead:
- Think about scale: I’m printing to A4 sheets and using inch-size squares, so every 11 x 8 squares equates to one sheet of paper. Knowing this, I can multiply-up to a whole number of sheets of paper and this informs my decisions about how to best make use of the maps (and what will and won’t fit on my dining table!).
- Focus on legibility: Your printer probably won’t have the same kind of resolution as your screen, and your players can’t “zoom in” to get details. Play with the grid styles (under Map Settings) to find what works best for you, and try not to clash with your floor patterns. If you’re printing in monochrome, use the “Printer-Friendly” camera filter (also under Map Settings, or in the Export Options dialog) to convert to gorgeous line-art. Make sure critical elements have sufficient contrast that they’ll stand out when printed or your players might walk right over that chest, campfire, or bookshelf.
- Think about exposure: You don’t get digital “fog of war” on the tabletop! Think about how you’re going to reveal the map to your players: plan to print in multiple sections to put together, jigsaw style, or have card to “cover” bits of the map. Think about how the tool can help you here: e.g. if you’ve got multiple buildings the players can explore, use a higher “level” or roof layer to put roofs on your buildings, then print the relevant parts of that level separately: now you’ve got a thematic cover-up that you can remove to show the insides of the building. Go the other way around for secret doors: print the empty wall on your main map (so players can’t infer the location of the secret door by the inclusion of a cover-up) and the secret door/passage on the overlay, so you can stick it onto the map when they find it.
Printing it out
There’s no “print” option in Dungeondraft, so – especially if your map spans multiple “pages” – you’ll need a multi-step process to printing it out. With a little practice, it’s not too hard or time-consuming, though:
Export your map (level by level) from Dungeondraft as PNG files. The default settings are fine, but pay attention to the “Overlay level” setting if you’re using smart or complex cover-ups as described above.
To easily spread your map across multiple pages, you’ll need to convert it to a PDF. I’m using Gimp to do this. Simply open the PNG in Gimp, make any post-processing/last minute changes that you couldn’t manage in Dungeondraft, then click File >
Export As… and change the filename to have a .pdf
extension. You could print directly from Gimp, but in my experience PDF reader software does a much better job at multi-page printing.
Open your PDF in an appropriate reader application with good print management. I’m using Foxit, which is… okay? Print it, selecting “tile large pages” to tell it to print across multiple sheets. Assuming you’ve produced a map an appropriate size for your printer’s margins, your preview should be perfect. If not, you can get away with reducing the zoom level by up to a percent or two without causing trouble for your miniatures. If you’d like the page breaks to occur at specific places (for exposure/reveal reasons), go back to Gimp and pad one side of the image by increasing the canvas size.
Check the level of “overlap” specified: I like to keep mine low and use the print margins as the overlapping part of my maps when I tape them together, but you’ll want to see how your printer behaves and adapt accordingly.
If you’re sticking together multiple pages to make a single large map, trim off the bottom and right margins of each page: if you printed with cut marks, this is easy enough even without a guillotine. Then tape them together on the underside, taking care to line-up the features on the map (it’s not just your players who’ll appreciate a good, visible grid: it’s useful when lining-up your printouts to stick, too!).
I keep my maps rolled-up in a box. If you do this too, just be ready with some paperweights to keep the edges from curling when you unfurl them across your gaming table. Or cut into separate rooms and mount to stiff card for that “jigsaw” effect! Whatever works best for you!
The Board Game Remix Kit
This is a repost promoting content originally published elsewhere. See more things Dan's reposted.
New rules for old games! The Board Game Remix Kit is a collection of tips, tweaks, reimaginings and completely new games that you can play with the board and pieces from games you might already own: Monopoly, Cluedo, Scrabble and Trivial Pursuit.
The 26 rule tweaks and new games include:
- Full Houses: poker, but played with Monopoly properties
- Citygrid: a single-player city-building game
- Use Your Words: Scrabble with storytelling
- Them’s Fightin’ Words: a game of making anagrams, and arguing about which one would win in a fight
- Hunt the Lead Piping: hiding and searching for the Cluedo pieces in your actual house
- Guess Who Done It: A series of yes/no questions to identify the murderer (contributed by Meg Pickard)
- Zombie Mansion: use the lead piping to defend the Cluedo mansion
- Judy Garland on the Moon with a Bassoon: a drawing game that uses the answers to trivia questions as prompts
The Board Game Remix Kit was originally released in 2010 by the company Hide&Seek (which closed in 2014). We are releasing it here as a pdf (for phones/computers) and an epub (for ereaders) under a CC-BY-SA license.
If you enjoy the Kit and can afford it, please consider a donation to the World Health Organisation’s COVID-19 Response Fund.
Confined to your house? What a great opportunity to play board games with your fellow confinees.
Only got old family classics like Monopoly, Cluedo and Scrabble? Here’s a guide to mixing-them-up into new, fun, and highly-playable alternatives. Monopoly certainly needs it.
Cheating Hangman
A long while ago, inspired by Nick Berry‘s analysis of optimal Hangman strategy, I worked it backwards to find the hardest words to guess when playing Hangman. This week, I showed these to my colleague Grace – who turns out to be a fan of word puzzles – and our conversation inspired me to go a little deeper. Is it possible, I thought, for me to make a Hangman game that cheats by changing the word it’s thinking of based on the guesses you make in order to make it as difficult as possible for you to win?
The principle is this: every time the player picks a letter, but before declaring whether or not it’s found in the word –
- Make a list of all possible words that would fit into the boxes from the current game state.
- If there are lots of them, still, that’s fine: let the player’s guess go ahead.
- But if the player’s managing to narrow down the possibilities, attempt to change the word that they’re trying to guess! The new word must be:
- Legitimate: it must still be the same length, have correctly-guessed letters in the same places, and contain no letters that have been declared to be incorrect guesses.
- Harder: after resolving the player’s current guess, the number of possible words must be larger than the number of possible words that would have resulted otherwise.
You might think that this strategy would just involve changing the target word so that you can say “nope” to the player’s current guess. That happens a lot, but it’s not always the case: sometimes, it’ll mean changing to a different word in which the guessed letter also appears. Occasionally, it can even involve changing from a word in which the guessed letter didn’t appear to one in which it does: that is, giving the player a “freebie”. This may seem counterintuitive as a strategy, but it sometimes makes sense: if saying “yeah, there’s an E at the end” increases the number of possible words that it might be compared to saying “no, there are no Es” then this is the right move for a cheating hangman.
Playing against a cheating hangman also lends itself to devising new strategies as a player, too, although I haven’t yet looked deeply into this. But logically, it seems that the optimal strategy against a cheating hangman might involve making guesses that force the hangman to bisect the search space: knowing that they’re always going to adapt towards the largest set of candidate words, a perfect player might be able to make guesses to narrow down the possibilities as fast as possible, early on, only making guesses that they actually expect to be in the word later (before their guess limit runs out!).
I also find myself wondering how easily I could adapt this into a “helpful hangman”: a game which would always change the word that you’re trying to guess in order to try to make you win. This raises the possibility of a whole new game, “suicide hangman”, in which the player is trying to get themselves killed and so is trying to pick letters that can’t possibly be in the word and the hangman is trying to pick words in which those letters can be found, except where doing so makes it obvious which letters the player must avoid next. Maybe another day.
In the meantime, you’re welcome to go play the game (and let me know what you think, below!) and, if you’re of such an inclination, read the source code. I’ve used some seriously ugly techniques to make this work, including regular expression metaprogramming (using regular expressions to write regular expressions), but the code should broadly make sense if you want to adapt it. Have fun!
Update 26 September 2019, 16:23: I’ve now added “helpful mode”, where the computer tries to cheat on your behalf rather than against you, but it’s not as helpful as you’d think because it assumes you’re playing optimally and have already memorised the dictionary!
Update 1 October 2019, 06:40: Now featured on MetaFilter; hi, MeFites!