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.
No comments:
Post a Comment