Game Development Reference
In-Depth Information
Welcome to Reversi!
Enter number of games to run: 100
Game #0: X scored 50 points. O scored 14 points.
Game #1: X scored 38 points. O scored 8 points.
...skipped for brevity...
Game #98: X scored 36 points. O scored 16 points.
Game #99: X scored 19 points. O scored 0 points.
X wins 98 games (98.0%), O wins 2 games (2.0%),
ties for 0 games (0.0%) of 100.0 games total.
Whoa! The algorithm in getWorstMove() , which always choose the move that flips
the fewest tiles, will almost always lose to our regular algorithm. This isn't really surprising
at all.
Comparing the Regular Algorithm Against the WorstCorner
Algorithm
How about when we replace getWorstMove() on line 351 with
getCornerWorstMove() , which is the same algorithm except it takes any available
corner pieces. Try changing the function calls and running the program again.
Welcome to Reversi!
Enter number of games to run: 100
Game #0: X scored 36 points. O scored 7 points.
Game #1: X scored 44 points. O scored 19 points.
...skipped for brevity...
Game #98: X scored 47 points. O scored 17 points.
Game #99: X scored 36 points. O scored 18 points.
X wins 94 games (94.0%), O wins 6 games (6.0%),
ties for 0 games (0.0%) of 100.0 games total.
The getCornerWorstMove() still loses most of the games, but it seems to win a
few more games than getWorstMove() (6% compared to 2%). Does taking the corner
spaces when they are available really make a difference?
Comparing the Worst Algorithm Against the WorstCorner Algorithm
We can check by setting X's algorithm to getWorstMove() and O's algorithm to
getCornerWorstMove() , and then running the program. Try changing the function
Search WWH ::




Custom Search