Tic Tac Toe: Understanding The Minimax Algorithm (2013)
neverstopbuilding.com
neverstopbuilding.com
It's far, far more sophisticated than this and still only about 2k lines of C. The source is available on the site linked above.
One common optimization is alpha-beta pruning. It is applicable of you have already found a good move (when we use a heuristic we don't know for sure if it will win or not, only if it is good or not), and consider another candidate move. If the latter move has a strong counter, that means it will for sure be worse than the good move. We can then immediately discard the weak move from consideration, there is no need to find out just how weak it is. To make best use of this, one should check promising moves first, because then the bar for potential moves will be higher and more pruning can be done.
Ultimately with algorithms like minimax or negamax if your scoring / winning algorithm is slow this will compound on top of that. I didn't dig in deep to OPs code nor do I "know" ruby but a quick glance at the scoring / checking code and I saw a yield in use so that's good :D
(spock_play is what the OP called fatalistic, max_play is more like a human.)
[0]: https://www.edx.org/course/artificial-intelligence-uc-berkel...
hmm no, "masters" will concede the game when they realize they lost, if conceding isn't an option I believe making a play that will end the game faster is the next best.
One reason for prolonging the game is that it gives your opponent more chances to make mistakes, turning some losses into either ties or victories. This is true for both human or AI opponents.
Another reason to prolong the game against human competitors is if you're playing another game after this one, and you think your opponent will tire before you will. By causing the game to go longer, you gain a mental advantage in the next game.
Now, these may be considered "unfair" or "unsportsmanlike", but explaining that is left as an exercise for the reader.
https://github.com/geon/Othello-in-Haskell/blob/master/othel...
Just add the ts parameter to the query string...