Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: Dynamic memory allocation question

Author: David Hanley

Date: 16:40:48 12/02/02

Go up one level in this thread


Well, if you are calling malloc/free in search, that will be expensive.

I tried this approach in a little java chess program ( never went anywhere )
and i ended up preallocating move objects.

There are some advantages, for example:

for( a = 0 ; a < 64 ; ++ a )
{
  if ( board[a] != NULL && board[a].side == toMove )
    board[a].movegen[a].generate();
}

The idea being that, say, pawns from the second rank can have different move
generation functions that know about double jump, and generate moves that know
about setting the en pesant flag, etc.

Then you need something like this

class PawnMove : public Mode
{
  Vector moves;

  PawnMove( int from )
  {
    //pre-generate all move objects that a pawn from this square may make
  }

  void generate()
  {
  }
}





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.