Difference between revisions of "Hex theory"

From HexWiki
Jump to: navigation, search
(Winning strategy for non-square boards: Fixed proof error - connection symmetry is only for groups within one of the triangles)
(Winning strategy for non-square boards)
Line 40: Line 40:
 
   contents="R arrow(12):a2 j:b2 B j:b1 arrow(2):a3 S red:(b1 a2) blue:(b2 a3) "/>
 
   contents="R arrow(12):a2 j:b2 B j:b1 arrow(2):a3 S red:(b1 a2) blue:(b2 a3) "/>
  
Now ''{r(1),r(2),...,r(j-1)}'' lies entirely within the red triangle, and so the cells in the blue triangle with corresponding labels ''{b(1),b(2),...,b(j-1)}'' must all be Blue and form a connected chain from the right edge to ''b(j-1)'' since the adjacency relationships are the same within the 2 triangles, and so ''{r(1),r(2),...,r(j-1),b(j-1),b(j-2),...,b(2),b(1)}'' forms a connected chain from the top edge to the right edge.  Notice that ''{r(j),r(j+1),...,r(k)}'' cannot contain any of the cells ''{b(1),b(2),...,b(j-1)}'' because they are Blue, or the cells ''{r(1),r(2),...,r(j-1)}'' by minimality of R, and so cannot connect ''r(j)'' to the bottom edge (although this may be difficult to prove).
+
Now ''{r(1),r(2),...,r(j-1)}'' lies entirely within the red triangle, and so the cells in the blue triangle with corresponding labels ''{b(1),b(2),...,b(j-1)}'' must all be Blue and form a connected chain from the right edge to ''b(j-1)'' since the adjacency relationships are the same within the 2 triangles, and so ''{r(1),r(2),...,r(j-1),b(j-1),b(j-2),...,b(2),b(1)}'' forms a connected chain from the top edge to the right edge.  Notice that ''{r(j),r(j+1),...,r(k)}'' cannot contain any of the cells ''{r(1),r(2),...,r(j-1)}'' by minimality of R (so intuitively ''r(j)'' is cut off from bottom edge giving a contradiction as we shall show). Also ''r(1)'' is the only Red cell on the top row, by minimality of R, so if we set the cells ''{r(1),r(2),...,r(j-1)}'' to Blue, this produces a chain of Blue pieces entirely within the red triangle connecting ''r(j-1)'' to the left edge via ''{r(1),r(2),...,r(j-1)}'' and the top row, and does not alter the  Red chain ''{r(j),r(j+1),...,r(k)}'', which is assumed to connect ''r(j)'' to the bottom edge.
  
Alternatively, (in a similar manner to the Gayle proof of no draws) we can consider the directed boundary between cells containing Red and Blue pieces beginning at the boundary between ''r(j-1)'' and ''b(j-1)'' (the arrowed pieces in the diagram) in the direction away from ''r(j)''.  The cells to the left bank of this directed boundary are all connected to ''b(j-1)'' and hence to the right edge.  The cells to the right bank of this directed boundary are ''{r(j-1),r(j-2),...}'', which are all within the red triangle.  If this directed boundary meets the left edge, this gives a connection from ''b(j-1)'' to the left edge, otherwise the directed boundary meets the top edge, and this gives a connection from ''b(j-1)'' to the cell on the top row to the immediate left of ''r(1)''.  However ''r(1)'' is the only Red cell on the top row, by minimality of R, so the Blue cell to its left, and hence also ''b(j-1)'', is connected to the left edge, giving the required contradiction.
+
<hexboard size="6x5"
 +
  coords="none"
 +
  contents="S red:all blue:area(a6,e6,e2)
 +
            B arrow(8):c3 arrow(2):c4
 +
            R arrow(6):d3 "
 +
  />
 +
 
 +
Now, if we add a short diagonal between the two triangles, making an ''(n+1)x(n+1)'' board, and set one cell on this short diagonal to Blue, linking ''r(j-1)'' to ''b(j-1)'' (the 2 Blue arrowed cells) and the rest to Red, then any connected Red group from the smaller board, together with adjacent Red pieces on the short diagonal is still connected on the larger board, so ''r(j)'' is still connected to the bottom edge.  Also, since ''r(j-1)'' and ''b(j-1)'' are connected to the left and right edges respectively by Blue chains entirely within the red and blue triangles respectively, they are still connected on the larger board, and so there is a Blue chain linking the left and right edges via ''r(j-1)'', the Blue piece on the short diagonal and ''b(j-1)''.
 +
 
 +
<hexboard size="6x6"
 +
  coords="none"
 +
  contents="S red:area(a1,a5,e1) blue:area(b6,f6,f2)
 +
            B arrow(8):c3 arrow(2):d4 d3
 +
            R arrow(6):e3 f1 e2 c4 b5 a6 "
 +
  />
 +
 
 +
But ''r(j)'' is now connected to the top edge via the short diagonal, so there is also a Red chain linking the top and bottom edges on the larger board.  This gives the required contradiction.
 +
 
 +
