@ main |news |files |fun |java |ai |links |me? |e-mail

Chess - New Ideas.

During the last 3 months (now is 27 of January 1998) I tried to reach only one thing in my chess game - speed, but... failed. Game became more agile but in only negligible proportion. And this was all. My heart was broken. Never the less, few ideas that went through my mind [initially, in my dreams, they should skyrocket me directly into Paradise] now I want share with you. The first idea is about the description of chess board and the second one about certain rules of check. The last idea could guide you when you will write the moves for your chess game.

Description Table.

In describing the pieces on the board, I only changed the position of the Color and Occupation bits. This permitted to cut few kilobytes of fat from the body of the game. What can be done! Everyone those days is obsessed with slim and attractive figure. The chess game is no exception. In this Universe everything goes together after One Universal Law. And, probably, this universality amazed you as many time as me during your life time. But, I believe, it will be better to drop this intense and controversial subject and go back to our simple and rustic talk. So, we spoke about initial description of your chess board. Once I already said what I think about this, but since I am not sure that you was there the last time to know what I said, I will repeat everything once again. And now with my new idea in it.

If you write you Chess Game, never mind with graphics or not, you must have some place where everything starts. My name for this is Description Table. My suggestion is to write it this way: 64 bytes for the whole table. One byte to describe one square. In my last description I have:

  1. 3 bites to describe the piece. Bits 0, 1 and 2.
  2. 1 bit that says if the square is empty or occupied. This is said by bit 3.
  3. 1 bit that indicate the color of the piece (if there are some piece). This indicate by bit 4.

Three bits (bits 5, 6 and 7) are put to zero. This "extra" bits are not used in Description Table, but used later in the game to indicate "piece of promotion".

At the beginning of your game you can initiate the value for each piece like this:

empty   equ 00001000b ;Initiate the value for the Empty Square.
rookb   equ 00000000b ;Initiate the value for the Black Rook.
knightb equ 00000001b ;Initiate the value for the Black Knight.
bishopb equ 00000010b ;Initiate the value for the Black Bishop.
queenb  equ 00000011b ;Initiate the value for the Black Queen.
kingb   equ 00000100b ;Initiate the value for the Black King.
pawnb   equ 00000101b ;Initiate the value for the Black Pawn.
rookw   equ 00010000b ;Initiate the value for the White Rook.
knightw equ 00010001b ;Initiate the value for the White Knight.
bishopw equ 00010010b ;Initiate the value for the White Bishop.
queenw  equ 00010011b ;Initiate the value for the White Queen.
kingw   equ 00010100b ;Initiate the value of the White King.
pawnw   equ 00010101b ;Initiate the value for the White Pawn.

See also that here each piece is:

000b - rook.
001b - knight.
010b - bishop.
011b - queen.
100b - king.
101b - pawn.

This description of the squares have some practical advantage. Later, in your game, very often you will try to find if this, or other piece can enter into given square. And if, for instance, your piece is black, it can enter into the square which is empty or contain white piece. So, if you know what you have in this square, the logic for finding the access to it could be like this:

;==============================================================
cmp cl,empty  ;Description of the content of the square came in CL.
jge rushin    ;If square is empty or have the white piece you can enter.
;-- Otherwise, you have in the square black piece. You cannot enter into it.

rushin:       ;You can enter into this square.
;==============================================================

If you piece is white, you will be able to enter into the square that is empty of have black piece in it. Your logic should be something of this nature:

;==============================================================
cmp cl,empty ;Description of the square arrived in CL.
jle rushin   ;Square in empty or have the black piece in it. You can enter.
;-- Otherwise, square have white piece. You can't enter into it.

rushin:      ;You can enter into this square.
;==============================================================

