There were so many challenges with the assignment, first I had to read and understand completely the given game view and game state structure, and on top of that I had to follow the formula and make a harder game state with a more intelligent move chooser. The hardest part for me was writing the winner function for Tippy (a function that checks if either player had won the game) and suggest_move function for MiniMax strategy. The winner function for Tippy was hard in the sense that I had to write so many lines to check all the possibilities for each position on the game board and restrict places that were been checked on the board. The suggest_move function for MiniMax strategy was without a doubt the hardest part in this assignment for me, and as the title of this week's blog suggest it is related to recursion, and in fact I had to write two very hard helper function using recursion to make suggest_move work, and as you can imagine all the different bugs I had when writing suggest_move, where I spend most of the time tracing values in the recursion functions.
So... what is recursion? Basically to put into the simplest words recursion is preformed when a function calls it self in the program. Recursion can be useful when writing harder functions (like ones I mentioned in assignment 2). For example, there is a list that contains many list and integer, and those list inside also could potentially contain more lists and integer (nested list with integer), and we want to write a function that adds all the integer in the list up. By writing a function with a for loop looping each variables (whether a list or integer) and calls the itself (the function) with the variables we can simply accomplish this task, no matter how many list is nested inside the first list.
![]() |
| (sample function by me) |
![]() |
| (example of BTnode from week 7 lecture slide) |
Thus to conclude my adventure for this week, I found understanding recursion and knows how to write it is very important for writing Python functions (or maybe as well for other programming language). Although it was very tiring this week trying to fix all the bugs in assignment 2 tracing recursions, but I found it very exciting to program those functions, and very rewarding when I found that my programmed AI can beat me most of the times. Especially when AI goes first on Tic Tac Toe (very similar to Tippy I made on spare time), the win rate for AI is really high!




