private IEnumerable <int> GetCastlingPositions(Gameboard gameboard) { bool EmptyAndNoCheck(int direction, BasePiece rookTile) { if (!(rookTile is Rook) || rookTile.HasMoved) { return(false); } if (direction < 0) { for (int index = Position + direction; index >= rookTile.Position; index--) { if (gameboard.Board[index] != null) { return(false); } } } else { for (int index = Position + direction; index <= rookTile.Position; index++) { if (gameboard.Board[index] != null) { return(false); } } } if (gameboard.CheckDetection(Color) || HypotheticalMove(gameboard, Position + direction).CheckDetection(Color) || HypotheticalMove(gameboard, Position + 2 * direction).CheckDetection(Color)) { return(false); } return(true); } if (!HasMoved && (Position == 4 || Position == 60)) { var rookTileLeft = gameboard.Board[Position - 4]; var rookTileRight = gameboard.Board[Position + 3]; if (rookTileLeft != default && EmptyAndNoCheck(-1, rookTileLeft)) { yield return(Position - 2); } if (rookTileRight != null && EmptyAndNoCheck(1, rookTileRight)) { yield return(Position + 2); } } }
protected override IEnumerable <int> GetPotentialMovements(Gameboard gameboard) { var returnValues = new List <(int X, int Y)>(8); for (int index = -1; index < 2; index += 2) { returnValues.Add((PositionXY.X + index, PositionXY.Y - 2)); returnValues.Add((PositionXY.X + index, PositionXY.Y + 2)); returnValues.Add((PositionXY.X - 2, PositionXY.Y + index)); returnValues.Add((PositionXY.X + 2, PositionXY.Y + index)); } return(returnValues.Where(p => p.X >= 0 && p.X < 8 && p.Y >= 0 && p.Y < 8 && (gameboard.Board[ConvertToOneD(p)] != null == false || gameboard.Board[ConvertToOneD(p)] != null == true && gameboard.Board[ConvertToOneD(p)].Color != Color)) .Select(t => ConvertToOneD(t))); }
protected override IEnumerable <int> GetPotentialMovements(Gameboard gameboard) { int possibleMove = (StartPosition == Position) ? 2 : 1; Func <int, bool> enemyPiece = position => gameboard.Board[position] != null && gameboard.Board[position].Color != Color; if (Color == PieceColor.White) { //Position - 7 hack to prevent movement to the left/right var returnValues = GetStraightLines(gameboard, possibleMove).Where(x => x < Position - 7 && gameboard.Board[x] == null); return(returnValues.Concat(GetDiagonals(gameboard, 1).Where(x => x < Position && enemyPiece(x) || x == gameboard.EnPassantTarget))); } else { //Position + 7 hack to prevent movement to the left/right var returnValues = GetStraightLines(gameboard, possibleMove).Where(x => x > Position + 7 && gameboard.Board[x] == null); return(returnValues.Concat(GetDiagonals(gameboard, 1).Where(x => x > Position && enemyPiece(x) || x == gameboard.EnPassantTarget))); } }
protected override IEnumerable <int> GetPotentialMovements(Gameboard gameboard) { return(GetStraightLines(gameboard)); }
protected override IEnumerable <int> GetPotentialMovements(Gameboard gameboard) { return(GetDiagonals(gameboard)); }
protected override IEnumerable <int> GetPotentialMovements(Gameboard gameboard) { return(GetDiagonals(gameboard, 1).Concat(GetStraightLines(gameboard, 1)).Concat(GetCastlingPositions(gameboard))); }