コード例 #1
0
ファイル: Kakuro.cs プロジェクト: mahendramavani/Sudoku
        private bool CheckForLastMissingPart(SumCell sumCell, int sum, GameCell[] parts, Direction direction)
        {
            var unSolvedCells = new List <GameCell>();

            foreach (var gameCell in parts)
            {
                if (gameCell.IsSolved)
                {
                    var gameCellValue = gameCell.Value;
                    sumCell.AddAlreadySolved(gameCellValue, direction);
                    sum -= gameCellValue;
                }
                else
                {
                    unSolvedCells.Add(gameCell);
                }
            }

            var unSolvedCount = unSolvedCells.Count;

            if (unSolvedCount == 1)
            {
                unSolvedCells[0].MarkAsSolved(sum);
                return(true);
            }

            if (unSolvedCount > 1)
            {
                if (EliminatePossibilitiesBasedOnRemainingUnSolvedSubset(sum, unSolvedCount, unSolvedCells))
                {
                    return(true);
                }

                var possibleSets  = NumberSets[NumberSet.KeyFrom(unSolvedCount, sum)].Sets;
                var alreadySolved = sumCell.GetAlreadySolved(direction);

                var remainingPossibleSets = possibleSets.Where(x => !x.Intersect(alreadySolved).Any());

                // foreach (var set in remainingPossibleSets)
                // {
                //     foreach (var value in set)
                //     {
                //         foreach (var unSolvedCell in unSolvedCells)
                //         {
                //             unSolvedCell.IsTheValuePossibleSolution(value);
                //         }
                //     }
                // }
            }

            return(false);
        }
コード例 #2
0
ファイル: Kakuro.cs プロジェクト: mahendramavani/Sudoku
        private bool EliminateNeverUsedNumbers(SumCell sumCell, string lookupKey, GameCell[] partCells, Direction direction)
        {
            foreach (var gameCell in partCells.Where(x => x.IsSolved))
            {
                sumCell.AddAlreadySolved(gameCell.Value, direction);
            }

            var neverUsed       = NumberSets[lookupKey].NeverUsed;
            var alreadySolved   = sumCell.GetAlreadySolved(direction);
            var eliminationList = neverUsed.Union(alreadySolved);

            var anythingSolved = false;

            foreach (var gameCell in partCells.Where(x => !x.IsSolved))
            {
                if (gameCell.EliminateTheNumbers(eliminationList.ToArray()))
                {
                    anythingSolved = true;
                }
            }
            return(anythingSolved);
        }