Skip to content

Instantly share code, notes, and snippets.

@Karang
Karang / cg_spring_2025_pm.md
Last active April 14, 2025 10:30
CG Spring Challenge 2025

General algorithm

I used a DFS with a cache. DFS is implemented with a stack and a while loop, no function call. I used 2 stacks, one for the generated boards containing only the board as an int32 and one for the parent board with the hash being accumulated, the number of children and the permutation (used for symetries).

Board representation & SWAR

I used 3 bit per cell in a board fitted into a 32bit integer. I never decode that representation into an array, instead I use SWAR (SIMD within a register) to do computations, shuffling and tests. During move generation, two operations are quite useful: add_saturate and zmask. The first one adds each of the 9 cells of two input board, if the result overflows it is clamped to 7 (maximum representable value in 3 bits). The second set the top bit of each cell to one if the cell is zero, otherwise it clears all bits of the cell.