示例#1
0
        // TODO: Refactoroi
        private IList<Square> GetPositionsBetween(Square origin, Square destination)
        {
            var positionsBetweenToReturn = new List<Square>();

            if (origin.AlongFile(destination))
            {
                for (int file = origin.File; file < destination.File; file++)
                    positionsBetweenToReturn.Add(Board.GetSquare(file, origin.Rank));

                for (int file = origin.File; file > destination.File; file--)
                    positionsBetweenToReturn.Add(Board.GetSquare(file, origin.Rank));
            }
            else if (origin.AlongRank(destination))
            {
                for (int rank = origin.Rank; rank < destination.Rank; rank++)
                    positionsBetweenToReturn.Add(Board.GetSquare(origin.File, rank));

                for (int rank = origin.Rank; rank > destination.Rank; rank--)
                    positionsBetweenToReturn.Add(Board.GetSquare(origin.File, rank));
            }
            else if (origin.DiagonallyTo(destination))
            {
                var startingFile = origin.File;
                var startingRank = origin.Rank;

                if (origin.File < destination.File
                    && origin.Rank > destination.Rank)
                {
                    while (startingFile <= destination.File && startingRank <= destination.File)
                    {
                        positionsBetweenToReturn.Add(Board.GetSquare(startingFile, startingRank));
                        startingFile += 1;
                        startingRank -= 1;
                    }
                }
                else if (origin.File > destination.File
                    && origin.Rank < destination.Rank)
                {
                    while (startingFile >= destination.File && startingRank <= destination.Rank)
                    {
                        positionsBetweenToReturn.Add(Board.GetSquare(startingFile, startingRank));
                        startingFile -= 1;
                        startingRank += 1;
                    }
                }
                else if (origin.File < destination.File
                    && origin.Rank < destination.Rank)
                {
                    while (startingFile <= destination.File && startingRank <= destination.Rank)
                    {
                        positionsBetweenToReturn.Add(Board.GetSquare(startingFile, startingRank));
                        startingFile += 1;
                        startingRank += 1;
                    }
                }
                else if (origin.File > destination.File
                    && origin.Rank > destination.Rank)
                {
                    while (startingFile >= destination.File && startingRank >= destination.Rank)
                    {
                        positionsBetweenToReturn.Add(Board.GetSquare(startingFile, startingRank));
                        startingFile -= 1;
                        startingRank -= 1;
                    }
                }
            }

            positionsBetweenToReturn.Remove(origin);
            positionsBetweenToReturn.Remove(destination);

            return positionsBetweenToReturn;
        }