Mar 21, 2007

[Other] New piece lists done

Mediocre now has piece lists in the Board class like this:
public PieceList w_pawns;
public PieceList b_pawns;
public PieceList w_knights;
public PieceList b_knights;
public PieceList w_bishops;
public PieceList b_bishops;
public PieceList w_rooks;
public PieceList b_rooks;
public PieceList w_queens;
public PieceList b_queens;
public PieceList w_king;
public PieceList b_king;
The piece lists for the kings were a bit of a workaround to make it all work together, obviously there will never be a 'list' of kings.

As I mentioned before my previous piece list was a simple 32 slot array where index 0-15 held the black pieces and 16-31 the white.

The problem with them was the promotions. If a pawn got promoted one of the pawn slots (0-7 for black, 16-23 for white) started representing the promoted piece instead of a pawn.

This caused a lot of unnescessary looping since it was never possible to know beforehand if there was a promoted pawn, so both the ordinary slots for the piece type and the 8 pawn slots had to be checked.

The new setup has arrays for every type of piece which are updated in the makeMove and unmakeMove methods. The array comes with a count keeping track of how many pieces there are in the array.

I also added a boardArrayUnique array that keeps track of which index a certain piece is on in its corresponding piece list. So a 2 on 'd7' in boardArrayUnique and a -6 on 'd7' in boardArray means the black pawn on 'd7' can be found on index 2 in the corresponding piece list.

Perhaps this could be done in an easier way, but I am quite satisfied with the result. It was a needed change.

Moving on

The move generation time was essentially cut in half with this and the other changes I have made since last version. It was quite complicated but worth it.

On to revamping the evaluation, and then Mediocre 0.3 is ready (time to let the beta go, I think Mediocre is stable enough now).

No comments: