Download as pdf or txt
Download as pdf or txt
You are on page 1of 5

International Journal of Computer Applications® (IJCA) (0975 – 8887)

National Conference cum Workshop on Bioinformatics and Computational Biology, NCWBCB- 2014

An Improved Chess Machine based on Artificial Neural


Networks
Diwas Sharma Udit Kr. Chakraborty
CSE Department CSE Department
Sikkim Manipal Institute of Sikkim Manipal Institute of
Technology Technology
Sikkim, India Sikkim, India

ABSTRACT capable of deriving any useful information in an extremely


Numerous published studies revealed that various researchers sparse environment using a purist approach of introducing
have attempted to build a program that learns to play knowledge. In order to achieve this objective the board game
cognitive games, given little or no earlier knowledge about the chess was selected as the problem domain.
rule of the game. A usual chess playing machine thoroughly 2. SURVEY
explores the moving possibilities from a chessboard The classical approaches to chess playing by machines have
configuration to choose what the next best move to make. The evolved over the years. Nicolas Lassabe et al [7] mentioned
brute- force searching technique used by the Deep Blue chess on their work that, the earliest approach was to evaluate and to
engine has made vast impact in the ground of artificial store, for each chessboard configuration the best move to
intelligence, but still found to be resource hungry. This paper, play. This simplistic and idealistic approach required huge
with the concept of Artificial Neural Networks presents a very comparisons and evaluations. Von Neumann and Morgenstern
simple and efficient approach to develop an intelligent chess (1944) proposed minimax as a method to decide which move
engine which can assist and hint the possible move within the to make in chess.[8] A two player game such as chess can be
game using the evolutionary and a adaptive computing represented by a tree. Each node is a position on the board,
technique on learning from the human grandmasters. starting at the root with the beginning position of the game.
The vertices then are the possible moves, leading to the next
Keywords nodes (positions). The minimax algorithm is the basic search
Artificial Neural Network, Championship game, En passant, tool used in most game programs. Minimax works by building
legal move, Octavius. a depth-first, left-to-right, and search tree with alternating
moves by Max and Min. Only one Artificial Neural Network
1. INTRODUCTION based approach for developing a chess engine is reported in
Chess, known as the game of “perfect information”, since
literature by the name of Octavius. Octavius attempts to gain
both players are conscious about the entire situation of the
an understanding of chess through a positional analysis of
game at all time, just by looking at the board, has since been
master and grandmaster games. Its training is based on the
considered as standard of testing intelligence. Artificially
assumption that any position reached during such games must
intelligent programs have been developed by such computing
be positionally superior to any alternatively available position
majors as IBM, specifically for the purpose of playing chess,
during that game. [5]
and after Deep Blue, (Mid 1990’s) [1], defeated the world
chess champion Garry Kasparov, machines have been 3. PROBLEM DEFINITION
consistently beating man in the rapid version of the game. The To generate a function f, which take as input a chess board
kind of victory of a machine over a human grand master has position denoted by [13],
led to make chess one of the most used games to promote
artificial intelligence and Computer Science. Nevertheless,
chess engines are not able to strategically plan moves or to Such that,
explain why they compute such a combination of moves.
This limitation in the power of the machine exists due to the (1)
fact that the decision tree based hardware and software takes
too much time to search the exhaustive option set for the Here, X and Y denotes white and black pieces respectively, i
correct move. = 1,2,…,16 represents total number pieces for each
side,k=1,2,…,8 denotes files and j=1,2,…,8 denotes ranks,Xi
It is found that Neural Networks are rarely used to solve board Bkj/YiBkj represents the current position of X (white) and Y
games. Major focus is given only to the end-game stages of (black) pieces accordingly.
the game but few uses of Neural Network in computer chess
game as a whole. The playing strength of the top human chess 4. METHODOLOGY
players is due to their strategic planning ability, look ahead, The Figure 1 illustrates the sequence of flow during training
intuition and creativity. The playing strength of the phase where input moves taken from the grandmaster game is
computers, however, is mainly based on their speed. It would encoded using the board encoding scheme discussed later.
be more interesting to find out if machine can inherit the way The encoded moves are then fed into the designed neural
human player plans the game. There has been little work network where the system is trained to produce the output.
published looking at Artificial Neural Network learning where The system learns the patterns (moves and strategy) that are
external(human) knowledge applied to deterministic problems generated by the human grandmaster during their
with large state spaces. This work is interested in investigating championship games. The system is trained until it produces
this area by testing whether Artificial Neural Network is the result with minimum error. The Figure 02 shows the flow

