Game Development Reference
In-Depth Information
Creating the computer's minimax-style AI
The createAIMove function is called when the GameStates.STATE_START_AI game state is set as the
gameState . The job of createAIMove is to simulate a move exactly like the player and score it just
like we would a player move. The difference being that the AI move will subtract the value of the
move from playerLife instead of from computerLife , thus reducing the player's hit points.
When trying to decided how to create the AI for this game, one thought kept coming to us: The
computer making a move is no different than the player making a move; just the way we handle
the outcome is different. Furthermore, if we could simulate the act of the player choosing the
proper die to click that will score the most points, we could in effect, create AI that could play
against a human. This kind of AI in commonly referred to as minimax , which really stands for
“min or max.”
This type of AI is great for games where the AI player has the full information of the board and can
calculate the most optimal move to make (max) and the least optimal move (min) and then make a
decision on how to move based on this information. This type of AI usually involves a decision tree
that includes all the possible moves for an entire game, thus allowing the AI player to calculate the
best move at any given moment and still know what the outcome will be in the end.
However, using this type of AI for our game presents a problem. The AI player only has full
information for the dice displayed on the board currently. It has no information about the dice that
will be generated once a move is made and dice are replenished. This limitation exists because
we made the new dice have random color and values. Therefore, we can only generate a list of
AI moves based on how the board currently looks at any given time. This means our minimax AI
only has one pile (a set of moves that we can sort by value) at any given time. Also, we are going
to augment this AI by scaling it back so that the computer does not always make the best move,
thus allowing us to have difficulty levels for the game. This is why we call it a minimax-style AI:
while it is related to minimax, it is not an exact implementation of a minimax algorithm.
Analyzing the Dice Battle AI
To figure how to create the AI for the computer player in Dice Battle, we first sat down to discuss
the things we needed the computer to know about the game:
When it is the computer's turn to make a move
All the possible moves it could make on its turn
The value of all the moves (i.e., how many hit points each would remove from the player)
Its own ability to choose the best (max) move
Its own ability to not make a terrible (min) move
We then set out to solve each of these problems one at a time.
The first problem, letting the computer know to make a move, was very easy to solve. As we
stated before, we created the turn variable and the GameStates.STATE_CHANGE_TURN game state to
solve this problem. Basically, the computer is told by a call to createAIMove that it is time for it to
make a decision.
The next problem, knowing all the possible moves the computer could make on its turn, was a bit
more difficult. We already have the function findLikeColoredDice that accepts an instance of Die
as its parameter. That function returns an array of Die classes that are touching with the same
Search WWH ::




Custom Search