/// <summary> /// Changes the bot. /// </summary> /// <param name="file">The file.</param> private static void ChangeBot(string file) { try { var settings = SettingsManager.LoadSettings(file); var bot = Bots[settings]; if (bot == default(BotInstance)) { Bots.Add(new BotInstance(settings)); } else { bot.ChangeSettings(settings); } Queue.Remove(file); } catch (InvalidOperationException ex) { LogService.Warning(ex.InnerException == null ? ex.Message : ex.InnerException.Message); Queue.Add(file); } catch (IOException ex) { LogService.Warning(string.Format("{0} File will be queued for later reading.", ex.Message)); Queue.Add(file); } catch (Exception ex) { LogService.Warning(ex.ToString()); } }
private void refreshUserList(JObject data) { try { if ((string)data.GetValue("lobbyName") == this.LobbyName && ((string)data.GetValue("type") == "join")) { fetchUsername(); } if ((string)data.GetValue("type") == "leave" && (string)data.GetValue("lobbyName") == this.LobbyName) { if (data.GetValue("username").ToString().Contains("bot:")) { App.Current.Dispatcher.Invoke(delegate { Bots.Add(data.GetValue("username").ToString()); }); } fetchUsername(); } } catch (Exception e) { ShowMessageBox(e.Message); } }
public void GetRandom_Seed17_AreEqual() { var exp = new Bot() { Info = new BotInfo("Engine4") }; var bots = new Bots(); bots.Add(new Bot() { Info = new BotInfo("Engine1", 0, true) }); bots.Add(new Bot() { Info = new BotInfo("Engine2", 0, true) }); bots.Add(new Bot() { Info = new BotInfo("Engine3", 0, true) }); bots.Add(exp); var rnd = new Random(17); var act = bots.GetRandom(rnd); Assert.AreEqual(exp, act); }
public SimObject AddOrGetObject(string name) { SimObject obj; if (Objects.ContainsKey(name)) { obj = Objects[name]; } else { if (name.StartsWith("bot")) { obj = new Bot(this, name); Bots.Add(obj as Bot); } else if (name.StartsWith("output")) { obj = new Output(this, name); Outputs.Add(obj as Output); } else { throw new ArgumentException("unknown name"); } Objects[name] = obj; } return(obj); }
public void GetDefault_None_ParametersToString() { var pars = EvaluatorParameters.GetDefault(); var act = BotData.ParametersToString(pars); Console.Write(act); var bots = new Bots(); bots.Add(pars); bots.Save(new FileInfo("default.xml")); }
public Bot GetBot(int id) { if (Bots.ContainsKey(id)) { return(Bots[id]); } var r = new Bot(id); Bots.Add(id, r); return(r); }
public void GetRandom_NoActive_IsNull() { var bots = new Bots(); bots.Add(new Bot() { Info = new BotInfo("Engine1", 0, true) }); var rnd = new Random(17); var act = bots.GetRandom(rnd); Assert.IsNull(act); }
public void GetOrCreate_Existing_AreEqual() { var info = new BotInfo("Engine1", 0); var bots = new Bots(); bots.Add(new Bot() { Info = new BotInfo("Engine1", 0, true) }); var act = bots.GetOrCreate(info); Assert.AreEqual(1, bots.Count, "bots.Count"); Assert.AreEqual("Engine1", act.Info.Name, "Name"); Assert.AreEqual(false, act.Info.Inactive, "Inactive"); }
private void AddNewBot(Bot newBot) { if (newBot == null) { return; } Bots.Add(newBot); _botRepository.Save(newBot); if (!_connections.Any(c => c.Bot.Id == newBot.Id)) { _connections.Add(new Connection(_socket, newBot)); } SelectBot(newBot); }
private async void AddNewBotAsync() { await RunCommandAsync(() => isBusy, async() => { Directory.CreateDirectory(@"Bots\New" + (Bots.Count + 1)); foreach (var file in Directory.GetFiles(@"openkore\control")) { File.Copy(file, Path.Combine(@"Bots\New" + (Bots.Count + 1), Path.GetFileName(file))); } var newbot = new ContentViewModel("New" + (Bots.Count + 1)); newbot.Content.ViewModel.PropertyChanged += ViewModel_PropertyChanged; Bots.Add(newbot); SelectedIndex = Bots.Count - 1; }); }
public async Task UpdateBot(InventoryBot bot) { await _dao.UpdatePlayerBotAsync(bot); if (bot.RoomId != 0) { Bots.Remove(bot.Id); } else { if (!Bots.ContainsKey(bot.Id)) { Bots.Add(bot.Id, bot); } } }
public void NextGeneration() { Bots.Sort((a, b) => a.Best.CompareTo(b.Best)); var count = Math.Max(1, Math.Min(BestCount, Bots.Count)); var bestBots = Bots.Take(count).ToArray(); Bots.Clear(); var i = 0; while (Bots.Count < TotalCount) { var child = new Bot(_model, _checker.Solve(_model)) { Dna = bestBots[i].Dna, }; // Вероятностная мутация if (_random.Next(100) <= 35) { // Количество ячеек мутации var mutationsCount = _random.Next(1, child.Dna.Length / 8); for (var j = 0; j < mutationsCount; j++) { var k = _random.Next(child.Dna.Length); child.Dna[k] = BotCommandExtension.GetRandomCommand(); } child.IsMutant = true; } Bots.Add(child); if (++i >= bestBots.Length) { i = 0; } } Generation++; }
/// <summary> /// Load given robots, compile, instantiate and initialize /// Sets loaded robots Id's and calls each robots Initialize method /// </summary> /// <param name="botsSource"></param> /// <returns></returns> public bool Load(string[] botsSource) { string currentSourceFile = String.Empty; Bots.Clear(); if (null != Errors) { Errors.Clear(); } try { int botId = 1; foreach (var sourceFile in botsSource) { // Create a unique assembly name so we can pit the same bot class against itself string assemblyName = Path.GetFileNameWithoutExtension(sourceFile) + botId; currentSourceFile = sourceFile; BotAssembly bot = Compile(sourceFile, assemblyName); if (null == bot || null == bot.AssemblyInstance) { return(false); } Ininialize(ref bot, ++botId); Bots.Add(bot); } } catch (Exception ex) { if (null != Errors) { Errors.Add(new CompilerError(currentSourceFile, 0, 0, "0", ex.ToString())); } return(false); } return(true); }
public SimulationEngine(Func <Action, Task> invokeEvent = null) { cyclePerSecondTimer = new Timer(CyclePerSecondTick, null, -1, 1000); Field.Size = new Vector2(1000, 1000); for (var i = 0; i < InitialRobotCount; i++) { var bot = new Bot(invokeEvent) { Position = new Vector2((float)random.NextDouble() * Field.Size.X, (float)random.NextDouble() * Field.Size.Y), Speed = new Vector2(0, 0), DNA = DNASerializer.DeserializeDNA("test-dna.txt"), Orientation = (float)(random.NextDouble() * Math.PI * 2), Color = Color.Red }; botsToAdvertise.Add(bot); Bots.Add(bot); } for (var i = 0; i < InitialRobotCount; i++) { var bot = new Bot(invokeEvent) { Position = new Vector2( (float)random.NextDouble() * Field.Size.X, (float)random.NextDouble() * Field.Size.Y), Speed = new Vector2(0, 0), DNA = DNASerializer.DeserializeDNA("test-dna-2.txt"), Orientation = (float)(random.NextDouble() * Math.PI * 2), Color = Color.Green, IsFixed = true }; botsToAdvertise.Add(bot); Bots.Add(bot); } }
/// <summary> /// Creates the bot. /// </summary> /// <param name="file">The file.</param> private static void CreateBot(string file) { try { Bots.Add(new BotInstance(SettingsManager.LoadSettings(file))); Queue.Remove(file); } catch (InvalidOperationException ex) { LogService.Warning(ex.InnerException == null ? string.Format("[{0}] {1}", Path.GetFileName(file), ex.Message) : string.Format("[{0}] {1}: {2}", Path.GetFileName(file), ex.Message, ex.InnerException.Message)); Queue.Add(file); } catch (IOException ex) { LogService.Warning(string.Format("{0} File will be queued for later reading.", ex.Message)); Queue.Add(file); } catch (Exception ex) { LogService.Warning(ex.ToString()); } }
public void AddBot(Bot bot) { Bots.Add(CreateBoardBot(bot)); }
public async Task AddBot(InventoryBot bot) { await _dao.AddPlayerBotAsync(bot, _player.Id); Bots.Add(bot.Id, bot); }
public void AddBot(VtuberBot bot) { Bots.Add(bot); bot.ReceivedGroupMessageEvent += ReceivedMessageEvent; bot.ReceivedPrivateMessageEvent += ReceivedMessageEvent; }
private IBot _AddBot(BotMode mode, BacktestResultHandle backtestResultHandle = null, IAccount account = null, BacktestResult backtestResult = null, PBot pBot = null, TBot tBot = null, IBot bot = null) { if (account == null) { throw new ArgumentNullException(nameof(account)); } if (backtestResult == null) { backtestResult = backtestResultHandle?.Object; } if (bot == null) { if (pBot != null) { bot = (IBot)pBot.Instantiate(); } else { if (tBot == null) { tBot = backtestResult.TBot; //if (backtestResult == null) { backtestResult = backtestResultHandle?.Object; } //var templateType = ResolveType(backtestResult.BotConfigType); ////var templateType = Type.GetType(result.BotConfigType); //if (templateType == null) //{ // throw new NotSupportedException($"Bot type not supported: {backtestResult.BotConfigType}"); //} //tBot = (TBot)((JObject)backtestResult.Config).ToObject(templateType); } if (tBot == null) { throw new ArgumentNullException(nameof(tBot)); } bot = (IBot)tBot.Create(); } } //bot.Modes = mode | BotMode.Paper; //var botVM = new BotVM() { Bot = bot }; //botVM.State = SupervisorBotState.Scanner; if (bot.Modes.HasFlag(BotMode.Live)) { throw new Exception("Not ready for live yet"); } bot.Account = account; //botVM.AddBacktestResult(backtestResult); //bool hasPaper = mode.HasFlag(BotMode.Paper); //if (mode != BotMode.Paper) //{ // mode = mode & ~BotMode.Paper; //} //if (mode.HasFlag(BotMode.Live)) { LiveBots.Add(bot); Template.LiveBots.Add(tBot.Id); } //if (mode.HasFlag(BotMode.Demo)) { DemoBots.Add(bot); Template.DemoBots.Add(tBot.Id); } //if (mode.HasFlag(BotMode.Scanner)) { Scanners.Add(bot); Template.Scanners.Add(tBot.Id); } //if (mode.HasFlag(BotMode.Paper)) { PaperBots.Add(bot); Template.PaperBots.Add(tBot.Id); } //if (mode.HasFlag(BotMode.Live)) { if (LiveBots == null) { LiveBots = new ObservableCollection<IBot>(); } LiveBots.Add(bot); } //if (mode.HasFlag(BotMode.Demo)) { if (DemoBots == null) { DemoBots = new ObservableCollection<IBot>(); } DemoBots.Add(bot); } if (Bots == null) { Bots = new ObservableCollection <IBot>(); } if (!BotIds.Contains(bot.Template.Id)) { BotIds.Add(bot.Template.Id); Bots.Add(bot); } //if (mode.HasFlag(BotMode.Paper)) { if (PaperBots==null) { PaperBots = new ObservableCollection<IBot>(); } PaperBots.Add(bot); } //if (pBot != null) //{ // bot.DesiredExecutionState = pBot.DesiredExecutionState; //} //switch (mode) //{ // case BotMode.Live: // LiveBots.Add(bot); // break; // case BotMode.Demo: // DemoBots.Add(bot); // break; // case BotMode.Scanner: // Scanners.Add(bot); // break; // case BotMode.Paper: // break; // default: // throw new ArgumentException(nameof(mode)); //} //if (mode.HasFlag(BotMode.Scanner)) //{ // Scanners.Add(bot); //} //if (mode.HasFlag(BotMode.Live)) //{ // LiveBots.Add(bot); //} //if (mode.HasFlag(BotMode.Demo)) //{ // DemoBots.Add(bot); //} //if (mode.HasFlag(BotMode.Paper)) //{ // PaperBots.Add(bot); //} //Task.Factory.StartNew(() => bot.Start()); return(bot); }
/// <summary> /// Creates a bot with the given characteristics. /// </summary> /// <param name="id">The ID of the bot.</param> /// <param name="tier">The initial position (tier).</param> /// <param name="x">The initial position (x-coordinate).</param> /// <param name="y">The initial position (y-coordinate).</param> /// <param name="radius">The radius of the bot.</param> /// <param name="orientation">The initial orientation.</param> /// <param name="podTransferTime">The time for picking up and setting down a pod.</param> /// <param name="maxAcceleration">The maximal acceleration in m/s^2.</param> /// <param name="maxDeceleration">The maximal deceleration in m/s^2.</param> /// <param name="maxVelocity">The maximal velocity in m/s.</param> /// <param name="turnSpeed">The time it takes the bot to take a full turn in s.</param> /// <param name="collisionPenaltyTime">The penalty time for a collision in s.</param> /// <returns>The newly created bot.</returns> public Bot CreateBot(int id, Tier tier, double x, double y, double radius, double orientation, double podTransferTime, double maxAcceleration, double maxDeceleration, double maxVelocity, double turnSpeed, double collisionPenaltyTime, bool createMovableStation = false) { // Consider override values if (SettingConfig.OverrideConfig != null && SettingConfig.OverrideConfig.OverrideBotPodTransferTime) { podTransferTime = SettingConfig.OverrideConfig.OverrideBotPodTransferTimeValue; } if (SettingConfig.OverrideConfig != null && SettingConfig.OverrideConfig.OverrideBotMaxAcceleration) { maxAcceleration = SettingConfig.OverrideConfig.OverrideBotMaxAccelerationValue; } if (SettingConfig.OverrideConfig != null && SettingConfig.OverrideConfig.OverrideBotMaxDeceleration) { maxDeceleration = SettingConfig.OverrideConfig.OverrideBotMaxDecelerationValue; } if (SettingConfig.OverrideConfig != null && SettingConfig.OverrideConfig.OverrideBotMaxVelocity) { maxVelocity = SettingConfig.OverrideConfig.OverrideBotMaxVelocityValue; } if (SettingConfig.OverrideConfig != null && SettingConfig.OverrideConfig.OverrideBotTurnSpeed) { turnSpeed = SettingConfig.OverrideConfig.OverrideBotTurnSpeedValue; } // Init Bot bot = null; MovableStation ms = null; if (createMovableStation) { ms = new MovableStation(id, this, radius, maxAcceleration, maxDeceleration, maxVelocity, turnSpeed, collisionPenaltyTime, x, y); bot = ms; } else { switch (ControllerConfig.PathPlanningConfig.GetMethodType()) { case PathPlanningMethodType.Simple: bot = new BotHazard(this, ControllerConfig.PathPlanningConfig as SimplePathPlanningConfiguration); break; case PathPlanningMethodType.Dummy: case PathPlanningMethodType.WHCAvStar: case PathPlanningMethodType.WHCAnStar: case PathPlanningMethodType.FAR: case PathPlanningMethodType.BCP: case PathPlanningMethodType.OD_ID: case PathPlanningMethodType.CBS: case PathPlanningMethodType.PAS: bot = new BotNormal(id, this, radius, podTransferTime, maxAcceleration, maxDeceleration, maxVelocity, turnSpeed, collisionPenaltyTime, x, y); break; default: throw new ArgumentException("Unknown path planning engine: " + ControllerConfig.PathPlanningConfig.GetMethodType()); } } // Set values bot.ID = id; bot.Tier = tier; bot.Instance = this; bot.Radius = radius; bot.X = x; bot.Y = y; bot.PodTransferTime = podTransferTime; bot.MaxAcceleration = maxAcceleration; bot.MaxDeceleration = maxDeceleration; bot.MaxVelocity = maxVelocity; bot.TurnSpeed = turnSpeed; bot.CollisionPenaltyTime = collisionPenaltyTime; bot.Orientation = orientation; if (bot is BotHazard) { ((BotHazard)bot).EvadeDistance = 2.3 * radius; ((BotHazard)bot).SetTargetOrientation(orientation); } // Add bot if (ms != null) { ms.Capacity = 1000; Bots.Add(ms); //bot was referencing only bot-part of movable station and those values were updated MovableStations.Add(ms); } else { Bots.Add(bot); } tier.AddBot(bot); _idToBots[bot.ID] = bot; // Determine volatile ID int volatileID = 0; while (_volatileBotIDs.Contains(volatileID)) { volatileID++; } bot.VolatileID = volatileID; _volatileBotIDs.Add(bot.VolatileID); // Return it return(bot); }