Only 15 days later, Victor Allis announced his independently discovered solution, described in his thesis.
Inspired by these results, I set out to strongly solve the game by compiling a database of all 8-ply positions with their theoretical result. This took about 40,000 hours of computation on the Sun and SGI workstations at the CWI. A subset of this database, namely the 67557 unfinished and unforced positions, is available as a dataset for machine learning experiments. The value of all 1+7+49+343+2401=2801 up to 4-ply positions turned out to make a nice illustration for my own thesis cover. With the help of this database, any position in the game can be evaluated in a matter of seconds.
If you see no PLAY! button right below this line, then your browser has Java absent or disabled; I suggest you try this Javascript based solver instead, which also sports a more conventional interface.
This applet plays a perfect game of connect-4 with the help of the 8-ply database (read from a 12Kbyte compressed file). The applet understands the keys b, f, m, 1-7 and q for back, forward, move, play, and quit. The right mouse button takes you back or forward to when a certain stone was played.
Solving connect-4 positions also makes a decent benchmark aptly named Fhourstones as a pun on the Dhrystone benchmark. The included source is a useful guide to writing an exhaustive alpha-beta search program with a transposition table and dynamic move ordering.
This somewhat improved board logic code shows how to best represent connect-4 bitboards, test for a win with 8 shifts/ands, and encode a position in 49 bits. Dominikus Herzberg offers this detailed explanation for the benefit of his students.
Based on that code and a smarter transposition table replacement strategy, my solver is now busy compiling results on different board sizes:
height | |||||||||
---|---|---|---|---|---|---|---|---|---|
11 | = | ||||||||
10 | = | = | |||||||
9 | = | = | + | ||||||
8 | = | = | - | + | - | ||||
7 | = | = | + | = | + | ||||
6 | = | = | - | + | - | - | |||
5 | = | = | = | = | + | + | + | ||
4 | = | = | - | = | - | - | - | - | |
4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | width |
height | |||||||||
---|---|---|---|---|---|---|---|---|---|
8 | 9 | 13343 | 8424616 | 1104642469 | |||||
7 | 8 | 4587 | 1417322 | 135385909 | 14171315454 | ||||
6 | 7 | 1571 | 235781 | 15835683 | 1044334437 | 69173028785 | 4531985219092 | ||
5 | 6 | 537 | 38310 | 1706255 | 69763700 | 2818972642 | 112829665923 | ||
4 | 5 | 179 | 6000 | 161029 | 3945711 | 94910577 | 2265792710 | 54233186631 | |
3 | 4 | 58 | 869 | 12031 | 158911 | 2087325 | 27441956 | 362940958 | |
2 | 3 | 18 | 116 | 741 | 4688 | 29737 | 189648 | 1216721 | |
1 | 2 | 5 | 13 | 35 | 96 | 267 | 750 | 2118 | |
1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | width |