8
International Journal of Computer Applications® (IJCA) (0975 – 8887)
National Conference cum Workshop on Bioinformatics and Computational Biology, NCWBCB- 2014

of designed system during testing phase. Here the trained piece as well as the next position to be moved together within
system is tested with the moves that are not trained earlier i.e. the board. As shown in the Figure 4, the move e4 is
user fed unknown moves in unknown environment, where the represented as 5254 indicating that a piece is to be moved
system behaves as a move generator. The moves so generated from position 52 to next position 54.The work tries to train the
are validated to check whether they are the valid moves or system by means of the patterns generated by the master and
not. It also checks the suggested move to meet the rules of the grandmaster during the championship games. [13]
game.[13]

Fig 4: Move e4 in Algebraic and Numerical notation 5254

Fig 1: Training Phase Fig 2: Testing Phase

5. IMPLEMENTATION
Algebraic notation is a method for recording and describing
the moves in a game of chess. Each square of
the chessboard is identified by a unique coordinate pair, a
letter and a number. Each square has a unique identification of
file letter followed by rank number. [14] Considering the fact
that the Artificial Neural Network only understand the
numeric input values those algebraic notations are to be pre-
processed. Firstly, the ANN understandable board is to be
obtained where each square in the chessboard is represented
Fig 5: Proposed Neural Network Structure[13]
with the unique ANN understandable numerals, the idea here
is the use of numerical notational technique of the board as The use of adaptive Neural Network techniques allows us to
shown in the figure 3, train the system to construct a winning position, as well as to
develop its pieces which result with the best possible move.
The trained system is then deployed in the testing
environment where the result will be examined based on its
performance. The network structure is of high importance in
such ANN based approaches, and the encoding of the problem
into ANN understandable format is essential. The strategy is
to have 16 inputs and 16 output system where each input
connections signifies a piece of the one player (in order) and
each output connection stands for a piece of the other player.
Each input will be active for only one input, showing a
particular piece movement and have values showing from and
to squares in the chess board. The Network Object created is
Fig 3: ANN understandable chessboard[13] then trained using the encoded data that are actually generated
by the human Grandmaster (GM) during Championship
Table 1. Encoding scheme for ANN representation games. The training process requires a set of examples of
White Piece Black Piece proper network behavior - network inputs and the target
outputs. During training the weights and biases of the network
Algebraic Numeric Algebraic Numeric are iteratively adjusted to minimize the error of the network.
e4 5254 d5 4745 The simulation of the designed system allows checking of
Nf6 7163 Nf3 7866 performance for the new input moves. The trained network
object is simulated in the new unknown environment where
with the aid of patterns provided to it. This is to test whether it
In the numeric notation all the squares are numbered with a has learnt to produce an output that is intelligent enough.
unique two-digit numbers. In this simple numeric coordinate
system the file and the rank of the chess board is represented 6. Results and Discussions
by the numerals 1 to 8 starting from left to right (white side) 6.1 Test Case I: Scenario (Initial phase of
and bottom to top respectively. Hence, the individual square
of the chess board can now be denoted by a uniquely
the game)
identifiable co-ordinate value where first digit describes The trained system when tested in the unknown environment
the file and the second one the rank. Hence, the move that found to behave intelligently and was capable enough to
would be written is as shown in the Figure 5.2.The encoded produce the result which drives the chess pieces within the
moves depict the combination of the current position of the board on account of the learned patterns. The system when
tested generated the exact moves as the way grandmasters

9
International Journal of Computer Applications® (IJCA) (0975 – 8887)
National Conference cum Workshop on Bioinformatics and Computational Biology, NCWBCB- 2014

