Success! (Sort of)
With my mentor’s algorithm as a guide I was able to get a working version of Minimax up and running. The final gap in my own solution that I started to glimpse last Friday morning was that my comparison of the “best move” for the min and max players needed separate logic. I had started to build it out into two separate methods for the min and max moves, but keeping it all in one method is much cleaner.
I have just one final anomaly to figure it out. It’s currently returning all of the squares as possible opening moves when it should only choose a corner. Yesterday it was choosing the corners but I made an egregious error in my refactoring process today that has bitten me in the ass.
I had a test that the opening move would return a corner…. but since my algorithm isn’t optimized it takes about 2 to 3 minutes to play through all of the scenarios on an empty board (to determine the opening move). So while I was busily red, green, refactoring I commented out that test— and I didn’t uncomment it at regular enough intervals to figure out which refactoring might have led me astray. Fortunately it still doesn’t lose after a dumb opening move, but tomorrow morning I’ll have to figure out what happened.