Exemple #1
0
 private SolverResultControl GetOrCreateSolverResultControl(int index)
 {
     if (index < m_SolverResultControls.Count)
     {
         return(m_SolverResultControls[index]);
     }
     else
     {
         var r = new SolverResultControl();
         r.Result = null;
         r.Click += (object sender, EventArgs e) =>
         {
             SelectResult(r.Result);
         };
         m_SolverResultControls.Add(r);
         return(r);
     }
 }
Exemple #2
0
        private void RefreshSolverResults()
        {
            var gameState = m_FileView.State;

            m_CancellableTaskHelper.Start(async(CancellationToken ct) =>
            {
                m_SaveMenuItem.Enabled   = m_FileView.HasFile;
                m_SaveAsMenuItem.Enabled = m_FileView.HasFile;
                m_PrevButton.Enabled     = m_FileView.HasPrevious;
                m_NextButton.Enabled     = m_FileView.HasNext;

                if (gameState == null)
                {
                    m_Time.Text  = string.Empty;
                    m_Level.Text = string.Empty;
                    m_CurrentBoardRenderer.Reset();
                    m_Preview.Reset();
                    m_PreviewStrip.Reset();
                }
                else
                {
                    m_Time.Text  = gameState.TimeString;
                    m_Level.Text = string.Format("Level: {0}", gameState.Level);
                    m_CurrentBoardRenderer.SetBoard(gameState.Board);
                    m_Preview.SetPreview(gameState);
                    m_PreviewStrip.SetPreviewStrip(gameState);
                }

                await Task.Delay(1, ct);
                ct.ThrowIfCancellationRequested();
                m_Choices.Controls.Clear();

                if (gameState != null)
                {
                    var scorer = new ResultScorer();

                    var results = await Task.Run(() =>
                    {
                        var r = Solver.BruteForce(gameState);
                        if (m_Options.HideHoles)
                        {
                            r = r.Where(a => !scorer.HasHoles(a));
                        }
                        r = r.Where(a => a.Step.Inputs.Count <= m_Options.MaxMoves + 2);
                        return(r.OrderBy(a => scorer.ScoreResult(a)));
                    });

                    var controls = new List <SolverResultControl>();

                    foreach (var a in results)
                    {
                        await Task.Delay(1, ct);
                        ct.ThrowIfCancellationRequested();
                        SolverResultControl r = GetOrCreateSolverResultControl(controls.Count);
                        r.Result = a;
                        controls.Add(r);
                    }

                    m_Choices.SuspendLayout();
                    m_Choices.Controls.AddRange(controls.ToArray());
                    m_Choices.ResumeLayout();
                }
            });
        }