So my digression about minimax from my last post got moved here :)
Before I go in, I would like to mention that in class we do worst case analysis. I don't like that. I want to talk about the average needed time. For example, we can easily see that the worst time for pruning is the same as checking everything... but on average for Tippy... it saves so much time... (3x3 tippy first point runs fast enough that you're not waiting for computation). Kind of interesting aspect of average time analysis is to think about when the averages change. In a sense, the average time is just an expected value and it depends on the probability distribution of the input feeds.
First:
Combine pruning and memoizing... these two techniques are obviously somewhat mutually exclusive. I would try to prune first and then if I need the data, see if I can fetch from my memos... An interesting twist / implementation detail might be whether I should store the partial info I get from pruning. Let's say I exit early since I know 0 is a guaranteeable score, should I remember this to take advantage of the next potential pruning step??? I think this is a design decision and probably what's better is game dependent. I'm not sure what's best, but I'm thinking in along the following lines. 1) suppose the tree can be pruned often... that's good right? I'm saving a lot of computation... but this also means that I'm not collecting much memos and it's kind of useless. Suppose I do keep partial info... then I would need two different notes for each state I encounter... 1) The minimum gauranteed or actual score depending on 2) whether the value I have is the actual score. Upon some thought, I'm starting to wonder if there would be significant boost in performance. Here's why: Suppose you pruned... but you actually need this value then you need to go back and evaluate everything anyways, regardless of the minimum gauranteed score. This means even with the memo, you might need to compute that many more times, but of course on your second try... you might get some help when you prune since you know the minimum value you can achieve out of it... but then you need to be careful about what to do when the values are the same... Also, you need to check if it's in your set, which takes time. Here, I used python Set() which uses hashing, but if I used a list... the finding time would be nlogn... Overall, I CAN see it potentially beneficial... but I'm not sure if it would be so much.
Second:
Notice that the last child can be "pruned". The actual value at the last node doesn't matter This is probably beneficial where the number of children is small...
Third:
and most interesting in my opinion is symmetry considering memoize.
In all the two player games, the score is symmetric in that score for p1 in state1 is the same as the score for p2 in -state1... where -state1 is the condition where all the "stuff" are as though p2 and p1 are switched... To illustrate, in subtract squares game, suppose the score for state p1: 500000 is 1.0 then I know that the score for p2: 500000 is 1.0 (score for p2). In tippy, take the stones in the grid and exchange p1 and p2's play... you get the mirror image state. Now, you can cut the number of states to memorize in half.
For the implementation of this, I think that concept of hashing might be interesting thing to introduce to GameState. Make a method that returns an ID of this game... some sort of number which encapsulates all the stuff about the state. And make it such that if it's symmetric, this tag is the same... That would provide a really cool handle for the implementation of memoize. I would call it memoizeSymmetry. Another interesting thing about tippy is that there's also rotational symmetry that can be taken advantage of. The score does not depend on the rotational state of the grid. You can use this to further cut the checks. The best part is that the memoizeSymmetry would work in both cases but in subtract sq game get a 2x boost and in tippy get ~8x boost (the rotations may be identical in some grids). I think this is a really cool class to write.
Do you have any extra ideas about other minimax implementations? Criticisms or runtime/resource analysis?
No comments:
Post a Comment