
A parallel connect4 AI player written in a webgpu shader.
Does a minimax evaluation on the current game state, looking 8 moves ahead at all possible game states. Expands the tree out 3 levels which results in 343 game states, those are then each evaluated on a gpu thread to check 5 more moves ahead. All in all it looks at 5,764,801 different game states to make it's decision.
Runs pretty quickly on an M series mac or on a computer with a good gpu. Can be kinda slow if you only have an integrated gpu and probably doesn't work at all on most phones. I basically just wrote it to work well on my computer, I could probably tune it to run better on the device it's loaded on.
I'm pretty new to gpu programming and I don't think this is really the best way to do this. The code is very branchy and it's likely that is slowing things down a lot. Ideally each gpu "thread" should run the same instructions since a thread in a gpu is really more like a simd lane. When the threads diverge I think you lose a lot of the throughput.