HIP
Copyright (c) 1960 Martin Gardner
The game is played on a NxN square. The board starts empty
- MOVE - Each player drops a stone into an empty cell, which does not form a square with 3 other placed stones of the same color.
- Squares are not just formed by orthogonal lines, they can make any slope with the board edge.
- GOAL - Wins the player that moved the last stone.
An example White cannot play at [1] since it would form a square with c5,e4 and d2 stones.
Black cannot also play there since it would form a black square with b5, d5 and d3.
Gardner, on his legendary Scientific American articles, states that if the board size is even (like the 8x8 Chess board), the game is a win for the 2nd player. Why? He just needs to mirror what the 1st player is doing, until his opponent is out of legal moves. There are two ways to remedy this:
1) Play on odd sized boards, with a center cell where the 2nd player cannot continue to use the mirror strategy.
2) Each player moves twice (except for the first move of the first player). This version, called DM Hip was designed by Mark Thompson and is presented at his website.
In July 2014 I received an email from Kurt Alan Franke which wrote a min-max solver and found that the 5x5 version is a win for player 2 (the solver evaluated 8331853 positions). He also wrote a blog entry about this which I'll copy-paste here in the interest of posterity:
[The 6x6 board]
an interesting problem to solve numerically. There are 2^36 possible filled board positions, but “only” 36 choose 18 have an even number of counters. We know that the 6x6 board has possible draw games, but how many? And what about larger or smaller boards?
The 6x6 board has 2^36 possible filled board positions. Iterating through all of them and checking for a draw game takes ~1 hour. 7x7 boards have 2^49 possible filled board positions — that will take a long time to iterate through.
But there is a trick! A 6x6 subset of a draw game on a 7x7 board must be a draw game on a 6x6 board. We only need to iterate through all possible 6x6 draw games, and for each one expand with all possible combinations for the 2*6+1 additional board places. Using this strategy, the results are calculated extremely fast. I used straight c for this because of the abundance of bit-twiddling involved.
Here are the number of draw games as the board size increases. Playable draws are restricted to states that can be reached during game play whereas “draws” are any filled board with no completed squares, even if the number of pieces played by each side is not equal.
- Board Draws Playable Draws
- (2x3) 50 20
- (3x3) 248 92
- (3 x 4) 1236 482
- (4 x 4) 5006 2094
- (4 x 5) 18282 7236
- (5 x 5) 7120 2704
- (5 x 6) 5684 2316
- (6 x 6) 56 24
- (6 x 7) 0 0
- (7 x 7) 0 0
So there are no draw games on boards larger than 6x6. The number of draws first increases rapidly as the possible number of filled boards goes up exponentially, but then falls quickly since the possible number of “squares” is increasing.
Can you find a draw board for the 6x6 game by hand?
Next question: What is the value of the game for the different board sizes? If both players are perfect, will the game be a draw, or will player 1 or player two win the game?
So, to answer this question, I wrote a min-max solver to find the value of the game of Hip. The search space increases rapidly with board size, as players may play on any open place. Consider: at a size of 6x7 or larger, there must be a winner because there are no draw positions. The smaller boards have many draw positions, so it seems likely that the values of these games are zero. Boards with an odd number of spaces seem to favor player 2 because player 1 has to make the first and last moves.
A simple exhaustive min-max search got bogged down on 4x4 boards, but there were room for improvements:
- Cache computed results with a hash of the board state.
- Cache the state symmetrically to avoid repeating different rotations/inversions of the same position.
- Use a heuristic to order the search of possible plays at each level. This is a simple position evaluator which tries to score each move based on partially completed squares and plays no longer available (because they would complete a square).
- Optimize the weighting factors for the heuristic by calculating the number of function calls needed for solving mid-sized games. The most important factor seems to be avoidance of obstructing the opponent’s partially completed squares.
- Instead of having both players trying to win, allow one to be satisfied with a draw. If the other player can’t beat the draw-accepting opponent, then he also couldn’t beat the cut-throat opponent. On the other hand, if he *can* beat the draw-accepting opponent, then he could beat any opponent. Of course, this won’t help in pruning the search tree on larger games where no draw is possible.
Using these improvements, I was able to solve the 5x5 game in 30 seconds of run time. I also looked at a variant called Double-Hip where player 1 first makes a single move followed by players taking turns making two moves at a time.
The hippest winners (standard hip):
Columns are board size, winner (or 0 for draw), number of minMax() calls
- 2x2 0 25
- 2x3 0 151
- 2x4 0 513
- 2x5 0 3046
- 2x6 0 13528
- 2x7 0 53801
- 2x8 0 209741
- 2x9 0 966712
- 2x10 0 4672889
- 2x11 0 24160738
- 2x12 0 128431909
- 2x13 0 693940594
- 2x14 0 3914022690
- 3x3 0 1152
- 3x4 0 13588
- 3x5 0 91577
- 3x6 0 553238
- 3x7 0 9373741
- 3x8 0 43565423
- 3x9 0 1579968088
- 3x10 0 8326162019
- 3x11 2 836468053068
- 4x4 0 143191
- 4x5 0 2047147
- 4x6 0 33405985
- 4x7 2 148339665
- 4x8 2 2512894759
- 4x9 2 59706092136
- 5x5 2 18497405
- 5x6 2 238732219
- 5x7 2 8841991760
- 6x6 2 45650574451
Double hip:
- 2x2 0 24
- 2x3 0 140
- 2x4 0 642
- 2x5 0 2677
- 2x6 0 12817
- 2x7 0 41236
- 2x8 0 169427
- 2x9 0 727970
- 2x10 0 3595501
- 2x11 0 17365736
- 2x12 0 89847914
- 2x13 0 462033442
- 2x14 0 2488845822
- 3x3 2 718
- 3x4 0 11738
- 3x5 1 42993
- 3x6 0 532264
- 3x7 2 2032602
- 3x8 0 43098332
- 3x9 1 176813342
- 3x10 0 6939859704
- 3x11 2 32870151228
- 4x4 0 145907
- 4x5 1 1076920
- 4x6 1 8222698
- 4x7 1 112612598
- 4x8 1 2459422890
- 4x9 1 146032800681
- 5x5 1 69554600
- 5x6 2 367440552
- 5x7 2 8024602689
- 6x6 2 52499400683
Player 2 seems to have the advantage on larger games. A strange game. The only way to win is not to play… first.