Volume 10, Issue 2 Articles In and Out Trott's Corner Beyond Sudoku New Products New Publications Calendar News Bulletins New Resources Classifieds Download This Issue Editorial Policy Staff and Contributors Submissions Subscriptions Advertising Back Issues Contact Information 
Exploring Board Game Strategies
Playing Lines"Your task is to build lines of balls of the same color on the checkerboard. Every time you move a ball, 3 new balls appear. When you build a line of 5 or more balls, these balls are removed from the board. Easy? And exciting!!!" 5star Free LinesHow to play (www.atomax.com/lines.stm) Figure 7. The board of the fivestar version of the game Lines. Once again, the design pattern will help us quickly implement this game (Figure 7). Configuration of the BoardThe following values define the physical parameters of the board.
Initially, the board is empty.
But before the first play, the computer makes three balls appear.
The colors of the next three balls to be added are selected in advance and must be shown to the player to help him play. They are selected randomly by the Next function and kept in a global variable, NextBall.
Adding BallsThe positions at which to add the balls are also selected randomly in the list of the empty positions.
RandomElement is a miscellaneous function randomly selecting an element of a list.
Visualizing the BoardLet us initialize the game and visualize it.
With some colors and a few graphics primitives, we are able to display the board and the next three balls.
Transition FunctionIn this game, a play consists of three possible successive actions: selecting and adding three balls, moving a ball, and deleting a line of balls. When a player selects a ball and a new location for it, this ball is moved. If possible a line is deleted and the computer adds three balls, possibly deleting a line. Moving BallsTo decide whether a motion is valid or not, we again use a fixedpoint algorithm applied to a neighbourhood extension function: the set of reachable positions is incrementally built from the starting position by exploring empty locations. We reuse the function BoardValue to simplify the computations of the neighbourhood.
Neighbour is slightly different than FaceNeighbour from the previous example.
Possible searches for empty locations in the neighbourhood.
The fixedpoint algorithm is performed by IsPlayable, which returns a Boolean.
PlayBoard updates the board, checks for lines of five balls to delete, and adds three balls.
Checking for Lines to DeleteTo check if there is a line of five balls to delete, we try to extend the position in four (nonoriented) directions as long as the color of the ball remains the same. This is performed by Extend.
DeleteBall suppresses the balls from the line.
And NewLine is the toplevel function, returning a Boolean.
Main LoopPlayingThe game continues until fewer than three slots are available for the balls.
Once again, the interface with the player is extremely basic.
But we can play!
A Notebook InterfaceTo cope with the display of the "balls to come", it is necessary to adapt the NBView function and develop the dedicated function NBNext, which is similar to NBBoard.
To select two locations, the player clicks twice in a play on the board. This is taken into account through the variable FromLoc and by a small difference in the implementation of NBPlayThere.
With the notebook interface, playing becomes easier, even if the graphical design is not so nice.


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