Hi, I’ve been working on a 3d tic tac toe, which I expanded a bit into multi-dimensional (2D + 3 different board sizes, 3x3, 4x4 and 5x5x5 for example)
So you can make 3 in a row vertically as well.
I’ve implemented the minimax algorithm with alpha beta pruning for the computer AI, but it gets too slow at higher dimensions (4x4x4). Here is the live game and code:
https://3-dads-tactical-tuba-time.vercel.app/
https://github.com/pkdvalis/3-Dads-Tactical-Tuba-Time
Enable minimax with “Medium” or “Hard” difficulty. I use a fallback algorithm on 4x4x4 board and 5x5x5 which is faster. You can confirm if minimax is running in the console it should say “Running minimax depth 5”
Questions for feedback:
-
Is there a better or faster algorithm I could use?
Pruning improved performance a lot, 3x3x3 is now playable where it used to take 3 minutes to pick the first move. 4x4x4 still takes 1 minute to make it’s first move. Controlling the maximum depth helps but it’s either too slow, or the moves are too bad. -
When the player moves, it waits until the computer has made it’s move before rendering both moves. How could I render the player move first before the computer is thinking? More noticeable on 3x3x3 (on Medium or Hard difficulty)
Any other advice for improvement or how to organize my code is greatly appreciated. There might also be bugs I haven’t seen yet.
I noticed in this tutorial that more things seem to be rolled into objects which might make more readable code and I can pass an object as a prop instead of 50 variables, I might try this first.
JavaScript Tic Tac Toe Project Tutorial - Unbeatable AI w/ Minimax Algorithm




