Game Development Reference
In-Depth Information
16 - AI Simulation
run a hundred games to see which is better. Try changing the function calls and running
the program again.
Welcome to Reversi!
Enter number of games to run: 100
Game #0: X scored 52 points. O scored 12 points.
Game #1: X scored 10 points. O scored 54 points.
...skipped for brevity...
Game #98: X scored 41 points. O scored 23 points.
Game #99: X scored 46 points. O scored 13 points.
X wins 65 games (65.0%), O wins 31 games (31.0%),
ties for 4 games (4.0%) of 100.0 games total.
Wow! That's unexpected. It seems that choosing the side spaces over a space that flips
more tiles is a bad strategy to use. The benefit of the side space is not greater than the cost
of choosing a space that flips fewer of the opponent's tiles. Can we be sure of these results?
Let's run the program again, but this time let's have the program play one thousand games.
This may take a few minutes for your computer to run (but it would take days for you to do
this by hand!) Try changing the function calls and running the program again.
Welcome to Reversi!
Enter number of games to run: 1000
Game #0: X scored 20 points. O scored 44 points.
Game #1: X scored 54 points. O scored 9 points.
...skipped for brevity...
Game #998: X scored 38 points. O scored 23 points.
Game #999: X scored 38 points. O scored 26 points.
X wins 611 games (61.1%), O wins 363 games
(36.3%), ties for 26 games (2.6%) of 1000.0 games
total.
The more accurate statistics from the thousand-games run are about the same as the
statistics from the hundred-games run. It seems that choosing the move that flips the most
tiles is a better idea than choosing a side move.
Comparing the Regular Algorithm Against the Worst Algorithm
Now set the X player's algorithm on line 346 to use getComputerMove() and the O
player's algorithm on line 351 to getWorstMove() , and run a hundred games. Try
changing the function calls and running the program again.
Search WWH ::




Custom Search