Creating an Intelligent Computer Opponent
As we discussed when we were designing the game tree code for Dice of Doom, having a separate game tree generator makes it easy to add an AI player to a game engine. In fact, we’re now going to add a computer player that can play an absolutely perfect game with only 23 additional lines of code!
So how does an AI player decide to make a move? We’ll use the following strategy:
Look at each available move.
Give a point rating to the board position resulting from each move.
Pick the move with the maximum point rating.
This sounds like a simple plan, but there is one step in this algorithm that’s pretty tricky: calculating the best point rating for a given board position.
If a move leads immediately to a win, it’s ...