Example #1
0
        private void OnClickSolution(object sender, EventArgs e)
        {
            RoundButton pegButton  = (RoundButton)sender;
            var         boardState = (Dictionary <KeyValuePair <int, int>, int>)pegButton.Tag;

            SetBoardToState(boardState);
        }
Example #2
0
        void OnWorkCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            var solution = (List <GraphNode <Dictionary <KeyValuePair <int, int>, int> > >)e.Result;

            _tblSolutionTable.Controls.Clear();

            if (solution != null)
            {
                Label foundText = new Label();
                foundText.Text = "Found solution:";
                int columnCounter = 0;
                _tblSolutionTable.Controls.Add(foundText, columnCounter++, 0);

                int counter = 1;
                foreach (var solutionBoard in solution.Reverse <GraphNode <Dictionary <KeyValuePair <int, int>, int> > >())
                {
                    RoundButton pegButton = new RoundButton();
                    pegButton.Height  = 40;
                    pegButton.Width   = 40;
                    pegButton.Click  += OnClickSolution;
                    pegButton.Tag     = new Dictionary <KeyValuePair <int, int>, int>(solutionBoard.Value);
                    pegButton.Enabled = true;
                    pegButton.Text    = Convert.ToString(counter++);

                    _tblSolutionTable.Controls.Add(pegButton, columnCounter++, 2);
                }
            }
            else
            {
                _tblSolutionTable.Controls.Clear();
                Label foundText = new Label();
                foundText.Text = "No solution found.";
                _tblSolutionTable.Controls.Add(foundText, 0, 0);
            }
        }
Example #3
0
        private void PlacePeg(int column, int row)
        {
            RoundButton pegButton = new RoundButton();

            pegButton.Height  = 30;
            pegButton.Width   = 30;
            pegButton.Click  += OnClickPeg;
            pegButton.Enabled = false;
            pegButton.Tag     = new KeyValuePair <int, int>(column, row);

            pegButton.BackColor = Color.DarkRed;

            _tblPegBoard.Controls.Add(pegButton, column, row);
        }
Example #4
0
        private void OnClickPeg(object sender, EventArgs e)
        {
            RoundButton clickedPeg = (RoundButton)sender;

            if (clickedPeg.BackColor == Color.DarkRed)
            {
                // setting start state
                clickedPeg.BackColor = Color.White;
            }
            else if (clickedPeg.BackColor == Color.White)
            {
                // we are setting goal state
                clickedPeg.BackColor = Color.DarkRed;
            }
        }
        private void PlacePeg(int column, int row)
        {
            RoundButton pegButton = new RoundButton();
            pegButton.Height = 30;
            pegButton.Width = 30;
            pegButton.Click += OnClickPeg;
            pegButton.Enabled = false;
            pegButton.Tag = new KeyValuePair<int, int>(column, row);

            pegButton.BackColor = Color.DarkRed;

            _tblPegBoard.Controls.Add(pegButton, column, row);
        }
        void OnWorkCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            var solution = (List<GraphNode<Dictionary<KeyValuePair<int, int>, int>>>)e.Result;

            _tblSolutionTable.Controls.Clear();

            if (solution != null)
            {
                Label foundText = new Label();
                foundText.Text = "Found solution:";
                int columnCounter = 0;
                _tblSolutionTable.Controls.Add(foundText, columnCounter++, 0);

                int counter = 1;
                foreach (var solutionBoard in solution.Reverse<GraphNode<Dictionary<KeyValuePair<int, int>, int>>>())
                {
                    RoundButton pegButton = new RoundButton();
                    pegButton.Height = 40;
                    pegButton.Width = 40;
                    pegButton.Click += OnClickSolution;
                    pegButton.Tag = new Dictionary<KeyValuePair<int, int>, int>(solutionBoard.Value);
                    pegButton.Enabled = true;
                    pegButton.Text = Convert.ToString(counter++);

                    _tblSolutionTable.Controls.Add(pegButton, columnCounter++, 2);
                }
            }
            else
            {
                _tblSolutionTable.Controls.Clear();
                Label foundText = new Label();
                foundText.Text = "No solution found.";
                _tblSolutionTable.Controls.Add(foundText, 0, 0);

            }
        }