Need Help with a Tic Tac Toe MiniMax Algorithm

I know it’s a lot to ask, but I’ve rewritten this 3 times from complete scratch using various Javascript versions as references and trying to recreate them in Blueprints over the past 3 days.

Anyone familiar with the MiniMax Algorithm? For the life of me I can’t figure out why mine don’t work. It seems to be keeping the first move it runs across every time…the thing is I’ve fairly sure I have recreated the algorithm just like the example I seen from a Javascript version…

image

Here is the Log

LogBlueprintUserMessages: [GM_TicTacToe_C_1] Final Move: (0.0,1.0)
LogBlueprintUserMessages: [GM_TicTacToe_C_1] Player: Computer Move: (2,2) CurrentScore: 10 Depth: 0
LogBlueprintUserMessages: [GM_TicTacToe_C_1] Coords: (0,2) Score: 10
LogBlueprintUserMessages: [GM_TicTacToe_C_1] Move Over
LogBlueprintUserMessages: [GM_TicTacToe_C_1] Player: Computer Move: (0,2) CurrentScore: 10 Depth: 0
LogBlueprintUserMessages: [GM_TicTacToe_C_1] Coords: (2,2) Score: 10
LogBlueprintUserMessages: [GM_TicTacToe_C_1] Final Move: (0.0,2.0)

Blueprintue.com doesn’t read Enumerators so all of those fields will have enumerator0 or whatever written in them…basically the Max sets the AI move, Calls MiniMax with the Player as Input and then sets the move back to Empty…the for loops check to see if the positions are empty. On Best Move it’s Initialized as Minimizing Player with the Player as input. On the Check win it returns -10 if the Player Won, 10 if the Computer Won, and 0 if no one has won.

Best Move Function

MiniMax Algorithm

This one Checks for the Winner

To give for information:
During debugging I discovered this…

The Score 10 is only ever returned by the Human if the AI Won

And

The Score -10 is only ever returned by the AI if the Human Won

I never see the Human return -10 If the Human Won or the AI return 10 if the AI won

i cant offer any direct help here, but i just wanted to point out a resource that may be of interest for reference:
there is a blueprint chess project on the marketplace that i’m almost positive is using min/max algorithm.

I was doing some java tutorials for chess to get some basic programming practice though i didnt get to minmax implementation yet. I had bookmarked that blueprints chess in case i needed to see some blueprint examples without pulling my hair out, lol.

Thanks, I’ll check that out…still not exactly sure what I was doing wrong but here is the latest.

I figured it out…man, it took me 4 entire days and I ended up rebuilding the entire algorithm from scratch 4 times, once for every day…and spent the rest of the day trying to debug it.

Here are my scores for the Minimax algorithm. My Wins are on the left

Round 1 = 0:1
Round 2 = Tie
Round 3 = 0:2
Round 4 = 0:3
Round 5 = Tie
Round 6 = Tie
Round 7 = 1:4
Round 8 = Tie

It’s not unbeatable, but I’m also limiting it to how many moves ahead it can look and there may still be a slight bug in it somewhere

Here is the guide I followed.
How to make your Tic Tac Toe game unbeatable by using the minimax algorithm (freecodecamp.org)

I figured it out, I have confirmed that my board without the first move being random makes the same exact moves in response to me as the one I designed the algorithm around. The Solution would be too complex to explain here, simply put I was just doing things wrong.