Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: High performance move generation

Author: Dan Newman

Date: 13:30:26 11/16/99

Go up one level in this thread


On November 16, 1999 at 09:33:09, Pat King wrote:

>I do the same thing seperating capture and non-capture generation. I also extend
>your piece list concept a bit to avoid switches and big array lookups.
>
>In part...
>
>class CPiece {
>  private:
>    int Square;
>    int Color;
>    // etc
>  public:
>    // CMove set up as linked list. Slow, I know.
>    virtual CMove * GenCaptures(CMove * ML);
>    virtual CMove * GenNoCaptures(CMove * ML);
>    virtual void MakeMove(CMove * M);
>    virtual void UnMove( );
>    // etc
>};
>
>CPiece * Pieces[32];
>
>CMove * GenerateCaptureMoves(CMove * ML) {
>  if (WhiteToMove) for (int i = WP1; i <= WK; i++)
>    ML = Pieces[i]->GenCaptures(ML);
>  else for (int i = BP1; i <= BK; i++)
>    ML = Pieces[i]->GenCaptures(ML);
>  return ML;
>};
>
>// GenerateNoCaptureMoves similar, and GenerateMoves just calls the two.
>
>class CKing: public CPiece { // etc
>
>In exchange for the overhead for the extra calls, you get very readable code and
>less complexity (at least in terms of switches and ifs). Of course, my engine
>isn't winning any speed awards :)
>
>Pat

I've been playing around with this sort of thing in Yet Another Chess
Program.  In this one I'm attempting extreme object orientation, but I
think I'm running into trouble with it.  Bad design I suspect.  I'm
having trouble figuring out where certain structures and functions should
go...

For instance, like you are doing, I have an base class for pieces and was
intending to derive the various pieces from that, each with its own move
generation code.  But then how do you handle promotion?  Do you keep a
bunch of spares around or do you delete the pawn and new (say) a queen?
(You could do this with a class specific new and delete for efficiency
I guess--you certainly wouldn't want to do this in the search with
a real memory allocation.)

I put make() and undo() into the move class, though I'm not really sure
this is the best place.

Where do you put the board?  Do you simply make it global so that both
the move generator and make() and undo() can get at it, or do you embed
it into some class?  Currently I have it as a static member of the piece
class, but I don't think that is really working out since make() and
undo() need access to it too...

-Dan.



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.