Пример #1
0
        private void CreateTiles(int[,] Template)
        {
            for (int Row = 0; Row < Template.GetLength(0); Row++)
            {
                for (int Column = 0; Column < Template.GetLength(1); Column++)
                {
                    SudokuTile Tile = new SudokuTile(Row, Column, 9);
                    Tile.Value = Template[Row, Column];
                    Tile.Fix   = Template[Row, Column] == 0 ? false : true;
                    Tiles.Add(Tile);
                }
            }

            GroupByColumn = Tiles.GroupBy(tile => tile.Column).ToList();
            GroupByRow    = Tiles.GroupBy(tile => tile.Row).ToList();
            Columns       = GroupByColumn.Count();
            Rows          = GroupByRow.Count();

            GroupBy3x3.Clear();
            for (int Row = 0; Row < (Rows / MiniSquareSize); Row++)
            {
                for (int Column = 0; Column < (Columns / MiniSquareSize); Column++)
                {
                    var TilesInRange = Tiles.Where(tile => (tile.Row < (Row * MiniSquareSize)) && (tile.Row >= (Row * MiniSquareSize - MiniSquareSize)))
                                       .Where(tile => (tile.Column < (Column * MiniSquareSize)) && (tile.Column >= (Column * MiniSquareSize - MiniSquareSize)));
                    GroupBy3x3.Add(TilesInRange);
                }
            }
        }
Пример #2
0
        private List <int> PossibleMoves(SudokuTile Tile)
        {
            int        Row    = Tile.Row;
            int        Column = Tile.Column;
            List <int> Used   = new List <int>();
            List <int> UnUsed = new List <int>();

            foreach (SudokuTile tile in GroupByColumn[Column])
            {
                Used.Add(tile.Value);
            }

            foreach (SudokuTile tile in GroupByRow[Row])
            {
                Used.Add(Tile.Value);
            }

            foreach (var Box in GroupBy3x3)
            {
                if (Box.Any(tile => tile == Tile))
                {
                    foreach (SudokuTile tile in Box)
                    {
                        Used.Add(tile.Value);
                    }
                    break;
                }
            }

            for (int i = 1; i <= Tile.MaxValue; i++)
            {
                if (!Used.Contains(i) && i > Tile.Value)
                {
                    UnUsed.Add(i);
                }
            }

            return(UnUsed);
        }