Example #1
0
        // Takes ownership of all arrays passed to it; they should not be changed after the position is created.
        public Position(Piece[] pieceSquares, Color sideToMove, ulong castlingRights, ulong enPassant, int fiftyMoveCounter, int fullMove)
        {
            _pieceBitboards = new BitboardArray();
            _squares        = new PieceSquareArray();
            // safer to go by the length the PieceSquareArray, because the Piece[] will always error on index out of bounds
            for (int i = 0; i < _squares.Length; i++)
            {
                _squares[i] = pieceSquares[i];
            }

            PopulatePieceBitboardsFromSquares(ref _pieceBitboards, pieceSquares);

            _occupiedWhite = CalculateOccupied(Color.White);
            _occupiedBlack = CalculateOccupied(Color.Black);

            _occupied = _occupiedWhite | _occupiedBlack;

            Parent = null;

            SideToMove     = sideToMove;
            CastlingRights = castlingRights;
            EnPassant      = enPassant;

            FiftyMoveCounter = fiftyMoveCounter;
            GamePly          = GamePlyFromFullMove(fullMove, sideToMove);
            _historyPly      = 0;

            RepetitionNumber = 1;

            ZobristHash = ZobristHashing.CalculateFullHash(this);
        }
Example #2
0
        private static void PopulatePieceBitboardsFromSquares(ref BitboardArray pieceBitboards, Piece[] squares)
        {
            for (int i = 0; i < pieceBitboards.Length; i++)
            {
                pieceBitboards[i] = 0;
            }

            for (int ix = 0; ix < 64; ix++)
            {
                var piece = squares[ix];
                if (piece.PieceType == PieceType.None)
                {
                    continue;
                }

                var value = ValueFromIx(ix);
                pieceBitboards[PieceBitboardIndex(piece.Color, piece.PieceType)] |= value;
            }
        }
Example #3
0
 public Position()
 {
     _pieceBitboards = new BitboardArray();
     _squares        = new PieceSquareArray();
 }
Example #4
0
 // would need to copy the contents if this were an array
 private void CopyPieceBitboards(ref BitboardArray ret)
 {
     ret = _pieceBitboards;
 }