Example #1
0
        protected IEnumerable <Tuple <int, int> > RowDirections(int rowDir)
        {
            for (int i = 1, nextRow = NextPosition(CurrentRow, i, rowDir);                                              //var declarations
                 ChessBoard.IsLegalBoardPosition(nextRow, CurrentColumn) && !IsLocationBlocked(nextRow, CurrentColumn); //terminating conditions
                 i++, nextRow = NextPosition(CurrentRow, i, rowDir))                                                    //iterators
            {
                var nextLocation = new Tuple <int, int>(nextRow, CurrentColumn);
                yield return(nextLocation);

                if (CaptureableLocation.Equals(nextLocation))
                {
                    yield break;
                }
            }
        }
Example #2
0
        private IEnumerable <Tuple <int, int> > ColumnDirections(int colDir)
        {
            for (int i = 1, nextCol = NextPosition(CurrentColumn, i, colDir);                                     //var declarations
                 ChessBoard.IsLegalBoardPosition(CurrentRow, nextCol) && !IsLocationBlocked(CurrentRow, nextCol); //terminating conditions
                 i++, nextCol = NextPosition(CurrentColumn, i, colDir))                                           //iterators
            {
                var nextLocation = new Tuple <int, int>(CurrentRow, nextCol);
                yield return(nextLocation);

                if (CaptureableLocation.Equals(nextLocation))
                {
                    yield break;
                }
            }
        }