Alternatively, (on the smaller board without changing ''{r(1),r(2),...,r(j-1)}'' from Red to Blue) we can consider the directed boundary between cells containing Red and Blue pieces (in a similar manner to the Gayle proof of no draws) beginning at the boundary between ''r(j-1)'' and ''b(j-1)'' (the arrowed pieces in the 4-cell diagram above) in the direction away from ''r(j)''.  The cells to the left bank of this directed boundary are all connected to ''b(j-1)'' and hence to the right edge.  The cells to the right bank of this directed boundary are ''{r(j-1),r(j-2),...}'', which are all within the red triangle.  If this directed boundary meets the left edge, this gives a connection from ''b(j-1)'' to the left edge, otherwise the directed boundary meets the top edge, and this gives a connection from ''b(j-1)'' to the cell on the top row to the immediate left of ''r(1)''.  However ''r(1)'' is the only Red cell on the top row, by minimality of R, so the Blue cell to its left, and hence also ''b(j-1)'', is connected to the left edge, giving the required contradiction.
  
 
This shows that Red cannot have a winning path, so Blue must have a winning path. ∎
 
This shows that Red cannot have a winning path, so Blue must have a winning path. ∎

Revision as of 12:09, 23 January 2021

Unlike many other games, it is possible to say certain things about Hex, with absolute certainty. Whether this makes Hex a better game is of course debatable, but many find this attribute charming.

The most important properties of Hex are the following:

Winning Strategy

These first and third statements are proved below. The second statement is a simply consequence of the swap rule: since Hex has no draws, each move is either winning or losing. If the opening move would be winning without the swap rule, the second player swaps and inherits the win. If the opening move would be losing, the second player declines to swap and goes on to win. Thus, the second player can always win.

No winning strategy for Blue

In chess, while nobody seriously believes that black has a winning strategy, nobody has been able to disprove it. On the other hand, in Hex, a simple strategy-stealing argument shows that the second player cannot have a winning strategy, and therefore the first player must have one.

In fact, we can prove a more general statement: for boards of size n×n, any position that is symmetric (i.e., invariant by reflection about the short or long diagonal and inverting the color of the pieces) is a winning position for the next player to move under optimal play. This follows from the fact that Hex is a monotone game: a position with additional pieces of a player's color is always at least as good for that player as the position without the additional pieces. If "passing" were allowed, it would therefore never be to a player's advantage to pass. If the second player to move had a winning strategy for a symmetric position, then the first player to move could simply steal that strategy by passing and therefore themselves becoming the second player to move. Since passing does not help the player, they also have a winning strategy without passing, contradicting the assumption that the other player was winning.

Winning strategy for non-square boards

Consider a board of size (n+1) × n. In this case, Blue has a shorter distance to cover than Red. Blue has the following second-player winning strategy. Divide the board into two triangles as shown.

abcde123456123456789510111294131412831514117215131061

Now whenever Red plays in the red triangle, Blue responds by playing in the cell of the same number in the blue triangle, and vice versa. After filling all of the cells in this way, Red cannot have a winning path as outlined below.

Assume for a contradiction that Red does have a winning path, then let R be a minimal subset of the Red piece positions that connects the Red edges (i.e. no subset of R connects the Red edges) and set all other cells to Blue. It can be shown that R is a chain of connected cells {r(1),r(2),...,r(k)} with r(1) on the top row, r(k) on the bottom row and r(i) adjacent to r(i+1) for 0<i<k.

Let r(j) be the first cell of this chain in the blue triangle above, then r(j-1) is in the red triangle and must be in the 9 o'clock direction from r(j) because the cell in the 11 o'clock direction has the same number label as r(j), and so must be Blue.

jj

Now {r(1),r(2),...,r(j-1)} lies entirely within the red triangle, and so the cells in the blue triangle with corresponding labels {b(1),b(2),...,b(j-1)} must all be Blue and form a connected chain from the right edge to b(j-1) since the adjacency relationships are the same within the 2 triangles, and so {r(1),r(2),...,r(j-1),b(j-1),b(j-2),...,b(2),b(1)} forms a connected chain from the top edge to the right edge. Notice that {r(j),r(j+1),...,r(k)} cannot contain any of the cells {r(1),r(2),...,r(j-1)} by minimality of R (so intuitively r(j) is cut off from bottom edge giving a contradiction as we shall show). Also r(1) is the only Red cell on the top row, by minimality of R, so if we set the cells {r(1),r(2),...,r(j-1)} to Blue, this produces a chain of Blue pieces entirely within the red triangle connecting r(j-1) to the left edge via {r(1),r(2),...,r(j-1)} and the top row, and does not alter the Red chain {r(j),r(j+1),...,r(k)}, which is assumed to connect r(j) to the bottom edge.

