Game Development Reference
In-Depth Information
Game #98: X scored 33 points. O scored 31 points.
Game #99: X scored 45 points. O scored 19 points.
X wins 84 games (84.0%), O wins 15 games (15.0%),
ties for 1 games (1.0%) of 100.0 games total.
Wow! X win far more often than O did. That means that the algorithm in
getComputerMove() (take any available corners, otherwise take the space that flips the
most tiles) wins more games than the algorithm in getRandomMove() (which just makes
moves randomly). This makes sense, because making intelligent choices is usually going to
be better than just choosing things at random.
Comparing the Random Algorithm Against Itself
What if we changed O's algorithm to also use the algorithm in getRandomMove() ?
Let's find out by changing O's function call on line 351 from getComputerMove() to
getRandomMove() and running the program again.
Welcome to Reversi!
Enter number of games to run: 100
Game #0: X scored 37 points. O scored 24 points.
Game #1: X scored 19 points. O scored 45 points.
...skipped for brevity...
Game #98: X scored 27 points. O scored 37 points.
Game #99: X scored 38 points. O scored 22 points.
X wins 42 games (42.0%), O wins 54 games (54.0%),
ties for 4 games (4.0%) of 100.0 games total.
As you can see, when both players are making random moves, they each win about 50%
of the time. (In the above case, O just happen to get lucky and won a little bit more than
half of the time.)
Just like moving on the corner spaces is a good idea because they cannot be flipped,
moving on the side pieces may also be a good idea. On the side, the tile has the edge of the
board and is not as out in the open as the other pieces. The corners are still preferable to the
side spaces, but moving on the sides (even when there is a move that can flip more pieces)
may be a good strategy.
Comparing the Regular Algorithm Against the CornersSideBest
Algorithm
Change X's algorithm on line 346 to use getComputerMove() (our original
algorithm) and O's algorithm on line 351 to use getCornerSideBestMove() , and let's
 
Search WWH ::




Custom Search