The implementation of minimax really stumped me. I read the assignment sheet over multiple times and was able to figure out the base case to be when the game is over and returning -1, 0, or 1 according to the result. However, I couldn't figure out how to write the general case. Because of the notion that minimax can calculate both the next_player's and the opponent's scores, I tried to split the method into two parts, each for calculating the score of each side. That approach proved to be erroneous because it did not work well with the base cases that I chose. Eventually I realized that I was over-analyzing the problem by looking at the entire tree of possible game states at once. Like the author whose post is linked here http://1024forbidden.blogspot.ca/2015/03/week8-assignment2-about-recursion-and.html says, drawing pictures is quite helpful in figuring out the recursive part of minimax. I drew a game state with two child game states and recognized that this simple structure can be a child of another game state, and also it can have child game states of its own. Then shortly after I figured out to use list comprehension with minimax on a list of possible moves, then multiply all the scores by -1 to obtain the max to produce the current score for next_player.
Sunday, March 8, 2015
SLOG #6
My focus for this week has mainly been on the completion of assignment 2. The game state class was not particularly difficult because the starter code provides a clear concept of what methods the class should contain, and I only had to come up with some ideas on the abstract data structure to keep track of the state, and some specific attributes that are required to play the game Tippy. Checking the winning condition took a bit more thought because I tried to approach the problem using recursion at first, but coding the method in numerous lines was actually conceptually more straight-forward, since there are only four possible tippy shapes when all translations and rotations are broken down.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment