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 void ZobristTestHelper(Position position, int depth)
        {
            Assert.AreEqual(position.ZobristHash, ZobristHashing.CalculateFullHash(position));
            if (depth <= 0)
            {
                return;
            }

            var moves = new List <Move>();

            _moveGenerator.Generate(moves, position);

            foreach (var move in moves)
            {
                var updatedBoard = Position.MakeMove(new Position(), move, position);

                if (!_moveGenerator.OnlyLegalMoves && updatedBoard.MovedIntoCheck())
                {
                    continue;
                }

                ZobristTestHelper(updatedBoard, depth - 1);
            }
        }