The Game of Hex: Using Virtual Connections to Detect Win State

The Game of Hex: Using Virtual Connections to
Detect Win State
Emily Sarich
December 19, 2015
Abstract
The Game of Hex, though simple enough in concept, has puzzled and
delighted mathematicians and computer scientists for decades. Still unsolved for arbitrary board size, I attempted to create a Hex player that
can play on any board size by looking at virtual connections. Using virtual connections, a player can win more games and do it in fewer moves.
Though my Hex player has not yet solved the mystery of arbitrary board
size, it has made progress in the right direction.
1
Introduction & History
Invented in 1942 by Danish mathematician Piet Hein, the game of Hex became a
very popular topic among mathematicians in 1948 when John Nash rediscovered
its interesting mathematical properties. At a high level, Hex requires the same
level of strategy as games like Chess and Go, but the rules are much simpler:
players take turns placing colored stones onto a rhombus-shaped board of empty
hexagon-shaped cells, and try to be the first player to connect two opposite sides
of the board with their own stones. There are many variations to the game,
including one where players try to avoid connecting their two sides, and the
Game of Y, where players try to connect all three sides of a triangular board.
What makes Hex and games like it particularly interesting, though, is the fact
that the game cannot end in a tie [2]. As Gale explains, the idea of this proof is
fairly simple, but the underlying proof is much more complicated. On a square
board, one player connecting two opposite sides makes it impossible for the
other player to connect the other two sides (see Figure 1).
Over the years, there have been many attempts to solve the game. It was
quickly discovered that a simple decision tree would be ineffective, as the game
has a tremendous branching factor for larger board sizes (the standard board size
is 11x11, which means 121 possible cells). Because of this, mathematicians and
programmers have turned to other methods for computer Hex players. Other
successful Hex players have determined that a full tree search isn’t necessary,
since only a small number of game moves must be considered at a time [1].
Early methods used alpha beta search, but the strongest Hex player now uses
1
Figure 1: As we can see, the blue player’s path blocks the red player’s path in
all ways [3]
the Monte Carlo Tree Search, which is used in many Go players. These Hex
players all have one thing in common, though: they all use virtual connections
to win the game. This semester, I attempted to explore the idea of virtual
connections and how they were calculated used to win the game of Hex.
In Section 2, I will go into more detail about virtual connections and define
them more clearly. Then, in Section 3, I will discuss my implementation and
how I used them in my Hex Player. Section 4 will include a summary of my
results and conclusions.
2
A Two-Player Game
Though my goal for the semester was to create a Hex playing program, my first
step was to create a functional two-player version of the game, which proved to
be more of a challenge than I anticipated. One of the biggest difficulties was
checking for a win state (where one player successfully connected one side to its
opposite side). To avoid having to check every cell for connectivity after every
turn, I had each cell on the board keep track of all the edges it is connected
to. When a piece is played, the cell updates its own edges to include the edges
of its connected neighbors, checks to see if a win state is reached, and if not,
recursively updates the edges of all of its neighboring cells. Because of this, we
only have to check the most recently played cell for a win state. This algorithm
also proved useful later in my calculation of virtual connections, since the same
idea of checking and updating neighboring cells can be applied to virtually
connected cells just as it is applied to actual connections.
3
Virtual Connections
Before I explain how I used virtual connections to play Hex, I will first define
in more detail what they are. Anshelevich defines virtual connections as such:
?Two groups of black cells x and y? form virtual connection iff White cannot
prevent Black from connecting them, even if White moves first? [1]. Virtual
2
Figure 2: an example of a virtual connection between cells A and D (assuming
cells B and M1 are unoccupied)
connections are the key to creating a functional Hex player. Strong virtual
connections create an impenetrable wall that blocks the opposing player from
reaching the other side while also getting closer to your own win state. This is
what makes Hex a beautiful game: any defensive move made against the other
player doubles as an offensive move, bringing the player closer to winning the
game.
In my project I focused on virtual connections of two cells, referred to as
two-bridges. These virtual connections consist of two endpoints, which are
the occupied cells, and a group of two empty cells that make up the virtual
connection. Finding and identifying these bridges was actually quite challenging.
Though I kept track of each cell?s neighboring cells, these bridges are composed
of adjacent neighbors of a given cell. To remedy this, I took advantage of certain
properties of the Hex board.
As we see in Figure 2, given a cell and one of its neighbors, we can find the
two adjacent cells by looking at mutual neighbors. Cell B is a neighbor of Cell
A. The mutual neighbors of Cell A and Cell B (let?s call that Na [int] Nb) is a
set of two cells, let?s call them M1 and M2. As we can see, Cell B and Cell M1,
and Cell B and Cell M2 are adjacent neighbors to Cell A. To determine cells
that form two-bridge virtual connections with Cell A, we look at the mutual
neighbors of the two Cells that make up the connection (In this case, Cell B
and Cell M1). The mutual neighbors of these two cells are Cell A, the occupied
cell, and Cell D, an unoccupied cell that, if Black plays there, will form a virtual
connection between Cell A and Cell D. In this way, we can find all the potential
virtual neighbors of a cell, and from there, play a stone on one of those cells to
create a virtual connection that creates a connection towards the opposite side.
We keep track of these virtual connections in the same way that we keep track
of actual connections between two cells.
3
4
Using Virtual Connections
My Hex player uses this concept of virtual connections to leapfrog across the
board, creating a row of virtually connected cells from one side of the board
to the other. It checks for an open group of cells to form a bridge with, and
executes one of them. Each cell keeps track of its own virtual connections as
well as its actual connections, and after each piece is played, these lists are
recursively updated. This way, each cell acts as an active branch coming from
each edge, and a win state is reached when two of these branches meet up.
Once the Hex Player has created a virtually connected bridge from one side
of the board to the other, it starts to fill in these connections to turn the virtual
connections into actual connections. At this point, none of these connections
can be broken by the white player by the definition of a virtual connection, so
a win is guaranteed for Black.
5
Results & Conclusions
My Hex player is good at creating and filling in virtual connections, but it
still struggles with creating the right virtual connections. The current version
doesn?t have much of an evaluation function for determining which of the potential virtual connections is best, so it will sometimes mistakenly connect one
edge to itself rather than going from one side to another. It is also unable to
backtrack to previously played pieces, basing the next set of moves solely on
the last stone played. This results in the player often hitting dead ends, where
it can make no other virtual connections. Essentially, my Hex player is fantastic at end-game strategy, but not the greatest at the early part of the game,
when there are many more options for open cells. Once a virtual win has been
detected, this player can execute the right sequence of moves to win the game,
but detecting such a win is not a simple task.
I plan on continuing to work on my Hex player in the future, adding several
features that I didn?t have time to implement in one semester of work. My
original plan included a cool user interface with sweet graphics, but I ended up
with a simple text-based player because functionality was more important to
me than aesthetics. I would also, of course, like to improve the Hex player itself.
I?d like to give it the ability to recognize and fill in larger virtual connections,
backtrack to previous virtually connected branches, and make smarter moves
earlier in the game.
4
References
[1] Vadim V Anshelevich. The game of hex: An automatic theorem proving
approach to game programming. In AAAI/IAAI, pages 189–194, 2000.
[2] David Gale. The game of hex and the brouwer fixed-point theorem. The
American Mathematical Monthly, 86(10):818–827, 1979.
[3] Wikipedia Images. Hex (board game). https://en.wikipedia.org/wiki/
Hex_%28board_game%29.
5