private bool IsBetter(BotAttempt comparison, BotAttempt current) { if (!TestValue(MainComparisonType, current.Maximize, comparison.Maximize)) { return(false); } else if (current.Maximize == comparison.Maximize) { if (!TestValue(Tie1ComparisonType, current.TieBreak1, comparison.TieBreak1)) { return(false); } else if (current.TieBreak1 == comparison.TieBreak1) { if (!TestValue(Tie2ComparisonType, current.TieBreak2, comparison.TieBreak2)) { return(false); } else if (current.TieBreak2 == comparison.TieBreak2) { if (!TestValue(Tie3ComparisonType, current.TieBreak3, current.TieBreak3)) { return(false); } } } } return(true); }
private void NewMenuItem_Click(object sender, EventArgs e) { CurrentFileName = string.Empty; _bestBotAttempt = null; ControlProbabilityPanel.Controls .OfType <BotControlsRow>() .ToList() .ForEach(cp => cp.Probability = 0); FrameLength = 0; MaximizeAddress = 0; TieBreaker1Address = 0; TieBreaker2Address = 0; TieBreaker3Address = 0; StartFromSlotBox.SelectedIndex = 0; MainOperator.SelectedIndex = 0; Tiebreak1Operator.SelectedIndex = 0; Tiebreak2Operator.SelectedIndex = 0; Tiebreak3Operator.SelectedIndex = 0; MainBestRadio.Checked = true; MainValueNumeric.Value = 0; TieBreak1Numeric.Value = 0; TieBreak2Numeric.Value = 0; TieBreak3Numeric.Value = 0; TieBreak1BestRadio.Checked = true; TieBreak2BestRadio.Checked = true; TieBreak3BestRadio.Checked = true; UpdateBestAttempt(); UpdateComparisonBotAttempt(); }
private void ClearBestButton_Click(object sender, EventArgs e) { _bestBotAttempt = null; Attempts = 0; Frames = 0; UpdateBestAttempt(); UpdateComparisonBotAttempt(); }
public BasicBot() { InitializeComponent(); Text = DialogTitle; Settings = new BasicBotSettings(); _comparisonBotAttempt = new BotAttempt(); }
private void Update(bool fast) { if (_dontUpdateValues) { return; } if (_replayMode) { int index = Emulator.Frame - _startFrame; if (index < _bestBotAttempt.Log.Count) { var logEntry = _bestBotAttempt.Log[index]; var lg = Global.MovieSession.MovieControllerInstance(); lg.SetControllersAsMnemonic(logEntry); foreach (var button in lg.Type.BoolButtons) { // TODO: make an input adapter specifically for the bot? Global.LuaAndAdaptor.SetButton(button, lg.IsPressed(button)); } } else { FinishReplay(); } } else if (_isBotting) { if (Emulator.Frame >= _targetFrame) { Attempts++; Frames += FrameLength; _currentBotAttempt.Maximize = MaximizeValue; _currentBotAttempt.TieBreak1 = TieBreaker1Value; _currentBotAttempt.TieBreak2 = TieBreaker2Value; _currentBotAttempt.TieBreak3 = TieBreaker3Value; PlayBestButton.Enabled = true; if (_bestBotAttempt == null || IsBetter(_bestBotAttempt, _currentBotAttempt)) { _bestBotAttempt = _currentBotAttempt; UpdateBestAttempt(); } _currentBotAttempt = new BotAttempt { Attempt = Attempts }; GlobalWin.MainForm.LoadQuickSave(SelectedSlot, false, true); } PressButtons(); } }
private void StartBot() { if (!CanStart()) { MessageBox.Show("Unable to run with current settings"); return; } _isBotting = true; ControlsBox.Enabled = false; StartFromSlotBox.Enabled = false; RunBtn.Visible = false; StopBtn.Visible = true; GoalGroupBox.Enabled = false; _currentBotAttempt = new BotAttempt { Attempt = Attempts }; if (Global.MovieSession.Movie.IsRecording) { _oldCountingSetting = Global.MovieSession.Movie.IsCountingRerecords; Global.MovieSession.Movie.IsCountingRerecords = false; } _dontUpdateValues = true; GlobalWin.MainForm.LoadQuickSave(SelectedSlot, false, true); // Triggers an UpdateValues call _dontUpdateValues = false; _targetFrame = Emulator.Frame + (int)FrameLengthNumeric.Value; GlobalWin.MainForm.UnpauseEmulator(); if (Settings.TurboWhenBotting) { SetMaxSpeed(); } UpdateBotStatusIcon(); MessageLabel.Text = "Running..."; _cachedControlProbabilities = ControlProbabilities; _logGenerator = Global.MovieSession.LogGeneratorInstance(); _logGenerator.SetSource(Global.ClickyVirtualPadController); }
private void StopBot() { RunBtn.Visible = true; StopBtn.Visible = false; _isBotting = false; _targetFrame = 0; ControlsBox.Enabled = true; StartFromSlotBox.Enabled = true; _targetFrame = 0; _currentBotAttempt = null; GoalGroupBox.Enabled = true; if (Global.MovieSession.Movie.IsRecording) { Global.MovieSession.Movie.IsCountingRerecords = _oldCountingSetting; } GlobalWin.MainForm.PauseEmulator(); SetNormalSpeed(); UpdateBotStatusIcon(); MessageLabel.Text = "Bot stopped"; }
private bool LoadBotFile(string path) { var file = new FileInfo(path); if (!file.Exists) { return false; } var json = File.ReadAllText(path); var botData = (BotData)ConfigService.LoadWithType(json); _bestBotAttempt = botData.Best; var probabilityControls = ControlProbabilityPanel.Controls .OfType<BotControlsRow>() .ToList(); foreach (var kvp in botData.ControlProbabilities) { var control = probabilityControls.Single(c => c.ButtonName == kvp.Key); control.Probability = kvp.Value; } MaximizeAddress = botData.Maximize; TieBreaker1Address = botData.TieBreaker1; TieBreaker2Address = botData.TieBreaker2; TieBreaker3Address = botData.TieBreaker3; try { MainComparisonType = botData.ComparisonTypeMain; Tie1ComparisonType = botData.ComparisonTypeTie1; Tie2ComparisonType = botData.ComparisonTypeTie2; Tie3ComparisonType = botData.ComparisonTypeTie3; MainBestRadio.Checked = botData.MainCompareToBest; TieBreak1BestRadio.Checked = botData.TieBreaker1CompareToBest; TieBreak2BestRadio.Checked = botData.TieBreaker2CompareToBest; TieBreak3BestRadio.Checked = botData.TieBreaker3CompareToBest; MainValueRadio.Checked = !botData.MainCompareToBest; TieBreak1ValueRadio.Checked = !botData.TieBreaker1CompareToBest; TieBreak2ValueRadio.Checked = !botData.TieBreaker2CompareToBest; TieBreak3ValueRadio.Checked = !botData.TieBreaker3CompareToBest; MainValueNumeric.Value = botData.MainCompareToValue; TieBreak1Numeric.Value = botData.TieBreaker1CompareToValue; TieBreak2Numeric.Value = botData.TieBreaker2CompareToValue; TieBreak3Numeric.Value = botData.TieBreaker3CompareToValue; } catch { MainComparisonType = 0; Tie1ComparisonType = 0; Tie2ComparisonType = 0; Tie3ComparisonType = 0; MainBestRadio.Checked = true; TieBreak1BestRadio.Checked = true; TieBreak2BestRadio.Checked = true; TieBreak3BestRadio.Checked = true; MainBestRadio.Checked = false; TieBreak1BestRadio.Checked = false; TieBreak2BestRadio.Checked = false; TieBreak3BestRadio.Checked = false; MainValueNumeric.Value = 0; TieBreak1Numeric.Value = 0; TieBreak2Numeric.Value = 0; TieBreak3Numeric.Value = 0; } FrameLength = botData.FrameLength; FromSlot = botData.FromSlot; Attempts = botData.Attempts; Frames = botData.Frames; _currentDomain = !string.IsNullOrWhiteSpace(botData.MemoryDomain) ? MemoryDomains[botData.MemoryDomain] : MemoryDomains.MainMemory; _bigEndian = botData.BigEndian; _dataSize = botData.DataSize > 0 ? botData.DataSize : 1; UpdateBestAttempt(); UpdateComparisonBotAttempt(); if (_bestBotAttempt != null) { PlayBestButton.Enabled = true; } CurrentFileName = path; Settings.RecentBotFiles.Add(CurrentFileName); MessageLabel.Text = Path.GetFileNameWithoutExtension(path) + " loaded"; return true; }
private void NewMenuItem_Click(object sender, EventArgs e) { CurrentFileName = string.Empty; _bestBotAttempt = null; ControlProbabilityPanel.Controls .OfType<BotControlsRow>() .ToList() .ForEach(cp => cp.Probability = 0); FrameLength = 0; MaximizeAddress = 0; TieBreaker1Address = 0; TieBreaker2Address = 0; TieBreaker3Address = 0; StartFromSlotBox.SelectedIndex = 0; MainOperator.SelectedIndex = 0; Tiebreak1Operator.SelectedIndex = 0; Tiebreak2Operator.SelectedIndex = 0; Tiebreak3Operator.SelectedIndex = 0; MainBestRadio.Checked = true; MainValueNumeric.Value = 0; TieBreak1Numeric.Value = 0; TieBreak2Numeric.Value = 0; TieBreak3Numeric.Value = 0; TieBreak1BestRadio.Checked = true; TieBreak2BestRadio.Checked = true; TieBreak3BestRadio.Checked = true; UpdateBestAttempt(); UpdateComparisonBotAttempt(); }
private bool LoadBotFile(string path) { var file = new FileInfo(path); if (!file.Exists) { return(false); } var json = File.ReadAllText(path); var botData = (BotData)ConfigService.LoadWithType(json); _bestBotAttempt = botData.Best; var probabilityControls = ControlProbabilityPanel.Controls .OfType <BotControlsRow>() .ToList(); foreach (var kvp in botData.ControlProbabilities) { var control = probabilityControls.Single(c => c.ButtonName == kvp.Key); control.Probability = kvp.Value; } MaximizeAddress = botData.Maximize; TieBreaker1Address = botData.TieBreaker1; TieBreaker2Address = botData.TieBreaker2; TieBreaker3Address = botData.TieBreaker3; try { MainComparisonType = botData.ComparisonTypeMain; Tie1ComparisonType = botData.ComparisonTypeTie1; Tie2ComparisonType = botData.ComparisonTypeTie2; Tie3ComparisonType = botData.ComparisonTypeTie3; MainBestRadio.Checked = botData.MainCompareToBest; TieBreak1BestRadio.Checked = botData.TieBreaker1CompareToBest; TieBreak2BestRadio.Checked = botData.TieBreaker2CompareToBest; TieBreak3BestRadio.Checked = botData.TieBreaker3CompareToBest; MainValueRadio.Checked = !botData.MainCompareToBest; TieBreak1ValueRadio.Checked = !botData.TieBreaker1CompareToBest; TieBreak2ValueRadio.Checked = !botData.TieBreaker2CompareToBest; TieBreak3ValueRadio.Checked = !botData.TieBreaker3CompareToBest; MainValueNumeric.Value = botData.MainCompareToValue; TieBreak1Numeric.Value = botData.TieBreaker1CompareToValue; TieBreak2Numeric.Value = botData.TieBreaker2CompareToValue; TieBreak3Numeric.Value = botData.TieBreaker3CompareToValue; } catch { MainComparisonType = 0; Tie1ComparisonType = 0; Tie2ComparisonType = 0; Tie3ComparisonType = 0; MainBestRadio.Checked = true; TieBreak1BestRadio.Checked = true; TieBreak2BestRadio.Checked = true; TieBreak3BestRadio.Checked = true; MainBestRadio.Checked = false; TieBreak1BestRadio.Checked = false; TieBreak2BestRadio.Checked = false; TieBreak3BestRadio.Checked = false; MainValueNumeric.Value = 0; TieBreak1Numeric.Value = 0; TieBreak2Numeric.Value = 0; TieBreak3Numeric.Value = 0; } FrameLength = botData.FrameLength; FromSlot = botData.FromSlot; Attempts = botData.Attempts; Frames = botData.Frames; _currentDomain = !string.IsNullOrWhiteSpace(botData.MemoryDomain) ? MemoryDomains[botData.MemoryDomain] : MemoryDomains.MainMemory; _bigEndian = botData.BigEndian; _dataSize = botData.DataSize > 0 ? botData.DataSize : 1; UpdateBestAttempt(); UpdateComparisonBotAttempt(); if (_bestBotAttempt != null) { PlayBestButton.Enabled = true; } CurrentFileName = path; Settings.RecentBotFiles.Add(CurrentFileName); MessageLabel.Text = Path.GetFileNameWithoutExtension(path) + " loaded"; AssessRunButtonStatus(); return(true); }
private void StartBot() { if (!CanStart()) { MessageBox.Show("Unable to run with current settings"); return; } _isBotting = true; ControlsBox.Enabled = false; StartFromSlotBox.Enabled = false; RunBtn.Visible = false; StopBtn.Visible = true; GoalGroupBox.Enabled = false; _currentBotAttempt = new BotAttempt { Attempt = Attempts }; if (Global.MovieSession.Movie.IsRecording) { _oldCountingSetting = Global.MovieSession.Movie.IsCountingRerecords; Global.MovieSession.Movie.IsCountingRerecords = false; } _dontUpdateValues = true; GlobalWin.MainForm.LoadQuickSave(SelectedSlot, false, true); // Triggers an UpdateValues call _dontUpdateValues = false; _targetFrame = Global.Emulator.Frame + (int)FrameLengthNumeric.Value; GlobalWin.MainForm.UnpauseEmulator(); if (Settings.TurboWhenBotting) { SetMaxSpeed(); } UpdateBotStatusIcon(); MessageLabel.Text = "Running..."; _cachedControlProbabilities = ControlProbabilities; _logGenerator = Global.MovieSession.LogGeneratorInstance(); _logGenerator.SetSource(Global.ClickyVirtualPadController); }
private void NewMenuItem_Click(object sender, EventArgs e) { CurrentFileName = string.Empty; _bestBotAttempt = null; ControlProbabilityPanel.Controls .OfType<BotControlsRow>() .ToList() .ForEach(cp => cp.Probability = 0); FrameLength = 0; MaximizeAddress = 0; TieBreaker1Address = 0; TieBreaker2Address = 0; TieBreaker3Address = 0; StartFromSlotBox.SelectedIndex = 0; UpdateBestAttempt(); }
private bool IsBetter(BotAttempt best, BotAttempt current) { if (current.Maximize > best.Maximize) { return true; } else if (current.Maximize == best.Maximize) { if (current.TieBreak1 > best.TieBreak1) { return true; } else if (current.TieBreak1 == best.TieBreak1) { if (current.TieBreak2 > best.TieBreak2) { return true; } else if (current.TieBreak2 == best.TieBreak2) { if (current.TieBreak3 > current.TieBreak3) { return true; } } } } return false; }
private void Update(bool fast) { if (_dontUpdateValues) { return; } if (!HasFrameAdvanced()) { return; } if (_replayMode) { int index = Emulator.Frame - _startFrame; if (index < _bestBotAttempt.Log.Count) { var logEntry = _bestBotAttempt.Log[index]; var lg = Global.MovieSession.MovieControllerInstance(); lg.SetControllersAsMnemonic(logEntry); foreach (var button in lg.Definition.BoolButtons) { // TODO: make an input adapter specifically for the bot? Global.LuaAndAdaptor.SetButton(button, lg.IsPressed(button)); } } else { FinishReplay(); } } else if (_isBotting) { if (Emulator.Frame >= _targetFrame) { Attempts++; Frames += FrameLength; _currentBotAttempt.Maximize = MaximizeValue; _currentBotAttempt.TieBreak1 = TieBreaker1Value; _currentBotAttempt.TieBreak2 = TieBreaker2Value; _currentBotAttempt.TieBreak3 = TieBreaker3Value; PlayBestButton.Enabled = true; if (_bestBotAttempt == null || IsBetter(_bestBotAttempt, _currentBotAttempt)) { _bestBotAttempt = _currentBotAttempt; UpdateBestAttempt(); } _currentBotAttempt = new BotAttempt { Attempt = Attempts }; GlobalWin.MainForm.LoadQuickSave(SelectedSlot, false, true); } //Before this would have 2 additional hits before the frame even advanced, making the amount of inputs greater than the number of frames to test. if (_currentBotAttempt.Log.Count < FrameLength) //aka do not Add more inputs than there are Frames to test { PressButtons(); _lastFrameAdvanced = Emulator.Frame; } } }
private void Update(bool fast) { if (_dontUpdateValues) { return; } if (_replayMode) { int index = Emulator.Frame - _startFrame; if (index < _bestBotAttempt.Log.Count) { var logEntry = _bestBotAttempt.Log[index]; var lg = Global.MovieSession.MovieControllerInstance(); lg.SetControllersAsMnemonic(logEntry); foreach (var button in lg.Type.BoolButtons) { // TODO: make an input adapter specifically for the bot? Global.LuaAndAdaptor.SetButton(button, lg.IsPressed(button)); } } else { FinishReplay(); } } else if (_isBotting) { if (Global.Emulator.Frame >= _targetFrame) { Attempts++; Frames += FrameLength; _currentBotAttempt.Maximize = MaximizeValue; _currentBotAttempt.TieBreak1 = TieBreaker1Value; _currentBotAttempt.TieBreak2 = TieBreaker2Value; _currentBotAttempt.TieBreak3 = TieBreaker3Value; PlayBestButton.Enabled = true; if (IsBetter(_comparisonBotAttempt, _currentBotAttempt)) { _bestBotAttempt = _currentBotAttempt; UpdateBestAttempt(); } _currentBotAttempt = new BotAttempt { Attempt = Attempts }; GlobalWin.MainForm.LoadQuickSave(SelectedSlot, false, true); } PressButtons(); } }
private void ClearBestButton_Click(object sender, EventArgs e) { _bestBotAttempt = null; UpdateBestAttempt(); }
private bool IsBetter(BotAttempt comparison, BotAttempt current) { if (!TestValue(MainComparisonType, current.Maximize, comparison.Maximize)) { return false; } else if (current.Maximize == comparison.Maximize) { if (!TestValue(Tie1ComparisonType, current.TieBreak1, comparison.TieBreak1)) { return false; } else if (current.TieBreak1 == comparison.TieBreak1) { if (!TestValue(Tie2ComparisonType, current.TieBreak2, comparison.TieBreak2)) { return false; } else if (current.TieBreak2 == comparison.TieBreak2) { if (!TestValue(Tie3ComparisonType, current.TieBreak3, current.TieBreak3)) { return false; } } } } return true; }