Thursday, 2 April 2015

Revisitation Of Minimax (The Official "Revisitation" Post)

Two weeks ago I documented my apparent triumph over Minimax, only to find out that it's finality did not survive the scrutiny of doc tests and compatibility with A3 optimizations. At this point, I would like to offer some concluding remarks on a (still) incomplete Minimax/A3 and about the learning experience Minimax has entailed for me. In the future, when I think CSC148 I will think Minimax, likely as some personified entity the likes of which will reveal itself as this semester is consolidated in memory and more perspective develops. However, in the mean time, I still think I have a few words to say.

Technically, I am still unsure of my code. I have managed to pass all official Unit Tests except for one, which appears to have been elusive to other students (see http://adamosslog.blogspot.ca/) for reasons not directly related to Minimax's effectiveness. Specifically, this involves a winning start after the Unit Tests generates a Tippy grid. Debugging this last test will have to be a patient, clever trial-and-error process that really has to factor in all of the possibilities. The problem arising from the TippyGameState code is a best case scenario, with a worst-case being some deep-seated flaw in Minimax that will require a complete revamp. My guess is either the latter or a minor tweak in Minimax; it seems unlikely to pass all Subtract Square tests and be completely off.

Of course this begs the question: Why am I still pursuing A3 with an incomplete Minimax? There are several contributing factors here, but the primary one is simply that I wanted to. I got interested in AI search algorithms, have a persistent disposition, and really did not think that the finish line was too far off. I didn't seek enough help for A2 so I factored in that, with more help, I would be able to crack Minimax quickly and get on to the optimizations. Minimax itself proved to be a challenge even for helpful TA's, with the strike obviously factoring in to the level of preparation they had for A3 as well as the available aid for my initial stab at Minimax in A2. By the time I realized what I had gotten myself into, I was too close to the deadline to restart (creating a whirlwind of stress, for 6% of my mark, in a sensitive time before finals).

In the end, the real mistake I made was  assuming that my Minimax worked before Unit Testing, thus allocating my resources to optimizations of a flawed foundation. However, I still believe that I stand on optimistic grounds. Currently, my Minimax is one Unit Test away from full pass, the code of my optimizations makes perfect logical sense (evaluated by TA third-parties), was designed for a Minimax that isn't too far off of my latest version, and I have learnt an immense amount in a process for which transient regret ("I should have taken Option B!") is regularly replaced by a more productive process-orientation that leaves me confident that I'll bounce back from whatever negative consequences I may have accrued.

To address some algorithmic and implementation details: Two posts ago I mentioned what I perceived to be a genuine stroke of insight about the way Minimax had to function. With my recursive "score checking" in a get_score function, I believed that its base cases had to examine two moves ahead so that each full evaluation only looked at special opponent cases where the opponent played themselves into a loss, then made a recursive call on the next GameState where the computer was the current player. This was based a real misunderstanding of Minimax, which I rectified via discussions with Professor Heap and some "rigorous" hours paroozing YouTube. Minimax is supposed to make its simulated opponent as savvy as possible. In traditional versions of Minimax floating around the web ether, there is a "Minimizer" and a "Maximizer" (hence the name "Minimax") that take turns. The Maximizer's possible moves are whatever the Minimizer serves up from its possible moves, and vice-versa. This sets us up straightforwardly for pruning: The Maximizer sets a lower boundary for what values its will accept from calls to Minimizers, thus allowing us to recognize when to stop computing values the Maximizer will ignore anyways. The Minimizer also sets boundaries in an analogous manner.

The Minimax of CSC148 is most usefully thought of in terms of +1/-1, instead of a Maximizer and Minimizer, but a similar logic applies. As such I set out to create a get_max_score and get_worst_score functions to represent the competitors, then collapse them both into a _get_score helper that took a parameter for either +1 or -1. _get_worst_score lacked that parameter, simply returning _get_score(state, -1).

Upon failing multiple Unit Tests, I began to clean the code up. Humair Kahn and his assignment partner were incredibly helpful here, pointing out a HUGE mistake I was making (born of an overly-ambitious attempt at A2). I was incorporating bits of pruning into my original Minimax without realizing it!! get_score stopped computation upon seeing its first +1, and suggest_move returned the first move leading to a GameState with a +1 score. This created a huge headache for me in A2, and is illustrative of a general problem I have with academic assignments: Over-complication. Computer science, at the moment, is challenging for me in the way that Philosophy was when I initially decided to major in it (one degree ago). Simple, structured thought is more difficult for me than scattered creativity. Interesting research in Neuroscience and Psychology actually points to trade-offs between single-pointed attention and creativity (often associated with open attention and wandering thoughts), with the challenge for me being the former. Comp sci is a great exercise in that, and actually helps me productively channel creative thinking.

After dumbing down my basic Minimax to a version that straightforwardly fit the recommended algorithm in A2, I am now the mere Unit Test away from throwing my arms up and climbing atop a tall structure in my underwear. If that ends up happening or not, I have no regrets about the choice to attempt closure with Minimax. It has been bumpy, frustrating, but never boring.

No comments:

Post a Comment