Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: Need Help! Move-Generator performance( for beginners)!

Author: Filip Tvrzsky

Date: 05:45:06 02/20/03

Go up one level in this thread


On February 20, 2003 at 08:10:47, Axel Grüttner wrote:

>I´m programming my first Move Generator using a 10x12 Board.
>
>1)The main structure is somthing like this:
>
>for(i=A1;i<=H8; i++){
>  switch(BOARD[i]){
>    case KNIGHT: ...(make moves)
>    case PAWN  : ...
>    ...}
>}
>is this construct ok? or are there any better models which are simply to
>implement?
>

Major improvement here is to use the list of pieces containing their placing on
the board. Than you don't have to search whole board (64 arrays) but only this
list (16 pieces at most).

>2)First I used for KNIGHT moves a offset-array Koffset={-21,-19,..., 21}
> and implemented it :
>case KNIGHT: {
>  for(j=0; j<8; j++){
>    if(BOARD[i+Koffset[j]]==EMPTY)
>       _make move_
>}
>
>But testing with 8 seperate IF´s
>     case KNIGHT: {
>          if(BOARD[i-21]==EMPTY){_make move_}
>          if(BOARD[i-12]==EMPTY){_make move_}
>          ...
>          if(BOARD[i+21]==EMPTY){_make move_} }
>and without such an Offset-array was much faster. is this because of the LOOP,
>or because of everlasting dereferencing the offset
>

You need to have the lookup table Knight_moves[square][12] containing directly
the list of all possible moves for each square. The last element of all lists is
some arbitrary value which is different from all your legal square indexes,
let's name it END. Your code is going to be like this:
   for (unsigned char* pTo = &Knight_moves[From].To[0]; *pTo != END; pTo++)
     { make_move(From, *pTo); }
Mote that pTo is a pointer!

>3)because of the performance lag, using a loop, i´ve got no idea to realize the
>move generation for the bishop and rook with no use of any LOOP. are the any
>alternatives?
>

I'm afraid only alternative approch for sliding pieces is using of bitboards.

>thx axel

Filip



This page took 0 seconds to execute

Last modified: Thu, 15 Apr 21 08:11:13 -0700

Current Computer Chess Club Forums at Talkchess. This site by Sean Mintz.