Ejemplo n.º 1
0
        public void SolveAsync(object sender, DoWorkEventArgs e)
        {
            BackgroundWorker worker = sender as BackgroundWorker;

            List <List <HexPoint> > results = new List <List <HexPoint> >();
            int  moves = 1;
            bool done  = false;

            logMoves = false;
            while (!done)
            {
                logMoves      = true;
                possibleMoves = new int[moves];
                results       = Solve(engine.GetPossibleMoves(level.StartPos), level.Copy(), moves, new List <HexPoint>());

                if (results.Count > 0)
                {
                    List <List <HexPoint> > prevResults = results;

                    if (moves > 1)
                    {
                        moves--;
                        logMoves      = true;
                        possibleMoves = new int[moves];

                        results = Solve(engine.GetPossibleMoves(level.StartPos), level.Copy(), moves, new List <HexPoint>());

                        if (results.Count == 0)
                        {
                            results = prevResults;
                        }
                        done = true;
                    }
                }

                moves += 2;
                worker.ReportProgress(moves);
            }

            for (int i = 1; i < possibleMoves.Length; i++)
            {
                Console.WriteLine($"[LevelSolver]: Possible moves with {i} moves: {possibleMoves[possibleMoves.Length - i - 1]}");
            }

            MinMoves  = results.Min(x => x.Count);
            Solutions = results.Where(x => x.Count == MinMoves).ToList();
            worker.ReportProgress(100);
            Solved?.Invoke();
        }
Ejemplo n.º 2
0
        public void Solve()
        {
            List <List <HexPoint> > results = new List <List <HexPoint> >();
            int moves = 1;

            while (results.Count == 0)
            {
                results = Solve(engine.GetPossibleMoves(level.StartPos), level.Copy(), moves, new List <HexPoint>());
                moves++;
            }

            MinMoves  = results.Min(x => x.Count);
            Solutions = results.Where(x => x.Count == MinMoves).ToList();
            Solved?.Invoke();
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Raises the <see cref="Solved"/> event.
 /// </summary>
 /// <param name="e"></param>
 /// <see cref="IOrProblemSolver.Solved"/>
 protected virtual void OnSolved(EventArgs e) => Solved?.Invoke(this, e);
 /// <summary>
 /// Raises the <see cref="Solved"/> event.
 /// </summary>
 /// <param name="e"></param>
 private void OnSolved(EventArgs e) => Solved?.Invoke(this, e);
Ejemplo n.º 5
0
 /// <summary>
 /// Called when the constraint is solved
 /// </summary>
 /// <param name="e"></param>
 protected virtual void OnSolved(ConstraintSolvedEventArgs <TOwner> e) => Solved?.Invoke(this, e);
 /// <summary>
 /// Raised the Solved <paramref name="e"/> event arguments.
 /// </summary>
 /// <param name="e"></param>
 protected void OnSolved(SolutionEventArgs e)
 {
     Solved?.Invoke(this, e);
 }
Ejemplo n.º 7
0
 private void OnSolved(ChangeMaker solution)
 => Solved?.Invoke(this, new ChangeMakerSolutionEventArgs(solution));
Ejemplo n.º 8
0
 private void OnSolved()
 {
     Solved?.Invoke(this, EventArgs.Empty);
 }