Description for the whole chess table you can initialize, before the game, this way:
table   db 00000000b,00000001b,00000010b,00000011b,00000100b,00000010b
        db 00000001b,00000000b
        db 00000101b,00000101b,00000101b,00000101b,00000101b,00000101b
        db 00000101b,00000101b
        db 00001000b,00001000b,00001000b,00001000b,00001000b,00001000b
        db 00001000b,00001000b
        db 00001000b,00001000b,00001000b,00001000b,00001000b,00001000b
        db 00001000b,00001000b
        db 00001000b,00001000b,00001000b,00001000b,00001000b,00001000b
        db 00001000b,00001000b
        db 00001000b,00001000b,00001000b,00001000b,00001000b,00001000b
        db 00001000b,00001000b
        db 00010101b,00010101b,00010101b,00010101b,00010101b,00010101b
        db 00010101b,00010101b
        db 00010000b,00010001b,00010010b,00010011b,00010100b,00010010b
        db 00010001b,00010000b

Maybe you would like to say, and where are the coordinates of each piece? And you are absolutely right. You can indicate them but it is somewhat superfluous. When you will go to find all the pieces that you would like to see (usually you will do this for one color in order to find all the moves for this side) the coordinates of each piece will be already there. Position of each piece, counting from the beginning of the Reference Table, represent its coordinates on the chess board. Few examples, probably, will make this passage less scholastic and more transparent.

Beginning of the table is:
mov si,offset table ;Depose in the SI offset of the chain TABLE.

SI keeps now position of Black Rook that is at the position of left-top corner of chess table.

And, for instance, you want to find in the TABLE Black King and save its description in variable KING. Presumably, you have just one Black King on the board. If you will look for him this way:

;=========================================================================
mov si,seg table    ;Depose (just for more clarity) the segment of the TABLE
mov ds,si           ;in DS
mov si,offset table ;Find the initial position of the chess table (TABLE). 
                    ;Now, initial position, is in DS:SI.
mov ah,0            ;AH indicate the number of squares already seen in TABLE.
reviser:
mov al,byte ptr ds:[si] ;Depose the description of one square in AL.
cmp al,kingb        ;See if this square contain the Black King.
je kingfound        ;The King is found.

inc ah              ;Otherwise, go to see the next square.
cmp ah,64           ;All the TABLE was seen?
jl reviser          ;No. At least, one square to look in.

jmp sortie          ;Otherwise, all TABLE was revisioned. This is done only
                    ;for the sake of precaution.

kingfound:          ;You have your King.
mov king,ax         ;Now you saved the description of king in variable KING
                    ;like this: AH  - position of Black King on the chess
                    ;table and in AL description of the piece itself.
;-- And go out. On this Table you have just one King to take care of.

sortie:             ;The end of King hunt.
;============================================================================

Probably, from the last example with the King you could see that the description of coordinates (in the last example in AH) contain this:


bits 0,1,2 - horizontal position.
bits 3,4,5 - vertical position.
Bits 6 and 7 - empty (put to zero).

Second Idea.

When you write your chess game you must find the moves for each piece existing on the board. The biggest part in finding the move will be consumed in recognizing his legality. This "reality check" must be done twice. First "look around" and think about Geography. The second one is taking care about Personality. Geography - be on your guards! Do not fall beyond chess board! Personality - see if your King will be OK after this move. My second idea can help you in dealing with last [his Majesty] problem. Before I will even start speaking about the guideline that I have in mind, I presume that the position on the chess board is legal and you look for some moves that are also legal. So keep in mind:

1) If your King is under the two fires, only King can have some moves.

All the conditions below are true for the pieces others that your King.

2) If your King is under the fire of Pawn or Knight, your pieces can enter only into one square, square where the enemy Pawn or Knight stays. Be careful with one exception - taking pawn "en passant".

3) If your King is under the fire of Rook, Bishop or Queen, you can make the move by taking the threatening piece, or entering in every square between your King and enemy piece that keep your King nervous.

4) When you have your King under one fire your can't move the piece that shelter your King. In other words, if your piece shelter your King against some distant fire, you just can't use it in order to remove next direct threat.

To insure me that all in my last sentences was clear: Piece that shelter King - your piece that will leave your King under the enemy fire if removed from the board. Direct threat - check.

Enjoy writing your game code!

© Liberman Leonid. 27/2/98 leonidd at NO SPAM sympatico dot ca

 

 

© 1996-1998, Particle