public PieceArray(PieceArray reference) { _sideIndex = reference._sideIndex; _hash = reference._hash; TotalMaterialValue = reference.TotalMaterialValue; TotalPositionValue = reference.TotalPositionValue; Map = reference.Map; _pieces = new List <int> [reference._pieces.Length]; for (int i = 1; i < reference._pieces.Length; i++) { _pieces[i] = reference._pieces[i].ToList(); } Array.Copy(reference._map, _map, Constants.BoardSize); }
public Position(PieceArray whitePieces, PieceArray blackPieces, GameState initialGameState) { _pieces[0] = whitePieces; _pieces[1] = blackPieces; _gameStateHistory.Push(initialGameState); KingSideSquaresToCheck = new int[2][]; QueenSideSquaresToCheck = new int[2][]; // Regardless of initial King position (Chess960) after castling King stands on same sqares (2/6/58/62) // Also, skip 1 sqare next to the King as it will be checked during regular movement checks // TODO rework KingSideSquaresToCheck[0] = Enumerable.Range(whitePieces.King + 2, Math.Max(62 - whitePieces.King - 1, 0)).Concat(new[] { 62 }).Distinct().ToArray(); KingSideSquaresToCheck[1] = Enumerable.Range(blackPieces.King + 2, Math.Max(6 - blackPieces.King - 1, 0)).Concat(new[] { 6 }).Distinct().ToArray(); QueenSideSquaresToCheck[0] = Enumerable.Range(58, Math.Max(whitePieces.King - 58 - 1, 0)).Concat(new[] { 58 }).Distinct().ToArray(); QueenSideSquaresToCheck[1] = Enumerable.Range(2, Math.Max(blackPieces.King - 2 - 1, 0)).Concat(new[] { 2 }).Distinct().ToArray(); // TODO reworks this to make easier KingSideCastlingAttackMask = new ulong[2]; QueenSideCastlingAttackMask = new ulong[2]; KingSideCastlingMask = new ulong[2]; QueenSideCastlingMask = new ulong[2]; for (int i = whitePieces.King + 1; i <= 62; i++) { KingSideCastlingAttackMask[0] |= 1ul << i; if (!whitePieces.Rooks.Contains(i)) // Rook is not a blocker { KingSideCastlingMask[0] |= 1ul << i; } } for (int i = blackPieces.King + 1; i <= 6; i++) { KingSideCastlingAttackMask[1] |= 1ul << i; if (!blackPieces.Rooks.Contains(i)) { KingSideCastlingMask[1] |= 1ul << i; } } for (int i = whitePieces.King - 1; i >= 58; i--) { QueenSideCastlingAttackMask[0] |= 1ul << i; if (!whitePieces.Rooks.Contains(i)) { QueenSideCastlingMask[0] |= 1ul << i; } } for (int i = blackPieces.King - 1; i >= 2; i--) { QueenSideCastlingAttackMask[1] |= 1ul << i; if (!blackPieces.Rooks.Contains(i)) { QueenSideCastlingMask[1] |= 1ul << i; } } // Rook should be able to reach destination as well if (whitePieces.Rooks.Any()) { for (int i = whitePieces.Rooks.Min() + 1; i <= 59; i++) { if (i != whitePieces.King) { QueenSideCastlingMask[0] |= 1ul << i; } } for (int i = whitePieces.Rooks.Max() - 1; i >= 61; i--) { if (i != whitePieces.King) { KingSideCastlingMask[0] |= 1ul << i; } } } if (blackPieces.Rooks.Any()) { for (int i = blackPieces.Rooks.Min() + 1; i <= 3; i++) { if (i != blackPieces.King) { QueenSideCastlingMask[1] |= 1ul << i; } } for (int i = blackPieces.Rooks.Max() - 1; i >= 5; i--) { if (i != blackPieces.King) { KingSideCastlingMask[1] |= 1ul << i; } } } // Remember initial rook files if ((CurrentState.WhiteCastling & Castling.QueenSide) != 0) { QueenSideRookFile = whitePieces.Rooks.SingleOrDefault(r => r < whitePieces.King) % Constants.BoardFiles; } if ((CurrentState.BlackCastling & Castling.QueenSide) != 0) { QueenSideRookFile = blackPieces.Rooks.SingleOrDefault(r => r < blackPieces.King) % Constants.BoardFiles; } if ((CurrentState.WhiteCastling & Castling.KingSide) != 0) { KingSideRookFile = whitePieces.Rooks.SingleOrDefault(r => r > whitePieces.King) % Constants.BoardFiles; } if ((CurrentState.BlackCastling & Castling.KingSide) != 0) { KingSideRookFile = blackPieces.Rooks.SingleOrDefault(r => r > blackPieces.King) % Constants.BoardFiles; } }
public PieceEnumerator(PieceArray pieceArray) { _array = pieceArray; }