/// <summary> /// Called when [simulation complete]. /// </summary> /// <param name="args">The arguments.</param> public void OnSimulationComplete(OnSimulationComplete args) { var jobId = string.Empty; ActiveAgents.TryRemove(args.AgentId, out jobId); var group = Clients.Group(string.Format(GroupNameTemplate, args.AgentId)); group?.onSimulationCompleted(args); }
private void SimulationThread() { try { DiceBet NewBet = SimulatedBet(DiceStrategy.RunReset()); this.Balance += (decimal)NewBet.Profit; Profit += (decimal)NewBet.Profit; while (TotalBetsPlaced < Bets && !Stop && Running) { if (log) { bets.Add(string.Format("{0},{1},{2},{3},{4},{5},{6},{7},{8}" , TotalBetsPlaced, NewBet.Roll, NewBet.Chance, (NewBet.High ? ">" : "<"), NewBet.GetWin(Site) ? "win" : "lose", NewBet.TotalAmount, NewBet.Profit, this.Balance, Profit)); } if (TotalBetsPlaced % 10000 == 0) { OnSimulationWriting?.Invoke(this, new EventArgs()); if (log) { using (StreamWriter sw = File.AppendText(TmpFileName)) { foreach (string tmpbet in bets) { sw.WriteLine(tmpbet); } } bets.Clear(); } } TotalBetsPlaced++; BetsWithSeed++; bool Reset = false; PlaceDiceBet NewBetObject = null; bool win = NewBet.GetWin(Site); string Response = ""; if (BetSettings.CheckResetPreStats(NewBet, NewBet.GetWin(Site), Stats, SiteStats)) { Reset = true; NewBetObject = DiceStrategy.RunReset(); } if (BetSettings.CheckStopPreStats(NewBet, NewBet.GetWin(Site), Stats, out Response, SiteStats)) { this.Stop = (true); } Stats.UpdateStats(NewBet, win); if (DiceStrategy is ProgrammerMode) { (DiceStrategy as ProgrammerMode).UpdateSessionStats(CopyHelper.CreateCopy <SessionStats>(Stats)); (DiceStrategy as ProgrammerMode).UpdateSiteStats(CopyHelper.CreateCopy <SiteStats>(SiteStats)); (DiceStrategy as ProgrammerMode).UpdateSite(CopyHelper.CreateCopy <SiteDetails>(Site.SiteDetails)); } if (BetSettings.CheckResetPostStats(NewBet, NewBet.GetWin(Site), Stats, SiteStats)) { Reset = true; NewBetObject = DiceStrategy.RunReset(); } if (BetSettings.CheckStopPOstStats(NewBet, NewBet.GetWin(Site), Stats, out Response, SiteStats)) { Stop = true; } decimal withdrawamount = 0; if (BetSettings.CheckWithdraw(NewBet, NewBet.GetWin(Site), Stats, out withdrawamount, SiteStats)) { this.Balance -= withdrawamount; } if (BetSettings.CheckBank(NewBet, NewBet.GetWin(Site), Stats, out withdrawamount, SiteStats)) { this.Balance -= withdrawamount; } if (BetSettings.CheckTips(NewBet, NewBet.GetWin(Site), Stats, out withdrawamount, SiteStats)) { this.Balance -= withdrawamount; } bool NewHigh = false; if (BetSettings.CheckResetSeed(NewBet, NewBet.GetWin(Site), Stats, SiteStats)) { GenerateSeeds(); } if (BetSettings.CheckHighLow(NewBet, NewBet.GetWin(Site), Stats, out NewHigh, SiteStats)) { (DiceStrategy as iDiceStrategy).High = NewHigh; } if (!Reset) { NewBetObject = (DiceStrategy as iDiceStrategy).CalculateNextDiceBet(NewBet, win); } if (Running && !Stop && TotalBetsPlaced <= Bets) { if (this.Balance < (decimal)NewBetObject.Amount) { break; } NewBet = SimulatedBet(NewBetObject); this.Balance += (decimal)NewBet.Profit; Profit += (decimal)NewBet.Profit; //save to file } } using (StreamWriter sw = File.AppendText(TmpFileName)) { foreach (string tmpbet in bets) { sw.WriteLine(tmpbet); } } bets.Clear(); OnSimulationComplete?.Invoke(this, new EventArgs()); } catch (Exception e) { Logger.DumpLog(e); } }