Code: Select all
public partial class Board
{
public int sideToMove = Colour.Light;
public int enPassantSqaure = Squares.OffBoard;
public int currentSearchPly = 0;
public int currentHalfMoveCount = 0;
public int currentFiftyMoveRule = 0;
public int currentCastlePermission = 0;
// New piece list implementation
public int[] boardPieces = new int[BoardConstants.BoardSquareCount];
public int[] pceLst = new int[BoardConstants.PieceListMaxSize];
public int[] pceCount = new int[Pieces.PieceTotal];
public Board()
{
this.ClearBoard();
}
}
#region Add piece to board
public static void AddPieceToBoard(this Board board, int pce, int square)
{
board.boardPieces[square] = pce;
AddPieceToList(board, pce, square);
}
public static void AddPieceToList(Board board, int pce, int square)
{
int newIndex = board.pceCount[pce] + BoardConstants.StartIndex[pce];
board.pceLst[newIndex] = square;
board.pceCount[pce]++;
}
#endregion
#region remove Piece from board
public static void RemovePieceFromBoard(this Board board, int square)
{
RemoveFromPieceList(board, board.GetPiece(square), square);
board.boardPieces[square] = Pieces.NoPiece;
}
private static void RemoveFromPieceList(Board board, int pce, int square)
{
int start = BoardConstants.StartIndex[pce];
int end = (start + board.pceCount[pce]) - 1;
int index = start;
for (index = start; index <= end; ++index)
{
if (board.pceLst[index] == square) break;
}
if (index != end)
{
board.pceLst[index] = board.pceLst[end];
}
board.pceLst[end] = Squares.OffBoard;
board.pceCount[pce]--;
}
#endregion
#region move Piece on board
public static void MovePieceOnBoard(this Board board, int fromsq, int tosq)
{
MovePieceOnList(board, board.GetPiece(fromsq), fromsq, tosq);
board.boardPieces[tosq] = board.GetPiece(fromsq);
board.boardPieces[fromsq] = Pieces.NoPiece;
}
private static void MovePieceOnList(Board board, int pce, int fromsq, int tosq)
{
int start = BoardConstants.StartIndex[pce];
int end = (start + board.pceCount[pce]) - 1;
int index = start;
for (index = start; index <= end; ++index)
{
if (board.pceLst[index] == fromsq)
{
board.pceLst[index] = tosq;
}
}
}
#endregion
#region get piece, square
public static int GetPiece(this Board board, int sq)
{
return board.boardPieces[sq];
}
public static int GetSquare(this Board board, int pceIndex)
{
return board.pceLst[pceIndex];
}
#endregion
Thanks for the help and interest
Richard