Follow-up of the first part.
So, we know a couple of things about Hackenbush. We know a few outcomes: “Left wins”, “Right wins”, and “second player wins”. We’re missing one more: “first player wins”… What would “first player wins” be?
Consider . Here, whoever to move is forced to move to the zero game, which is a loss for the player to move. Thus here, the first player wins, as the second player loses. But what is its value?
This is not positive, as a positive value indicates that Left wins. Not negative either, as it means Right wins. Not zero too, since the first player instead of the second player is the one that wins! So this is not a number like our previous games are. Mathematicians call this , the star game.
But can a star game appear in Hackenbush?
As it turns out, no, it cannot! Hackenbush doesn’t allow star games. Thus to look at star games, we need to change games.
One possible approach is to make a variant of Hackenbush. The original Hackenbush is called Blue-Red Hackenbush, since it uses the colors blue and red. Let’s modify this into Blue-Red-Green Hackenbush, which adds edges of a third color, green, which can be removed by either player.
Thus, what is a Blue-Red-Green Hackenbush with a single green segment?
Exactly, it’s the star game. Whichever player to move must leave the zero game to the other player, thus this is .
We can analyze a few more positions here, but let’s turn our attention to another possible game that introduces stars… Nim.
In Nim, we have several piles, each containing some stones. In the position above, we have stones with 1, 3, and 6 stones; for convenience, we will call this position , so I don’t have to keep making images. The rules are simple: each player takes any number of stones from a single pile. Thus for example, a player might take four stones from the pile of 6, turning to the position , or they can remove the entire first pile, leaving . The winner, of course, is the player that makes the last move. Note that the only way to have no move left is if all stones are removed.
Here we see what’s called an impartial game, where the same moves are available to both players, compared to partisan game like Blue-Red Hackenbush where not the same moves are available to the players. (Note that in Blue-Red-Green Hackenbush, if the position contains only green edges (and thus the same moves are available to both players), it is also an impartial game.) Note that in an impartial game, there is no concept of “Left wins” or “Right wins”; only “first player wins” or “second player wins”.
First, as moves are available to both players, we can shorten our notation of a position: instead of repeating the same thing twice like , we’ll just do it once like . This makes it closer in notation to a set; but then again a position is simply a set of available moves!
Also, for convenience, let’s call to be a pile of stones. Thus the position above is . Note how two different piles never affect each other from the rules, hence why we can just assume they are separate games that are added together. You still remember game additions, no?
The simplest pile is , having no stone at all! This is clearly a zero game, so .
The next simplest pile is . A pile of one stone is just like a position of a single green segment in Blue-Red-Green Hackenbush, with the only available move reducing to , or the zero game. So .
What about ? What position is this? Listing out the moves, we get … Uh oh, what is this? This is nothing we have encountered before.
Well, mathematicians also decide to just ditch it, making yet another notation. is the value, called the nimber , which represents the value of , the pile with piles. So , and many more… We also see that the value for the position depicted in the image is . Can we simplify this?
Let’s start analyzing a few things. What is ?
Remember how zero games never affect additions? Yes, since is just the zero game, the result is simply . Thus . Also, of course, .
What about ? Let’s list the moves. We can either move in the first game, reducing it to , or in the second game, reducing it to… . Well, either way, we’re left with , so . What is its value?
Well, since is a win for the player to move, and the first player must move to that, we have the second player wins; in other words, . Or we can think in Nim piles: a Nim position with two piles, each of size 1. The first player must take one of the stones; note that they cannot take both. The second player must also take the remaining stone, but that means the second player wins.
Let’s try generalizing it. If we have , what is its value? Think in terms of Nim piles first; you have two equal-sized piles, who wins?
We can see that the second player wins. To see this, the second player simply mirror the first player’s move on the other pile, leaving both piles equal. If we start with , and the first player reduces the first pile to 3, then the second player mirrors it, reducing the second pile to 3 too, giving . If the first player then reduces the second pile down to zero, the second player also cleans up the first pile, leaving which is the zero game, as there is no move left. So first player loses. So . This can also be proven by induction; if we have the result for all , then we can conclude the same when too, proving the claim for all . Well, this addition is surely a weird thing…
Note how we had from our discussion of ? That is, a position having but not ? This is not our usual Nim pile, but turns out we can still simplify it. Let's generalize it. Suppose we have a position whose values are nimbers, but not necessarily in the form for some . For example, doesn’t have . What is its value?
Suppose that our position includes , but is missing . Let's consider the game . If the first player moves in , reducing it to where , then the second player can move in to ; remember how a pile of stones can be reduced to stones if ? Then the second player simply moves in the same game, reducing it to , since and thus is a move from . And now .
Thus we see the second player wins, and thus must have been the zero game after all! This strongly suggests that , since we know that . As it turns out, we can prove that indeed. Thus we know a rule: the value of any position whose available moves are nimbers is itself a nimber, equal to the smallest missing value of the available moves. Applying to , as the smallest missing value is , we have . Similarly, even though might seem to be such a wide array of moves, it is missing , so it is still the zero game anyway. Additionally, this fits with what we know: follows the rule too!
So, armed with this, let’s return back to addition. What is the value of ? Listing its moves, we have . So . And then, we also have . Well, this will be hard.
A relatively nice method for a human to compute the sum is to make a table of addition. For convenience, let’s assume the rows are ordered in ascending order from top to bottom, and so as the columns from left to right.
The above has been partially filled with what we have known.
Now pick a cell we want to compute, look on all cells above or to the left of our cell (but not both!), and find the smallest missing value.
Yes, keep doing this.
If you know the XOR operation, the table is precisely that. We can prove that it is indeed the case, but for now we’re satisfied enough with having a table.
Thus, to compute , we can just use the table:
What if we want to find a winning strategy for Nim? For example, who wins the above? Since is a win for the first player to move (the first player moves to ), the first player wins. But what move?
We know that . Now we try adding each of the piles with and see which one reduces the count. For example, , so we cannot move on the first pile, as we would need to add four stones to it instead of removing stones. , so it doesn’t work either, but , so we can move in the third pile, reducing it to 2 stones. We can show that there always exists one such pile as long as the original value is not , so there’s always a winning strategy for the player not having .
Well, that was math heavy, wasn’t it? But you still need to be prepared. The third part, and the final part of the series for now, will walk you through the game induced by my Monorail move (put 1-3 tiles that are contiguous in a straight line and stuff).