Now, if we add a short diagonal between the two triangles, making an (n+1)x(n+1) board, and set one cell on this short diagonal to Blue, linking r(j-1) to b(j-1) (the 2 Blue arrowed cells) and the rest to Red, then any connected Red group from the smaller board, together with adjacent Red pieces on the short diagonal is still connected on the larger board, so r(j) is still connected to the bottom edge. Also, since r(j-1) and b(j-1) are connected to the left and right edges respectively by Blue chains entirely within the red and blue triangles respectively, they are still connected on the larger board, and so there is a Blue chain linking the left and right edges via r(j-1), the Blue piece on the short diagonal and b(j-1).

But r(j) is now connected to the top edge via the short diagonal, so there is also a Red chain linking the top and bottom edges on the larger board. This gives the required contradiction.

Alternatively, (on the smaller board without changing {r(1),r(2),...,r(j-1)} from Red to Blue) we can consider the directed boundary between cells containing Red and Blue pieces (in a similar manner to the Gayle proof of no draws) beginning at the boundary between r(j-1) and b(j-1) (the arrowed pieces in the 4-cell diagram above) in the direction away from r(j). The cells to the left bank of this directed boundary are all connected to b(j-1) and hence to the right edge. The cells to the right bank of this directed boundary are {r(j-1),r(j-2),...}, which are all within the red triangle. If this directed boundary meets the left edge, this gives a connection from b(j-1) to the left edge, otherwise the directed boundary meets the top edge, and this gives a connection from b(j-1) to the cell on the top row to the immediate left of r(1). However r(1) is the only Red cell on the top row, by minimality of R, so the Blue cell to its left, and hence also b(j-1), is connected to the left edge, giving the required contradiction.

This shows that Red cannot have a winning path, so Blue must have a winning path. ∎


An analogous strategy works for all boards of size n×m with n > m. If the difference between n and m is greater than 1, Blue can simply ignore the additional rows, say at the bottom of the board, i.e., pretend that they have already been filled with Red pieces. If Red moves in the ignored area, Blue can pass (or in case passing is not permitted, Blue can move anywhere).

Since we showed that Blue has a second-player winning strategy, it follows that Blue also has a first-player winning strategy, since the additional move cannot hurt Blue.

For symmetric reasons, Red has a winning strategy when n < m.

See parallelogram boards for an analysis of how much headstart the player with the larger distance needs to win, for different non-square boards.

No draw

If a Hex board is full then there is one and only one player connecting their edges. See also draw. The proof idea is quite simple. On a full Hex board, consider the set A of all red cells that are connected to Red's top edge. If this set contains a cell on Red's bottom edge, then Red is the winner. Otherwise, Blue has a winning path by going along the boundary of A.

Links to more detailed proofs are on Javhar's page "Hex cannot end in a draw".

Complexity

  • The problem of determining the winner of a given Hex position (on a board of size n×n) is PSPACE-complete. The fact that it is a member of PSPACE is not surprising, because one can decide the winner by simply exploring the entire game tree, i.e., by playing every possible sequence of moves, which takes only a polynomial amount of memory. The fact that this decision problem is PSPACE-hard was first proved by Stefan Reisch in 1979.

Several other related decision problems are also PSPACE-complete. For example:

  • The detection of virtual connections is PSPACE-complete. Clearly, this problem is in PSPACE, since one can decide the validity of a virtual connection by exploring every possible sequence of moves within the given carrier set. The fact that it is PSPACE-hard follows from the PSPACE-hardness of detecting a winning position, since a board position is winning (for the second player) if and only if it gives a virtual connection between the player's two edges.
  • The detection of dominated cells is PSPACE-complete. More specifically, given a board size, a position on that board, a player to move, and two empty cells X and Y, the problem of deciding whether X dominates Y is PSPACE-complete. To see why it is in PSPACE, note that it is sufficient to check for each of X and Y whether it is a winning move for the player in question. X dominates Y if and only if X is a winning move or Y is not a winning move. For PSPACE-hardness, consider the following position on a board of size (n+2)×(n+2), where the cells marked "*" denote some arbitrary position of an n×n board:

    abcdef123456

    For Red, the move at b1 is clearly winning, whereas the move at c1 is winning if and only if Red has a first-player win in the game marked "*". Therefore, b1 dominates c1. Moreover, c1 dominates b1 if and only if Red has a first-player winning strategy for "*". Moreover, b1 strictly dominates c1 if and only if Red has no such strategy. Since answering the latter question on the n×n board is PSPACE-hard, it follows that both domination and strict domination are PSPACE-hard problems.

There are some computational problems in Hex that are easier than PSPACE.

  • The problem of deciding whether a given cell is dead is in co-NP. Equivalently, the problem of deciding whether a given cell is alive is in NP. This is because an empty cell is alive if and only if it belongs to some minimal winning path, relative to the given board position. Given such a path, it is checkable in polynomial time whether it is winning and minimal. Björnsson et al. showed that recognizing alive nodes is NP-complete in the Shannon game, a generalization of Hex. It is not known whether recognizing alive cells in Hex is also NP-complete or whether it is easier.

Solving Hex

See also

Open problems

External links