The Mathematica Journal
Volume 10, Issue 2

Search

In This Issue
Articles
In and Out
Trott's Corner
Beyond Sudoku
New Products
New Publications
Calendar
News Bulletins
New Resources
Classifieds

Download This Issue 

About the Journal
Editorial Policy
Staff and Contributors
Submissions
Subscriptions
Advertising
Back Issues
Contact Information

Exploring Board Game Strategies
Yves Papegay

The HMaki Example

"If you start this game, you see a board full of tiles. Your task is to remove as many tiles as possible from the board. You cannot remove single tiles, instead you have to remove them in groups of adjacent tiles filled with the same color." Holger Klawitter, HMaki 3.9.1 Information (www.klawitter.de/palm/hmaki.html)

Figure 5. The board of SameGame, the Gnome/KDE version of HMaki.

Let us try our design pattern for implementing this board game (Figure 5).

Configuration of the Board

We give some values for the size of the board and the number of colors. We also set the flag for randomness.

Positions of colored tiles are given by a succession of calls to the pseudorandom number generator.

Visualizing the Board

We are now able to initialize the game.

Choosing some colors, we can define the function View for a nicer display of the board.

Transition Function

To deal with corner and boundary situations, we define the BoardValue function to access the values of the board. It returns if the arguments for location are outside the bounds of the board. This allows us to ignore the boundaries of the board when considering the neighbours of a location.

The positions of neighbours are computed by the following two functions.

To get the spot enclosing the selected location, (i.e., the neighbourhood of locations with the same color), we use a fixed-point algorithm applied to a neighbourhood extension function.

IsPlayable is now easy to implement: only a non-empty location within a spot of at least two can be played. The result of the function is the list of the locations within the spot.

PlayBoard will "remove" the spot from the board, propagating individual tiles to the bottom and columns to the left whenever it is possible.

Main Loop

To check whether the game is over, it is necessary to decide if there remain two spots of the same color contiguous by a face.

Interaction with the player here is very basic.

And we are able to play--but the interface is a bit cumbersome.

With a Notebook Interface

To improve the interface, only one function has to be defined: one which colors the buttons and manages the end of the game (Figure 6).

And we are able to play without the keyboard!

Figure 6. A view of the notebook interface of the board of HMaki.



     
About Mathematica | Download Mathematica Player 
© Wolfram Media, Inc. All rights reserved.