Beispiel #1
0
        private ObservableCollection <Move> GetAllLegalBlackPawnMoves(Piece piece)
        {
            ObservableCollection <Move> moves = new ObservableCollection <Move>();
            char file = piece.Square.File;
            int  rank = piece.Square.Rank;

            if (piece.Square.Rank == 7)
            {
                if (rank - 2 >= 1 && This.Board[file][rank - 1].Piece == null && This.Board[file][rank - 2].Piece == null)
                {
                    moves.Add(new Move(file, rank, file, rank - 2));
                }
            }
            if (rank - 1 >= 1 && This.Board[file][rank - 1].Piece == null)
            {
                moves.Add(new Move(file, rank, file, rank - 1));
            }

            if (rank >= 2)
            {
                if (file != 'H' && This.Board[file.Add(1)][rank - 1].HasWhitePiece())
                {
                    moves.Add(new Move(file, rank, file.Add(1), rank - 1));
                }
                if (file != 'A' && This.Board[file.Add(-1)][rank - 1].HasWhitePiece())
                {
                    moves.Add(new Move(file, rank, file.Add(-1), rank - 1));
                }
            }

            return(moves);
        }
Beispiel #2
0
        public string PigIt(string str)
        {
            var list    = str.Split(" ").ToList();
            var newlist = new List <string>();

            foreach (var item in list)
            {
                var x           = item.ToCharArray();
                var firstLetter = x[0];
                var newItem     = new char[0].ToList();
                for (int i = 1; i < x.Length; i++)
                {
                    newItem.Add(x[i]);
                }
                newItem.Add(firstLetter);
                newItem.Add('a');
                newItem.Add('y');
                newlist.Add(string.Join("", newItem));
            }
            return(string.Join(" ", newlist));
        }
Beispiel #3
0
        public int Add(string numbers)
        {
            if (string.IsNullOrWhiteSpace(numbers))
            {
                return(0);
            }

            var delimiter = new char[] { ',', '\n' }.ToList();

            if (numbers.StartsWith("//"))
            {
                delimiter.Add(numbers[2]);
                numbers = numbers.Substring(4);
            }
            var stringOfNumbers = numbers.Split(delimiter.ToArray());
            var negativeNumbers = stringOfNumbers.Where(number => int.Parse(number) < 0);

            HandleNegativeNumbers(negativeNumbers);

            return(stringOfNumbers.Sum(number => int.Parse(number)));
        }