UNIT V - Chapter 2 - Mind Games


Mind games are the games which challenge a player’s mental ability. They are usually in form of puzzles, quizzes or board games like Chess, Tic-Tac-Toe. The card games also fall into this category. They could be of a large number of types. Some of the examples of mind games are:


§  Chess

§  Tic-Tac-Toe

§  Checkers

§  Othello

§  Scrabble

§  Puzzles

§  Quizzes

§  Solitaire

§  Heart

§  Bridge

§  Jawbreaker


Thus we can see that mind games are of many types. They have been popular since the advent of human race. Mobile phones are just a new medium. The charm of mind games is ageless. Thus we have to concentrate on building these games in a way that they retain there original charm plus the added pleasure of being played on mobile phones. ‘SKJ TicTacToe’ is a case in point here. In ‘SKJ TicTacToe’ we retained the original TicTacToe game and added a very hard to beat artificial intelligent opponent to it. We also added animating naughts and crosses so that the player finds something different in the mobile phone version of the game when compared with the offline pen and paper version.


Companion CD

The whole code and artwork of ‘SKJ TicTacToe’ has been included in the companion CD.



Mind games may have many features. Since there are no fixed types of mind games, the features depend on the inventor of the game. Some times the innovator in all of us guides us to add some extra features in already well established mind games. Even though there is no limit to the features in mobile phones, mind games usually have the following features:


·         Grids

Grids are an important element of mind games. Whether it is Chess, TicTacToe, board games like Scrabble® grids are an essential element. These grids may be scrollable/non-scrollable, animated/non-animated. The size of the grid depends upon the nature of the game. Scrabble® has a large grid while TicTacToe has a small grid. Thus any grid requires a detailed study of it’s characteristics before programming it. We will discuss the art of drawing grids in detail later in this chapter.


·         Checkable Goal

Most mind games have a goal that can be checked by the device and the result be conveyed to the user. It is preferable to write a dedicated method to test this. This gives a clear cut method that can be used at different places to check whether the user has won.


·         Rules for putting symbols

Most mind games have certain symbols. Chess has pieces like pawns, bishops, kings etc. TicTacToe has naughts and crosses. Puzzles have blocks. These are put according to certain rules. As a game developer it is useful to have a clear cut idea on this as once you start coding the game it is usually very difficult to modify the code to introduce new rules. Every time the user presses a key or gives some other input for moving the symbols or placing them, it should be checked whether all the rules of the game are being followed, if not then the user should be prompted to take the correct course.


·         A well defined marking scheme

In many mind games the winning is based on points. The marking scheme should be well understood in advance. Some have a very simple marking scheme while others like Scrabble® and Jawbreaker have moderately complicated marking schemes. Some card games have complicated marking schemes.


·         Role of ‘Artificial Intelligence’ in making the game more entertaining

Many mind games have two players. Since in simple mobile games having the second player as human is possible only in multi-player mode generally we go for Artificial Intelligence to add an artificial player. This artificial player should generally be configurable as well as it should be challenging enough for a human player to feel excited about the game. The artificial player should raise the adrenalin level of the human player. If your game is successful in doing so you have succeeded in developing a good game.


·         Multi-Player Games

Earlier the mind games were mostly single player games or games having a strong artificially intelligent player. These days due to reduction in the mobile internet rates and the advent of bluetooth technology multi-player games are becoming popular. These games enable multiple human players to play a game with each other. Card games are an excellent example of games that could be made into multi-player games.


Technical Details


·         Grids

Grids form an integral part of many mind games. Coding for them is easy once you understand there nuances. First of all we should define the characteristics of a grid. Some of the important characteristics of a grid are:

·                     Number of rows

·                     Number of columns

·                     Contents of each cell

·                     Whether the grid will be scrolling or not

·                     Whether a selection rectangle will be there on the grid which could be controlled by the player


The answer to each of these questions will depend on the game that you are developing. Here we will discuss the steps in creating a grid for the TicTacToe game. The steps are as follows:

·                     First define a two dimensional array containing the state information for all the cells of the grid. In case of the TicTacToe game the following will be the valid values:

§  -1            :           Empty cell

§  0             :           Symbol 1

§  1             :           Symbol 2

·                     Then initialize the grid to its starting state each time a new game starts by setting the contents of the above defined two-dimensional array to 0.

·                     While painting the grid follow the following steps:

§  Clear the screen

§  Draw the lines which will define the grid

§  After that draw the selection rectangle that the user is controlling based on its current position

§  Lastly draw the symbols by placing them appropriately within each cell. Images can be drawn in grids or outside grids through the drawImage method.


For a better understanding of the role of this method please remember to see the code of the ‘SKJ TicTacToe’ game.


Listed below are checklists which will help you in visualizing the grid and cell characteristics.


Checklist of Board characteristics

Cell Characteristics


Board Shape


Background Color


Background Image


Zoom Functionality


Number of Rows


Number of Columns




Checklist of cell characteristics

Cell Characteristics


Cell Shape


Background Color


Background Image


Foreground Text


Foreground Image


Foreground Pieces


·         Checking goals

We should have a method of checking for the result after every chance. This method can be named ‘win’. This method should contain the logic for checking the win for all the players. The logic for this method will depend on the type of game we are developing. For example in case of TicTacToe we check whether the same symbol has been placed thrice linearly. For a better understanding of the role of this method please remember to see the code of the ‘SKJ TicTacToe’ game.


·         Rules for putting symbols

Every mind game has certain rules for putting symbols. For example in most games you cannot place a symbol at the position where a symbol is already placed. Similarly in chess you have rules for moving pieces. The individual rules vary widely from game to game. Here we will discuss the same for TicTacToe. In TicTacToe the rule for putting the symbol is simply that once a symbol is placed on the board no other symbol can be placed on top of it. In the TicTacToe game we allow the user to put his symbol on the board only when the particular board position in question is empty.


Example Code (SKJ TicTacToe)

If (this.sq[this.colSelected][this.rowSelected] == -1)


this.sq[this.colSelected][this.rowSelected] = this.userSymbol ;

               if(this.win() == false)


                    this.AIRun() ;

                    this.win() ;




·         Marking schemes

Marking schemes are important in certain games. For example in Scrabble the marks a player gets depends on the position of the board that is covered by him in his chance. To compute this we can write an internal method named ‘scoring’. The inner details of this method will depend upon the type of game we are building.

For example in case of Scrabble this method can have 4 parameters referring to the player, row of block placement, column of block placement and index of the used block. The marks for the particular player can be calculated and added to his score based on the marks for the block multiplied by the multiplication factor of that particular cell on which that block has been placed.

Example Code

private void scoring (boolean player, int row, int column, int index)


            if (player == true)


                        p1Score += (index * mf[row][column]) ;




       p2Score += (index * mf[row][column]) ;




Here we will have to define the int [][] array mf before the start of the game.


·         Artificial Intelligence

While writing the AI for mobile games please keep in mind that the processors of mobile handsets are not as powerful as there PC counterparts. Thus the depth of the computation tree can not be very much. Also certain techniques like neural networks, genetic algorithms and distributed reasoning are computationally very expensive to be used in the game AI. Also they are not required for most of the mind games. Thus what is of interest to us are the techniques of symbolic reasoning.

The aim of this book is to guide on the issues that arise while using AI on mobile phones. Therefore we will stick to the techniques which can be useful in mobile context. A production system approach has many advantages like simplicity, low memory requirement and fast processing. Use of good heuristics can be a very good way of minimizing your AI effort.

Choosing the right search algorithm is very important. It can make or break the game AI. Also minimax search procedure with alpha – beta cutoffs can be very helpful in increasing the efficiency of search procedure while retaining the quality of the search procedure at the same time. ‘Iterative deepening’ technique can also be used. Even the use of ‘book moves’ (list of standard moves for a particular game configuration) can help a great deal. In fact we relied on book moves very heavily while developing our TicTacToe game.


·         Multi-Player Games

Technical issues concerning multi-player games have been discussed later on within the chapter 4 of this unit.