Sunday, 13 May 2012

Board representation and piece movement.

There are several ways of representing a chess board in a chess program. One such method is the use of bit boards, but considering the fact that I'm using VB6 I have decided to implement a simple single dimensional array. I'm assuming that visual Basic 6 is quite efficient at handling array and to try to utilise bit-boards would be more complicated to program in VB and maybe less efficient. I may be wrong, we'll just have to see how it goes.

I am representing the board by a single dimensional array of 36 element indexed 0 to 35.

Although it's a single dimensional array, as far as human thinking is concerned, I tend to think of the structure in two dimensions. That way it is easy to see which cells pieces move to etc.

The pieces are represented by positive numbers for white and negative numbers for black with vacant squares represented by zeros as follows:

pawn = 1, Knight = 2, Bishop = 3, Rook = 4, Queen = 5, King = 6

You will notice I have included a value for a bishop when the game does not include bishops. The reason for this is that I intend to give the user the option of setting up their own board position and I'm giving them the option to use bishops if they so desire.

To enable the computer to generate piece moves I have set up two dimensional arrays for each of the pieces which list all the possible moves available from any given square. If you examine the table below you can see for example that a knight on board square 10 has possibly 4 move to squares 2, 14, 21 and 23. Obviously not all of these moves may be legal. The program will have to check the destination square is not occupied by a piece of the same colour, or that it is not moving into check.

I've created similar tables for each of the chess pieces. For example, there are four tables which represent the rook moves. One table for each move direction N, S, E and W. If we take a rook on square 0, the table will show that it can move to squares 1, 2, 3, 4 and 5. The computer will look at each of these in turn until it reaches the end of the list or reaches an occupied square. If it reaches an occupies square with a piece of the same colour then this final move is not playable. If the occupied square has a piece of the opposite colour then that will be the final move available in that direction.

I have created two separate tables (arrays) for the pawn, as, unlike the other pieces which all move the same, the black and white pawns move in opposite directions.

Sunday, 6 May 2012


As I have an interest in programming as well as chess it is not surprising that I've often considered the idea of writing a chess program. Well I've finally decided to have a go. Well it's not quite chess. I've decided to first try something simpler. As a practice run I am writing a program to play chess on a 6x6 board. I am writing this in Visual Basic 6 which would probably not be the best choice for a chess program, but with the speed of computers now and the reduced size of board. I'm hoping a strong program can still emerge. One should also bear in mind that VB6 is a compiled language unlike future versions such as VB.NET etc. Therefore, assuming I'm not doing any bit twiddling - which VB was not made for - I'm hoping it's array handling capabilities can kick ass. If the program is successful I plan to then progress to writing a full chess program, possibly for a Java Applet. Obviously I'll eventually make the programs freely available.

I call the program: 'Son of Maniac'. It is so called because it was inspired by a program written in 1956 by Kister, Stein, Ulam, Walden and Wells at the Los Alamos Scientific Laboratory in New Mexico. Their program played a miniature version of chess on a 6x6 board. There were no bishops, no castling and the pawns could only move one square on their first move. The program ran on a MANIAC computer with a speed of 11000 operations per second. This enabled the program to perform an exhaustive search to a depth of 4-ply in an average of 12 minutes.

The only recorded game (that I know of) played by the program was against a young lady member of the laboratory who was taught how to play chess a week earlier. The game went as follows:

Black: Human

1    d2-d3      b5-b4
2    Ne1-f3     d5-d4
3    b2-b3      e5-e4
4    Nf3-e1     a5-a4
5    b3xa4?     Nb6xa4
6    Kd1-d2?    Na4-c3
7    Nb1xc3     b4xc3+
8    Kd2-d1     f5-f4
9    a2-a3      Ra6-b6
10   a3-a4      Rb6-a6
11   a4-a5      ...

11   ...        Kd6-d5
12   Qc1-a3     Qc6-b5
13   Qa3-a2+    Kd5-e5
14   Ra1-b1?    Ra6xa5
15   Rb1xb5     Ra5xa2
16   Rb5-b1     Ra2-a5
17   f2-f3      Ra5-a4
18   f3xe4      c5-c4
19   Ne1-f3+    Ke5-d6
20   e4-e5+     Kd6-d5
21   e5xf6=Q    Ne6-c5
22   Qf6xd4+    Kd5-c6
23   Nf3-e5#

So far I've just created an initial GUI which will obviously change as the program evolves(see image below).

By clicking on pieces and squares I can move the pieces on the board. It recognises pawn promotion and offers the choice of piece to promote to. Next I need to devise methods whereby the program can generate a list of its legal moves. From then on it will probably just get harder.

Sunday, 10 May 2009

A brief look at Fischer's bust to the King's Gambit.

Some years ago Bobby Fischer suggested what he called a 'A Bust To The King's Gambit' in the American Chess Quarterly (1962-63). Click hear to see the article.

You may only be rarely confronted with this variation, but the King's Gambit may be met often at club level, so, following I give some possible ideas for White.

1.e4 e5 2.f4 exf4 3.Nf3

Fischer's idea is that Black wants to defend the gambit pawn by ...g5 while keeping out White's knight from the attacking square e5. For instance, if at once 3...g5 4.h4 g4 5.Ne5 and White has enough for the pawn.

3...d6 This was called by Fischer 'a high-class waiting move.'

Fischer gives two main lines after...d6.

1) 4.d4 g5 5.h4 g4 6.Ng5 f6! 7.Nh3 gxh3 8.Qh5+ Kd7 9.Bxf4 Qe8 10.Qg4+ Kd8 and White has no real attack for the sacrificed piece.

2) 4.Bc4 h6! 5.d4 g5 6.0-0 Bg7 7.c3 Nc6 8.g3 g4 9.Nh4 f3 when if 10.Qb3 Qe7 11.Bf4 Nf6 12.Nf5 Bxf5 13.exf5 0-0 with a good game for Black. If then 14.Qxb7 Na5 15.Qa6 Nxc4 16.Qxc4 Rab8 material is level but Black holds the initiative.

White can try to postpone pawn to d4 in favour of breaking up the black pawn chain, but 4.Bc4 h6! 5.0-0 g5 6.g3 Bh3 should still favour Black.

A rarely played suggestion for White by Robert G. Wade goes as follows 4.d3 g5 5.h4 g4 6.Ng1 Bh6 7.Bd2 Nc6 8.Nc3 Be6 9.Nce2 White's overall plan has been to hold back his centre in order to avoid premature pawn exchanges.