Part 5 – Column exploration order

Alpha-beta allows to prune the exploration tree by taking into account the score of the first explored nodes to narrow the [alpha;beta] exploration window of their next sibling nodes. Exploring the best node first will thus allow to have the maximal reduction of the exploration window for the next nodes. On the contrary, exploring the nodes in the worst order (start with worst score first and finish with best score) won’t allow much pruning and have performance close to min-max algorithm.

There are many heuristics to try to order the possible moves in an optimal order. If you use a score function, you can use it for the next move or at a shallow depth. Other heuristics keep track of the moves that made cut-off at similar depth for previously explored nodes and try them first.

We will just implement a static column order strategy, exploring center columns first and edge columns at the end. Center columns are in average better moves in Connect 4 because they are involved in more possible alignments.

Implementation.

Implementation is straitforward, you just need to explore the next possible moves in a different static order. The order is initialize in the constructor of the Solver class.

Here are:

Benchmark

You can see that this very simple column exploration re-ordering allows to reduce significantly (more than 10-fold) the number of explored nodes and computation time. The improvement is greater for position needing deeper exploration.

SolverTest Set namemean timemean nb posK pos/s
Column exploration order (strong solver)End-Easy40.86 μs139.73,417
Column exploration order (strong solver)Middle-Easy189.1 ms2,081,79011,009
Column exploration order (strong solver)Middle-Medium3.48 s40,396,70011,594
Column exploration order (strong solver)Begin-EasyN/AN/AN/A
Column exploration order (strong solver)Begin-MediumN/AN/AN/A
Column exploration order (strong solver)Begin-HardN/AN/AN/A
Column exploration order (weak solver)End-Easy31.16 μs107.13,438
Column exploration order (weak solver)Middle-Easy77.13 ms927,94312,031
Column exploration order (weak solver)Middle-Medium1.949 s23,685,40012,153
Column exploration order (weak solver)Begin-EasyN/AN/AN/A
Column exploration order (weak solver)Begin-MediumN/AN/AN/A
Column exploration order (weak solver)Begin-HardN/AN/AN/A

mean time: average computation time (per test case). mean nb pos: average number of explored nodes (per test case). N/A means that the algorithm was too slow to evaluate the 1,000 test cases within 24h.

Tutorial plan

Updated: