예제 #1
0
 public void AddPiece(Piece pc, Square sq)
 {
     _pieces[sq.AsInt()] = pc;
     _byType[PieceTypes.AllPieces.AsInt()] |= sq;
     _byType[pc.Type().AsInt()]            |= sq;
     _bySide[pc.ColorOf().Side]            |= sq;
     _index[sq.AsInt()] = _pieceCount[pc.AsInt()]++;
     _pieceList[pc.AsInt()][_index[sq.AsInt()]] = sq;
     _pieceCount[PieceTypes.AllPieces.MakePiece(pc.ColorOf()).AsInt()]++;
 }
예제 #2
0
        private static bool CountPieceValidity(ReadOnlySpan <char> s)
        {
            var spaceIndex = s.IndexOf(Space);

            if (spaceIndex == -1)
            {
                throw new InvalidFen($"Invalid fen {s.ToString()}");
            }

            var mainSection = s.Slice(0, spaceIndex);

            Span <int> limits = stackalloc int[] { 32, 8, 10, 10, 10, 9, 1 };

            // piece count storage, using index 0 = '/' count
            Span <int> pieceCount = stackalloc int[(int)Pieces.PieceNb];

            foreach (var t in mainSection)
            {
                if (t == '/')
                {
                    if (++pieceCount[0] > SeparatorCount)
                    {
                        throw new InvalidFen($"Invalid fen (too many separators) {s.ToString()}");
                    }
                    continue;
                }

                if (char.IsNumber(t))
                {
                    if (!t.InBetween('1', '8'))
                    {
                        throw new InvalidFen($"Invalid fen (not a valid square jump) {s.ToString()}");
                    }
                    continue;
                }

                var pieceIndex = PieceExtensions.PieceChars.IndexOf(t);

                if (pieceIndex == -1)
                {
                    throw new InvalidFen($"Invalid fen (unknown piece) {s.ToString()}");
                }

                var pc = new Piece((Pieces)pieceIndex);
                var pt = pc.Type();

                pieceCount[pc.AsInt()]++;

                var limit = limits[pt.AsInt()];

                if (pieceCount[pc.AsInt()] > limit)
                {
                    throw new InvalidFen($"Invalid fen (piece limit exceeded for {pc}) {s.ToString()}");
                }
            }
예제 #3
0
        public void RemovePiece(Square square, Piece piece)
        {
            var invertedSq = ~square;

            BoardPieces[piece.AsInt()]      &= invertedSq;
            OccupiedBySide[piece.ColorOf()] &= invertedSq;
            BoardLayout[square.AsInt()]      = PieceExtensions.EmptyPiece;
            if (IsProbing)
            {
                return;
            }
            PieceUpdated?.Invoke(EPieces.NoPiece, square);
        }
예제 #4
0
        public void AddPiece(Piece piece, Square square)
        {
            BitBoard bbsq  = square;
            var      color = piece.ColorOf();

            BoardPieces[piece.AsInt()] |= bbsq;
            OccupiedBySide[color]      |= bbsq;
            BoardLayout[square.AsInt()] = piece;

            if (!IsProbing)
            {
                PieceUpdated?.Invoke(piece, square);
            }
        }
예제 #5
0
파일: Zobrist.cs 프로젝트: rudzen/ChessLib
 public static ulong GetZobristPst(this Piece piece, Square square) => ZobristPst[piece.AsInt()][square.AsInt()];
예제 #6
0
 public BitBoard Pieces(Piece pc) => BoardPieces[pc.AsInt()];