private void btnStart_Click(object sender, EventArgs e) { // Reset all the feedback values numericUpDown1.Value = 0; progressBar1.Value = 0; trackBar1.Value = 0; // Create FeedbackDelegate instance FeedbackDelegate feedback = null; // Bind delegate dynamically if (rdoSpin.Checked) { feedback = new FeedbackDelegate(updateSpinBox); } else if (rdoProg.Checked) { feedback = new FeedbackDelegate(updateProgressBar); } else if (rdoTrack.Checked) { feedback = new FeedbackDelegate(updateTrackBar); } slowMethod(feedback); }
private void startBtn_Click(object sender, EventArgs e) { FeedbackDelegate feedBackDelegate = null; numericUpDown1.Value = 0; progressBar1.Value = 0; trackBar1.Value = 0; if (spinBoxRbtn.Checked) { feedBackDelegate = new FeedbackDelegate(UpdateSpinBox); } else if (progBarRbtn.Checked) { feedBackDelegate = new FeedbackDelegate(UpdateProgressBar); } else if (trackBarRbtn.Checked) { feedBackDelegate = new FeedbackDelegate(UpdateTrackBar); } try { SlowMethod(feedBackDelegate); } catch (NullReferenceException) { } }
// Will slow down the progress public void slowMethod(FeedbackDelegate feedback) { for (int i = 0; i < 10; i++) { Thread.Sleep(1000); feedback(); } }
public void activate(bool isTutorial, FeedbackDelegate fbDel) { active = true; nextStimulus(); display(displayedStimulus); _isTutorial = isTutorial; _delegate = fbDel; }
public void slowMethod(FeedbackDelegate feedbackDelegate) { for (int i = 0; i < 100; i++) { System.Threading.Thread.Sleep(40); feedbackdelegateInstance(); } }
public void slowMethod(FeedbackDelegate feedbackDelegate) { // use sleep for (int i = 0; i < 10; i++) { Thread.Sleep(1000); feedbackDelegate(); } }
private void SlowMethod(FeedbackDelegate progDelegate) { for (int i = 0; i < 10; i++) { System.Threading.Thread.Sleep(500); progDelegate(); //needed to get the spinBox to work Application.DoEvents(); } }
//resets values and then calls the delegated update method incrementally public void slowMethod(FeedbackDelegate feedbackDelegate) { resetDisplays(); int i = 0; while (i < 10) { System.Threading.Thread.Sleep(400); feedbackDelegate(); i++; } }
public void slowMethod(FeedbackDelegate feedbackDelegate) { resetValues(); for (int i = 0; i < 100; i++) { System.Threading.Thread.Sleep(50); feedbackDelegate(); Application.DoEvents(); } }
private void button1_Click(object sender, EventArgs e) { setUpControls(); // reset if (rbTrackBar.Checked) feedbackDelegate = new FeedbackDelegate(updateTrackBar); else if (rbProgressBar.Checked) feedbackDelegate = new FeedbackDelegate(updateProgressBar); else feedbackDelegate = new FeedbackDelegate(updateSpinBox); slowMethod(feedbackDelegate); // call our slow method, who accepts a FeedBackDelegate }
private void button1_Click(object sender, EventArgs e) { FeedbackDelegate feedbackDelegate = null; if (rdoSpinBox.Checked) feedbackDelegate = new FeedbackDelegate(updateSpinBox); if (rdoProgressBar.Checked) feedbackDelegate = new FeedbackDelegate(updateProgressBar); if (rdoTrackBar.Checked) feedbackDelegate = new FeedbackDelegate(updateTrackBar); slowMethod(feedbackDelegate); }
private void button1_Click(object sender, EventArgs e) { setUpControls(); // reset if (rbTrackBar.Checked) { feedbackDelegate = new FeedbackDelegate(updateTrackBar); } else if (rbProgressBar.Checked) { feedbackDelegate = new FeedbackDelegate(updateProgressBar); } else { feedbackDelegate = new FeedbackDelegate(updateSpinBox); } slowMethod(feedbackDelegate); // call our slow method, who accepts a FeedBackDelegate }
private void button1_Click(object sender, EventArgs e) { if (rbtnSpin.Checked) { feedbackdelegateInstance = new FeedbackDelegate(updateSpinBox); slowMethod(feedbackdelegateInstance); } else if (rbtnProgress.Checked) { feedbackdelegateInstance = new FeedbackDelegate(updateProgressBar); slowMethod(feedbackdelegateInstance); } else { feedbackdelegateInstance = new FeedbackDelegate(updateTrackBar); slowMethod(feedbackdelegateInstance); } }
private void bStart_Click(object sender, EventArgs e) { resetControls(); updateControls(); // Assign method based on checked radiobutton if (rbSpinBox.Checked) feedBackDelegate = new FeedbackDelegate(updateSpinBox); if (rbProgressBar.Checked) feedBackDelegate = new FeedbackDelegate(updateProgressBar); if (rbTrackBar.Checked) feedBackDelegate = new FeedbackDelegate(updateTrackBar); // Execute worker slowMethod(feedBackDelegate); }
//click handler creates delegate and assigns it based on radio button selection private void buttonStart_Click(object sender, EventArgs e) { FeedbackDelegate feedbackDelegate; if (radioButtonProgressBar.Checked == true) { feedbackDelegate = new FeedbackDelegate(updateProgressBar); slowMethod(feedbackDelegate); } if (radioButtonSpinBox.Checked == true) { feedbackDelegate = new FeedbackDelegate(updateSpinBox); slowMethod(feedbackDelegate); } if (radioButtonTrackBar.Checked == true) { feedbackDelegate = new FeedbackDelegate(updateTrackBar); slowMethod(feedbackDelegate); } }
private void slowMethod(FeedbackDelegate feedBackDelegate) { // Reset flag finishedWork = false; while (!finishedWork) { // Do some work System.Threading.Thread.Sleep(500); // Update progress feedBackDelegate(); // Update controls updateControls(); } // Give feedback when done MessageBox.Show("Work Done"); }
private void startBtn_Click(object sender, EventArgs e) { FeedbackDelegate feedBackDelegate = null; numericUpDown1.Value = 0; progressBar1.Value = 0; trackBar1.Value = 0; if (spinBoxRbtn.Checked) feedBackDelegate = new FeedbackDelegate(UpdateSpinBox); else if (progBarRbtn.Checked) feedBackDelegate = new FeedbackDelegate(UpdateProgressBar); else if (trackBarRbtn.Checked) feedBackDelegate = new FeedbackDelegate(UpdateTrackBar); try { SlowMethod(feedBackDelegate); } catch(NullReferenceException) { } }
private void bStart_Click(object sender, EventArgs e) { resetControls(); updateControls(); // Assign method based on checked radiobutton if (rbSpinBox.Checked) { feedBackDelegate = new FeedbackDelegate(updateSpinBox); } if (rbProgressBar.Checked) { feedBackDelegate = new FeedbackDelegate(updateProgressBar); } if (rbTrackBar.Checked) { feedBackDelegate = new FeedbackDelegate(updateTrackBar); } // Execute worker slowMethod(feedBackDelegate); }
private void Form1_Load(object sender, EventArgs e) { feedBackDelegate = null; }
/// <summary> /// Generate an internal chance tree by MC sampling. /// </summary> /// <param name="chanceAbstractions">An array of chance abstractions</param> /// <param name="areAbstractionsEqual">If the absractions are equal, /// one MC sample will update multiple nodes of the chance tree.</param> /// <param name="samplesCount">Number of samples. If equal absractions are used, /// less MC samples will be actually done to reach the specified numbers of updates.</param> /// <param name="rngSeed">RNG seed.</param> /// <param name="feedback">User feedback callback.</param> /// <returns></returns> public static Tree Generate(GameDefinition gd, IChanceAbstraction[] chanceAbstractions, bool areAbstractionsEqual, long samplesCount, int rngSeed, FeedbackDelegate feedback) { if (chanceAbstractions.Length != 2) { throw new ArgumentOutOfRangeException("Only heads up games are supported now"); } McDealer mcDealer = new McDealer(gd, rngSeed); int [][] hands = new int[chanceAbstractions.Length][].Fill(i => new int[mcDealer.HandSize]); int[] handSizes = gd.GetHandSizes(); Tree tree = new Tree { PlayersCount = chanceAbstractions.Length, RoundsCount = gd.RoundsCount, SourceInfo = GetSourceInfo(gd, chanceAbstractions) }; Node root = tree.Root; byte[] abstrCards = new byte[gd.RoundsCount * chanceAbstractions.Length]; uint[] ranks = new uint[chanceAbstractions.Length]; Int64 samplesDone; int updateCount = areAbstractionsEqual ? 2 : 1; for (samplesDone = 0; samplesDone < samplesCount; samplesDone += updateCount) { if (feedback != null && (samplesDone % FEEDBACK_PERIOD == 0)) { if (!feedback(samplesDone)) { break; } } mcDealer.NextDeal(hands); gd.GameRules.Showdown(gd, hands, ranks); int c = 0; for (int r = 0; r < gd.RoundsCount; ++r) { for (int p = 0; p < chanceAbstractions.Length; ++p) { int abstrCard = chanceAbstractions[p].GetAbstractCard(hands[p], handSizes[r]); if (abstrCard < byte.MinValue || abstrCard > byte.MaxValue) { throw new ApplicationException(string.Format("Abstract card {0} out of byte range", abstrCard)); } abstrCards[c++] = (byte)abstrCard; } } for (int u = 0; ;) { LeafT[] leaves = tree.GetLeavesByCards(abstrCards); int lastCard = abstrCards[abstrCards.Length - 1]; leaves[lastCard].Update(ranks); if (++u == updateCount) { break; } // If the abstractions are equal, we can update another node // by permuting cards and results // Note: implemented for 2 players only for (c = 0; c < abstrCards.Length; c += 2) { ShortSequence.Swap(ref abstrCards[c], ref abstrCards[c + 1]); } ShortSequence.Swap(ref ranks[0], ref ranks[1]); } } tree.SamplesCount = (UInt64)samplesDone; tree.UpdateDescription(); return(tree); }
public void activate(bool isTutorial, FeedbackDelegate fbDel) { active = true; _isTutorial = isTutorial; _delegate = fbDel; }