public GridLineEnumerable(Definition.Sudoku sudoku, Definition.LineType lineType)
        {
            if (sudoku == null)
            {
                throw new ArgumentNullException("sudoku");
            }
            this.sudoku = sudoku;

            this.lineType = lineType;
        }
Exemple #2
0
        public static int GetLayer(int index, Definition.LineType lineType)
        {
            switch (lineType)
            {
            case Definition.LineType.Row: return(index / 3);

            case Definition.LineType.Column: return(index % 3);

            default: throw new NotImplementedException();
            }
        }
Exemple #3
0
        private static int GetLayerWithOppositeLineType(int index, Definition.LineType oppositeLineType)
        {
            switch (oppositeLineType)
            {
            case Definition.LineType.Row: return(index % 3);

            case Definition.LineType.Column: return(index / 3);

            default: throw new NotImplementedException();
            }
        }
Exemple #4
0
        private Definition.LineType getOppositeLineType(Definition.LineType sourceLineType)
        {
            switch (sourceLineType)
            {
            case Definition.LineType.Row:
                return(Definition.LineType.Column);

            case Definition.LineType.Column:
                return(Definition.LineType.Row);

            default: throw new NotImplementedException();
            }
        }
        private int getSudokuLineIndex(int gridLineIndex, int gridIndex, Definition.LineType lineType)
        {
            switch (lineType)
            {
            case Definition.LineType.Row:
                return((gridIndex / 3) * 3 + gridLineIndex);

            case Definition.LineType.Column:
                return((gridIndex % 3) * 3 + gridLineIndex);

            default: throw new InvalidOperationException(lineType.ToString());
            }
        }
Exemple #6
0
        private IEnumerable <Definition.Line> Iterator(Definition.Sudoku sudoku, Definition.LineType lineType)
        {
            switch (lineType)
            {
            case Definition.LineType.Row:
                return(sudoku.Rows);

            case Definition.LineType.Column:
                return(sudoku.Columns);

            case Definition.LineType.Both:
                return(sudoku.Rows.Concat(sudoku.Columns));

            default: throw new NotImplementedException();
            }
        }
Exemple #7
0
        public static void GetOtherGrids(this Definition.Grid sourceGrid, Definition.LineType gridLineType, out Definition.Grid otherGrid1, out Definition.Grid otherGrid2)
        {
            int currentLayer = GetLayerWithOppositeLineType(sourceGrid.Index, gridLineType);

            switch (gridLineType)
            {
            case Definition.LineType.Row:
            {
                switch (currentLayer)
                {
                case 0:
                {
                    sourceGrid.TryGetAdjacentGrid(GridAdjacentDirection.Right, out otherGrid1);
                    otherGrid1.TryGetAdjacentGrid(GridAdjacentDirection.Right, out otherGrid2);
                }
                break;

                case 1:
                {
                    sourceGrid.TryGetAdjacentGrid(GridAdjacentDirection.Left, out otherGrid1);
                    sourceGrid.TryGetAdjacentGrid(GridAdjacentDirection.Right, out otherGrid2);
                }
                break;

                case 2:
                {
                    sourceGrid.TryGetAdjacentGrid(GridAdjacentDirection.Left, out otherGrid2);
                    otherGrid2.TryGetAdjacentGrid(GridAdjacentDirection.Left, out otherGrid1);
                }
                break;

                default: throw new NotImplementedException();
                }
            }
            break;

            case Definition.LineType.Column:
            {
                switch (currentLayer)
                {
                case 0:
                {
                    sourceGrid.TryGetAdjacentGrid(GridAdjacentDirection.Down, out otherGrid1);
                    otherGrid1.TryGetAdjacentGrid(GridAdjacentDirection.Down, out otherGrid2);
                }
                break;

                case 1:
                {
                    sourceGrid.TryGetAdjacentGrid(GridAdjacentDirection.Up, out otherGrid1);
                    sourceGrid.TryGetAdjacentGrid(GridAdjacentDirection.Down, out otherGrid2);
                }
                break;

                case 2:
                {
                    sourceGrid.TryGetAdjacentGrid(GridAdjacentDirection.Up, out otherGrid2);
                    otherGrid2.TryGetAdjacentGrid(GridAdjacentDirection.Up, out otherGrid1);
                }
                break;

                default: throw new NotImplementedException();
                }
            }
            break;

            default: throw new NotImplementedException();
            }
        }
Exemple #8
0
        public static IEnumerable <Definition.Element> GetElementsInCurrentGridLine(this Definition.Grid sourceGrid, int layerIndex, Definition.LineType lineType)
        {
            IEnumerable <Definition.GridLine> lines;

            switch (lineType)
            {
            case Definition.LineType.Row:
                lines = sourceGrid.Rows;
                break;

            case Definition.LineType.Column:
                lines = sourceGrid.Columns;
                break;

            default: throw new NotImplementedException();
            }

            return(lines.Skip(layerIndex).First().Elements);
        }
Exemple #9
0
        /// <param name="skipIndex">line index to skip</param>
        public static IEnumerable <Definition.Element> GetElementsInOtherGridLine(this Definition.Grid sourceGrid, int skipIndex, Definition.LineType lineType)
        {
            IEnumerable <Definition.GridLine> lines;

            switch (lineType)
            {
            case Definition.LineType.Row:
                lines = sourceGrid.Rows;
                break;

            case Definition.LineType.Column:
                lines = sourceGrid.Columns;
                break;

            default: throw new NotImplementedException();
            }

            foreach (var line in lines)
            {
                if (line.Index != skipIndex)
                {
                    foreach (var element in line.Elements)
                    {
                        yield return(element);
                    }
                }
            }
        }