Ejemplo n.º 1
0
        public StrategyResult AttemptStrategy(out bool finished, out bool invalid, Difficulty cap = Difficulty.All)
        {
            invalid = false;
            if (PuzzleCompleted())
            {
                finished = true;
                return(null);
            }
            finished = false;
            Snapshot snapshot = new Snapshot(board.Select(cell => cell.info.Clone()).ToArray());

            foreach (Strategy strategy in strategies)
            {
                if ((int)strategy.difficulty > (int)cap)
                {
                    break;
                }
                string         outInfo = "";
                StrategyResult result  = strategy.Apply(this, ref outInfo);
                if (result != null)
                {
                    if (!ValidatePuzzle())
                    {
                        snapshot.CopyTo(this);
                        invalid = true;
                        return(null);
                    }
                    return(result);
                }
            }
            return(null);
        }
Ejemplo n.º 2
0
        public Solution Solve(Difficulty cap = Difficulty.All)
        {
            List <Snapshot> snapshots = new List <Snapshot>();

            snapshots.Add(new Snapshot(this));
            List <StrategyResult> steps = new List <StrategyResult>();
            bool           finished;
            bool           invalid;
            StrategyResult result = AttemptStrategy(out finished, out invalid, cap);

            while (result != null)
            {
                snapshots.Add(new Snapshot(this));
                steps.Add(result);
                result = AttemptStrategy(out finished, out invalid, cap);
            }
            Solution solution = new Solution(snapshots, steps, finished, invalid);

            snapshots[0].CopyTo(this);
            solutionProgress = 0;
            return(solution);
        }