opens the game during the initial stage of the game. The 6.3 Testing of the system in trained
standard patterns followed by the human grandmasters were
clearly imitated by the trained neural network in the early environment:
phase of the game. The designed system when tested with the sequence of trained
move produced the result as shown below in the Table 4. It is
Table 2. Test Data (Scenario 1) found that system behaved very well for the trained sequence
of moves.
Sl. Input Output Remarks
Table 4. Testing result (trained environment)
1 5254 5755 Optimal move
2 2133 7866 Optimal move
3 7163 2836 Optimal move

Sl. Input Output Remarks


1 4244 7866 Good move
Fig 6: Observation Table 2
2 3234 7776 Good move
6.2 Test Case II: Scenario (Intermediate 3 6263 3735 Good move
phase of the game) 4 4445 4746 Good move
After the game progresses, the pieces in the chess board
5 5254 6877 Good move
develop resulting on exponential growth in possibility for
each of the piece to move within the board. During such 6 7152 5870,8839 Castling, positions hinted
scenario the result of the system is found to be very simple 7 5233 6685 Good move
and effective as it realizes and hinted the intermediate move
of a particular piece on the board to be moved next. When an 8 3175 7766 Good move
unknown input move is supplied to the system it is found to 9 7566 5766 Good move
be capable of deciding the position from where the piece is to
10 4142 6665 Good move
be moved. Since the piece to be moved next was clearly
hinted, the tree search technique can help to find out the 11 5465 3865 Good move
suitable destination depending upon the situation of the game 12 7274 6858 Good move
on the board. The Artificial neural network and the tree based
searching technique together in hybrid form is hence found to 13 5141 6521 Good move
be effective that reduce the cost to produce move in terms of 14 1121 4866 Good move
move searching time. Instead of deriving all the possibility
and then searching the entire tree for best possible move, a 15 7485 6663 Good move
tree can formed from the position that is suggested by the 16 4132 6381 Queen thrown
designed system. Fig 8: Observation Table 4
Table 3. Testing result (scenario 2)
6.4 Testing of the system in unknown
Sl. Input Output Remarks environment
The designed system when tested in the new environment
1 6143 3639 Move knight from 36
produced the results that are very much acceptable during
2 6355 4852 Move Queen from 48 initial phase of the game by hinting some of the correct
position of the piece which is to be moved next (eg. 5755).
When the bishop was moved from position 61 to 34, the
system hinted to move pawn from position 67, but is found to
be blocked by knight positioned on 66. Even though it hinted
the invalid move but the system was intelligent enough to
suggest the piece to be move next in the unknown
environment. The system performed even more intelligently
as it hinted to move the knight from position 36 to 44 as
because 44 is found to be a good position supported by one of
the pawn residing in the position 55. But, when a move 6344
is tested it hinted to move a bishop from position 38, which is
Fig 7: Searching move using game tree found to be not a good choice. Instead, it could have captured
that knight by its pawn residing in the position 55.

10
International Journal of Computer Applications® (IJCA) (0975 – 8887)
National Conference cum Workshop on Bioinformatics and Computational Biology, NCWBCB- 2014

The designed system when tested in the untaught environment Table 6. Test data (unknown environment 2)
produced the following results:
Table 5. Testing result (unknown environment 1) Sl. Input Output Observation Remarks

Sl. Input Output Observation Move pawn Optimal


1 5254 5755
from 57 move
1 5254 5755 Good move
Move knight Optimal
2 6134 7866
2 2133 7866 Good move from 78 move

3 7163 2836 Good move Move knight Optimal


3 4243 2836
from 28 move
Move pawn(knight blocks
4 6134 6705
the move) Move bishop
4 7163 6829 Good move
Move knight (very strong from 68
5 4243 3644
move) Move knight
Move pawn (destination not 5 2133 6671 Good move
6 4142 2755 from 66
defined) Move pawn
6 3175 6705 Good move
7 6344 3845 Move bishop (weak move) from 67
Move pawn
7 7584 7759 Good move
from 77
Move pawn
8 8283 8765 Good move
from 87
Move knight Optimal
9 8473 7460
from 74 move

