Friday 26 May 2006

One Dimensional Rule

After a few minutes of trying basic mathematical formula, I solved the nature of each piece move. Here I what I found out

//valid moves - linear type - applicable only for 12 x 12 dimension
king = -13, -12, -11, -1, 1, 11, 12, 13
queen = -13, -12, -11, -1, 1, 11, 12, 13
rook = -12, -1, 1, 12
bishop = -13, -11, 11, 13
knight = -25, -23, -14, -10, 10, 14, 23, 25

As an example, knight on square 27 (b1), it can move to

27-25 = 2 (x)
27-23 = 4 (x)
27-14 = 13 (x)
27-10 = 17 (x)
27+10 = 37 (x)
27+14 = 41 (d2)
27+23 = 50 (a3)
27+25 = 52 (c3)

I already coded the rules above, it works for white and black pieces. I haven’t coded the rules for pawn. Queen and king move rules are the same but actually queen can jump to further square. I inserted loop to check all valid squares repeatedly.

Up to now, I have completed listing out all valid moves made by white and black pieces separatedly. Those valid moves able to check

  • extended square
  • capture move
  • blocked path because of capture move or own piece block the way

All those valid moves are stored in vector array for further process like prediciting the best move.. (it takes time to make the A.I part, be patient).

I haven’t implement rules for king castling, pawn rule like its move, en passant, capture, promotion, en passant.

No comments: