Apprenticeship -- Day 4

November 29th, 2018

Today I completed some Ruby tutorials and attended a minimax workshop. I also started watching a really cool TDD lesson by Thoughtbot.

Alongside the Ruby tutorials, I attempted to refactor my render method in board class. I realized that one of my roadblocks during this attempt was the "initialize" method. I still didn't understand the concept of initialization within a class. What exactly is initialized? Do I always need this method? Is this a reserved method from Ruby? How does initialization impact other methods? There seemed to be other tricks as well, like parameter configuration. I was just about to skip the minimax workshop, but my mentor saw my board and suggested that I definitely go to the workshop.

I went to the workshop, but I still need help understanding the concept. I would like to be a minimax master. For my very first attempt at making a tic tac toe unbeatable, I tried to implement minimax. I wasn't very successful. It was the first time my computer started acting funny. Anyway, minimax is an algorithm that can be used in a game with two players, where all information is publicly available (i.e. tic tac toe, checkers, chess, but not a game like poker), to make optimal moves. Minimax is one approach you can take if you want to make a game in which will always result in a tie or result in the computer winning. The computer is supposed to know the best move to make after each move from either the computer or human player (or computer and computer).

How does the computer know which move is optimal before the game begins and during the game? Or why does the algorithm work? This is where things get tricky for me and people try to bring out tree drawings and my brain turns to mush. From what I understand, the algorithm is supposed to consider end-game states -- possible game states before the game ends. Usually when I see minimax trees, they are explained by focusing on the point at which the game is three or four moves away from being won. I think the algorithm would only optimize for the best end-game states since there are thousands (hundreds of thousands?) of different possible games, but not all of these games result in the computer winning. So there are thousands of plays within a single tic tac toe game, and the goal is to make the best move by selecting a move that will incur the least amount of damage from the opponent.

During the workshop, we had an overview of minimax and its use in tic tac toe, but this particular workshop was mainly geared towards the algorithm itself and how to write tests for it. Minimax is a search algorithm at its core -- a way to search for things. So we weren't really looking at tic tac toe or players. We focused on the organization of scores. The scores were organized on a tree structure, where nodes represented scores. Still, we focused on a node and its path to the root node. Some of my tests checked to see that nodes were initialized, that nodes had children after calling a method to add children, or that nodes had certain scores. Overall, I need to review the workshop and just the general concepts of minimax, but testing the algorithm seems completely feasible now.

Phew! I've been learning so much these past few days. Tomorrow, my main focus will be TDD exercises in Ruby.