Game Development Reference
In-Depth Information
Topics Covered In This Chapter:
— Simulations
— Percentages
— Pie Charts
— Integer Division
— The round() Function
"Computer vs. Computer" Games
The Reversi AI algorithm was very simple, but it beats me almost every time I play it.
This is because the computer can process instructions very fast, so checking each possible
position on the board and selecting the highest scoring move is easy for the computer. If I
took the time to look at every space on the board and write down the score of each possible
move, it would take a long time for me to find the best move.
Did you notice that our Reversi program in Chapter 14 had two functions,
getPlayerMove() and getComputerMove() , which both returned the move
selected as a two-item list like [x, y] ? The both also had the same parameters, the game
board data structure and which tile they were. getPlayerMove() decided which [x,
y] move to return by letting the player type in the coordinates. getComputerMove()
decided which [x, y] move to return by running the Reversi AI algorithm.
What happens when we replace the call to getPlayerMove() with a call to
getComputerMove() ? Then the player never types in a move, it is decided for them!
The computer is playing against itself!
Search WWH ::




Custom Search