Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: Promotion frequency

Author: Bo Persson

Date: 03:28:43 07/23/02

Go up one level in this thread


On July 23, 2002 at 05:22:40, Russell Reagan wrote:

>On July 23, 2002 at 04:45:23, Bo Persson wrote:
>
>>Why don't you do it like
>>
>>squares[move.to()] = move.promotedPiece();
>>
>>That looks pretty OOP to me :-)
>
>To remain OOPish we can't have parts of one object being dependent upon other
>objects. So the only solution that will work here is if I have a Square class
>that makes up the squares[] array, and then if move.promotedPiece() returns a
>Square object. That's basically the same as doing it the "fast" way in a non-OOP
>approach like:
>
>squares[move.to] = move.promotePiece;
>
>Here is a problem that I see though. How are you going to initialize that Square
>object that you return from promotedPiece()? I think you will have to do the
>if(pieceType == QUEEN) ... else if (pieceType == ROOK)... and so on somewhere
>down the line, because there is no way to initialize the Square object without
>doing that unless you allow it to be initialized by setting it's private data to
>an unsigned int that you pass it, which seems to be bordering on maintaining
>encapsulation. What do you think? Is that still acceptable OOP or should I
>continue searching for a better way?

Well, in my case promotedPiece() doesn't return an int but a Piece object (which
encapsulates an int (or an enum; varies over time)). I don't really have your
Square type, but an array of Pieces in the Board structure. The question is if
the piece placement is a property of each square, or if it is a property of the
board. Or even of the piece. Who knows?

My Board (position) class has an array of Pieces to map from Square (enum {a1,
a2,...) to content. It has a set of bitmaps for the reverse mapping, from piece
to square.

It also has the usual set of flags for its non-positional states: castling, en
passant, and side to move.

>
>It seems that some things don't translate well to an object-oriented model.

Finding the right objects is the really difficult part. Chess is rather complex,
with some irregularities in the rules like checking, castling, en passant and
promotions. Pieces and boards seems like obvious objects to me, just like moves
and maybe a move generator. But do we need a Searcher object, or is that a part
of the position updating itself?

This will let us have fun for many years!  :-)


Bo Persson
bop2@telia.com



This page took 0.25 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.