Volume 10, Issue 2
In and Out
Download This Issue
Staff and Contributors
Exploring Board Game Strategies
Analysis and Strategies
In this section, we will show how easy it is to make the computer play on its own in order to analyze games or analyze, study, and improve playing strategies. We will focus again on the HMaki game, which is complex enough to demonstrate how powerful the analysis can be with our design.
As randomness is involved in the initialization of the game, we need to play repeatedly to study the game with statistical tools. So the computer should be able to play a game alone and give us feedback on it.
We are interested in the final score and the number of plays necessary to reach the end. Moreover, we consider two kind of scores: the number of remaining tiles and the sum of the scores obtained for removing each group of tiles--growing with the square of the size of the group. The global value Score contains a list of this information; it is initialized by InitScore and updated by UpdateScore.
Where to Play
Before playing, the computer should know where it is valid to play and then where to play. The function PlayableList computes the list of all the playable locations on the board, using an almost trivial algorithm.
The GetPlay function is rewritten to randomly select an element in the list of playable locations.
We define BatchPlayGame, an analog function to PlayGame, to make the computer play. Note the presence of the bound MaxPlay to avoid infinite loops and the call to SeedRandom to control random initialization of the board and select a play among the list of possible beginnings.
In the preceding results, the high computation time is due to the poor implementation of PlayableList: 76 is the number of plays in the game; 270 is the score when "playing for big"; and 60 is the number of remaining tiles.
Once the computer is able to play alone and produce information on the game, we can make it play enough games to give us statistical results. Let us conduct an experiment.
Playing 100 Games
The first experiment consists of playing 100 different games; the second in playing the same game 100 times.
Statistical standard functions describe the dispersion of this data.
We can view the data using standard graphical functions for plotting.
The fairly even dispersion we observe in these graphics is a testimony to the interest of the game for a human player.
Another goal of statistical analysis is to compare strategies and get a better understanding of how to play.
Simple strategies for playing HMaki are based on knowledge of the different groups of tiles of the same colors. The SpotList function returns the list of the groups computed from the board.
A new version of BatchPlayGame takes an integer argument as an index of the selected strategy, and an option for visualization.
Different instances of GetPlay correspond to different strategies of selecting the group of tiles to remove:
0--the group is randomly selected in the list of groups
1--the group is randomly selected among the biggest groups
2--the first biggest group (starting from the upper-left corner, then from left to right and top to bottom)
3--the group is randomly selected among the smallest groups
4--the first smallest group (starting from the upper-left corner, then from left to right and top to bottom)
Results of 170 games were collected--10 different games played 17 times: five times for the strategies involving randomness, only once for the two others. These results took several minutes to produce.
The following command produces the results in Table 1.
Table 1. Mean of the results over 10 games.
We can also visualize these results with an ad hoc plot function. The following plots show the numbers of remaining tiles for the first strategy.
About Mathematica | Download Mathematica Player
© Wolfram Media, Inc. All rights reserved.