So this week, I found out that I had done my minimax function completely wrong the day before it was due. My understanding of minimax was wrong the entire time.
I thought Minimax was a type of strategy where the computer would calculate every possible game state that can result from a move and then return the chance of winning for that move.
So for example, let's say that the computer can make 3 possible moves. Minimax would go through each of these moves and find every possible final game state. It would then find the "average" of all these final states and rate each of these three moves based on the percentage of win states to total states.
So minimax might end up generating something like this:
Move 1: (40% win chance)
Move 2: (70% win chance)
Move 3: (80% win chance)
Based upon my minimax, the computer would choose move 3.
The fundamental error here is that I assume that my computer is going up against an imperfect opponent. A real minimax is supposed to assume that the computer is facing a flawless opponent.
Knowing that I had such a huge problem in my program, I had to pull an all nighter to finish minimax.
By a miracle, it turns out that all the information I ever needed on minimax was on wikipedia. There was nothing to stress over the entire time.
http://en.wikipedia.org/wiki/Minimax
There was more than enough information for Minimax, Not only that, there was even pseudocode for minimax. With this much useful info, I finished minimax in 2 hours.
In addition to finishing minimax I also reviewed a few of the past labs for recursion. I found some of the recursion problems, (especially for binary lists) to be very hard. Not so difficult that I couldn't solve them with enough time but difficult enough that they can stump me for a while. I am going to have to practice these problems alot if I want to succeed on the test.
Monday, 30 March 2015
Slog #6
I spent most of the week working on assignment 2 and I was met with quite a few significant problems. The first problem I had was with the minimax function.
For some apparent reason, whenever I attempted to run minimax with Tippy, the minimax class would always crash midway. I did what I normally do in the event of an error, I filled my minimax class with print functions so that I can track different values in the minimax class.
So I went and tracked what happens in minimax when I run Tippy with a 3x3 board. What I found was incredibly confusing. For some reason, every time I ran the AI, minimax would load through only 9 different game states and then crash.
And for some reason, the last game state would always look like this:
[X,O,X]
[O,X,O]
[X,O,X]
I spent the next hour trying to find the problem and I still had no clue what was going on so I decided to sleep on it.
After some thinking I finally realized what was going on. In every one of my Tippy game states, I had a two-dimensional grid ([][]) that corresponds to my grid. Every time I made a move I would add an X or an O on an empty spot in the grid and then I would return the new corresponding game state. The problem here was that 2D arrays were mutable and as a result, my initial game state (which is supposed to remain an empty board) was consistently being changed every time minimax was called.
This perfectly explained why my minimax would crash after printing 9 states. This is because after going through 9 states, my initial state was already full and minimax could not find any more moves to make.
This problem was very interesting for me because I made use of knowledge about mutability I had learned in CSC108. Solving this problem also made me feel like I had done something substantial.
So I went and tracked what happens in minimax when I run Tippy with a 3x3 board. What I found was incredibly confusing. For some reason, every time I ran the AI, minimax would load through only 9 different game states and then crash.
And for some reason, the last game state would always look like this:
[X,O,X]
[O,X,O]
[X,O,X]
I spent the next hour trying to find the problem and I still had no clue what was going on so I decided to sleep on it.
After some thinking I finally realized what was going on. In every one of my Tippy game states, I had a two-dimensional grid ([][]) that corresponds to my grid. Every time I made a move I would add an X or an O on an empty spot in the grid and then I would return the new corresponding game state. The problem here was that 2D arrays were mutable and as a result, my initial game state (which is supposed to remain an empty board) was consistently being changed every time minimax was called.
This perfectly explained why my minimax would crash after printing 9 states. This is because after going through 9 states, my initial state was already full and minimax could not find any more moves to make.
This problem was very interesting for me because I made use of knowledge about mutability I had learned in CSC108. Solving this problem also made me feel like I had done something substantial.
Sunday, 1 March 2015
Slog #5
Please grade my summary of objected oriented programming this week.
I'll update this post once I'm done documenting Assignment 2.
I'll update this post once I'm done documenting Assignment 2.
Subscribe to:
Posts (Atom)