Friday, March 27, 2015

CSC 148 March 27th 2015

Normally I would be discussing this week's material, but I realised that I forgot to write a blog last week so this one will be based on the materials covered in week 10.

In week 10's lecture, Professor Heap showed us his sample solution of minimax, as well as introduced assignment 3.  The sample solution pairs every possible move of a gamestate with a score of 1, -1, or 0, depending on whether or not the move can guarantee a win.  Then, the sample solution will pick a move that has the highest score, and return it.  The sample solution is much shorter and more efficient than my code, because my solution uses two functions instead of one.  One of my function essentially takes a gamestate, and returns a score.  The second function uses the first one to determine the score of the opponent's gamestate, and picks the move that leads to the gamestate with the lowest score.  The main reason I split it into two functions was because when I tried to use max() on a list of tuples, where each tuple had an int representing the score, and a move, I kept getting errors because I didn't implement any methods that compared moves to each other.  The Professor showed us that we can use the max() function on only the first index of each iterable, and I will use this to rework my minimax strategy.  Other than that, we talked about how to create test cases to test our code.  These test cases should include as many possible scenarios as possible.  For minimax, there could be cases where there are no winning moves, gamestates where all moves are guaranteed wins, and gamestates that has a mixture of both.  We also discussed the difference between global and local variables in a tracing exercise, which is similar to questions that were tested on in 108 last semester.  Overall, the content this week was pretty mild, and I look forward to the materials next week.

No comments:

Post a Comment