7. CONCLUSION
The ANN’s can be trained to learn moves as complex as those
of chess games have been long debated upon. Apart from
Fig 9: Observation Table 5 Octavian there has been no mention of ANN applications in
chess playing. Even Octavius reports degradation in
The result of the game shown above in the Table 5 was performance. Our work brings out the fact that ANN’s can
readjusted using the concept of game tree technique when indeed be used for playing, teaching or helping humans in
required. The network is then further trained with the input playing chess. A true minimax search of a game tree may be
and the correct output so that the system adapts such scenario. expensive since every leaf node must be visited. Since, for a
Again, after training the system with the moves where system uniform tree with exactly W moves at each node, there are
found difficult to produce good result, the system produced WD nodes at the layer of the tree that is D ply from the root.
results as shown in the Table 6. Because of the depth of the game tree for chess was
potentially too deep to be successful when using a pure
approach, it was found if Artificial Neural Network and tree
searching technique used in hybrid form can substantially
reduce the move searching cost in terms of time and space. If
sufficient number of training patterns is presented to ANN, it
was found that the machine cleverly hints the suitable position
from where the move can be made. This position can be used
to derive a tree which tends to produce effective moves.
In the simplest case the best algorithm is the one that visits
fewest nodes when determining the true value of a tree. It was
found that the scope of chess as a problem domain was too
broad for minimax approach because of the fact that every
leaf node is to be reached for best move. Therefore, the
problem was narrowed by the way ANN performed. A lot of
Fig 10: Observation Table 6 time can be saved by the use of this smarter approach as
because there is no requirement to visit all leaves. This
technique can be used to device a chess engine that can play
suggest moves, and to improvise its play, game after game,
improving the understanding gained by the human players
during the play.

8. REFERENCES
[1] Murray Campbell, A. Joseph Hoane Jr., Feng-hsiung
Hsu, “Deep Blue”, IBM,August 1, 2001.
[2] Richard Peter Dazeley, “Investigations into Playing
Chess Endgames using Reinforcement Learning”

11
International Journal of Computer Applications® (IJCA) (0975 – 8887)
National Conference cum Workshop on Bioinformatics and Computational Biology, NCWBCB- 2014

Bachelor of Computing with Honours, University of [9] Olivier Mehani, “Complex Systems Seminar, Can
Tasmania (October, 2001) complex systems help design better chess-playing
programs”, February, 1 2006
[3] Jeroen W.T. Carolus, “Alpha-Beta with Sibling
Prediction Pruning in Chess” Netherlands 2006 [10] Robert Epstein, Gary Roberts, Grace Beber, “Parsing the
turing test philosophical and Methodological Issues in
[4] C.E. Shannon, “Programming a Computer for Playing the Quest for the Thinking Computer”. Springer, 03-Dec-
Chess”, Philosophical Magazine, Ser. 7, Vol. 41, Bell 2008
Telephone Laboratories, March 1950
[11] Robert Levinson and Ryan Weber, “Chess
[5] AlexandruGodescu, “An information theoretic analysis Neighbourhoods, Function Combination and
of decision in computer chess” ETH Zurich December Reinforcement Learning”, University of California Santa
13, 2011 Cruz, Springer, October 2000
[6] LaurenceFausett, “Fundamentals of Neural Networks [12] JoonatanManttari and Jonas Larsson, “Applications of
Architectures, Algorithms, and Applications”, Dorling Artificial Neural Networks in Games; An Overview”.
Kindersley Pvt. Ltd., South Asia, 2008 School of Innovation, Design and Engineering
[7] Nicolas Lassabe, Stephane Sanchez HerveLuga and Yves [13] Diwas Sharma, Udit Kr. Chakraborty, Artificial Neural
Duthen,“Genetically Programmed Strategies for Chess Network based adaptive chess playing machine.
Endgames”. GECCO’06, July 8-12, 2006 International Journal of Advance Research in Computer
[8] T.A. Marsland and Y. Björnsson, “From Minimax to Science, Vol 4 no. 4, March-April 2013.
Manhattan,”, University of Alberta Canada [14] http://en.wikipedia.org/wiki/ICCF_numeric_notation
dated: 12/10/2012
[15] Adam Berent “ChessBin” Version: 0.0.8.0 (snapsorts)

12

You might also like