public void Init() { if (_floorItems.Count > 0) { _floorItems.Clear(); } if (_wallItems.Count > 0) { _wallItems.Clear(); } if (_petsItems.Count > 0) { _petsItems.Clear(); } if (_botItems.Count > 0) { _botItems.Clear(); } var items = ItemLoader.GetItemsForUser(_userId); foreach (var item in items.ToList()) { if (item.IsFloorItem) { if (!_floorItems.TryAdd(item.Id, item)) { } } else if (item.IsWallItem) { if (!_wallItems.TryAdd(item.Id, item)) { } } } var pets = PetLoader.GetPetsForUser(Convert.ToInt32(_userId)); foreach (var pet in pets) { if (!_petsItems.TryAdd(pet.PetId, pet)) { Console.WriteLine("Error whilst loading pet x1: " + pet.PetId); } } var bots = BotLoader.GetBotsForUser(Convert.ToInt32(_userId)); foreach (var bot in bots) { if (!_botItems.TryAdd(bot.Id, bot)) { Console.WriteLine("Error whilst loading bot x1: " + bot.Id); } } }
/// <summary> /// Robot gallery window. /// </summary> void RobotGalleryWindow(int windowID) { // back button and refresh button GUILayout.BeginHorizontal(); if (GUILayout.Button("<", GUILayout.Width(30f))) { _windows.Pop(); } if (GUILayout.Button("R", GUILayout.Width(30f))) { BotLoader.SearchForRobots(); } GUILayout.Label("Robot Gallery"); GUILayout.EndHorizontal(); // gallery goes here... for (int i = 0; i < BotLoader.robotsFound.Count; i++) { if (GUILayout.Button(BotLoader.robotsFound[i].name)) { settings.robotName = BotLoader.robotsFound[i].name; _windows.Pop(); } } GUILayout.Space(10); // start robot creator GUILayout.Button("Create new robot..."); GUI.DragWindow(); }
static void Main(string[] args) { /* * JobFactory jobFactory = new JobFactory(); * IInventoryContent inventory = new Inventory(); * inventory.Items.Add(new SmallHealthPotion()); * inventory.Items.Add(new SmallManaPotion()); * * Character character1 = new Character( * "Character 2", * new Health(100, 100), * new Mana(80, 80), * inventory); * * IGameController game = new Game(character1, null); * * IBot bot = new BotSean(); * character1.ActualJob = bot.ChooseJob(jobFactory) as JobBase; * bot.DoTurn(game); */ BotLoader botLoader = new BotLoader(); MainSimulator simulator = new MainSimulator(botLoader.LoadBots(), new FullSimulationRunner(), new JobFactory()); simulator.Simulate(); }
private async Task DoStart() { if (GameStatus == GameStatus.Finished) { gameService.StopGame(); GameProgress.Clear(); DebugMessages.Clear(); } GameStatus = GameStatus.Unloaded; if (string.IsNullOrWhiteSpace(DllPathInput)) { await NotificationService.Show(Captions.PvB_ErrorMsg_NoDllPath, Captions.ND_OkButtonCaption); return; } if (!File.Exists(DllPathInput)) { await NotificationService.Show($"{Captions.PvB_ErrorMsg_FileDoesNotExist} [{DllPathInput}]", Captions.ND_OkButtonCaption); return; } Assembly dllToLoad; try { dllToLoad = Assembly.LoadFile(DllPathInput); } catch { await NotificationService.Show($"{Captions.PvB_ErrorMsg_FileIsNoAssembly} [{DllPathInput}]", Captions.ND_OkButtonCaption); return; } var uninitializedBotAndBotName = BotLoader.LoadBot(dllToLoad); if (uninitializedBotAndBotName == null) { await NotificationService.Show($"{Captions.PvB_ErrorMsg_BotCanNotBeLoadedFromAsembly} [{dllToLoad.FullName}]", Captions.ND_OkButtonCaption); return; } MovesLeft = (Constants.GameConstraint.MaximalMovesPerGame + 1).ToString(); applicationSettingsRepository.LastUsedBotPath = DllPathInput; gameService.CreateGame(uninitializedBotAndBotName.Item1, uninitializedBotAndBotName.Item2, new GameConstraints(TimeSpan.FromSeconds(Constants.GameConstraint.BotThinkingTimeSeconds), Constants.GameConstraint.MaximalMovesPerGame)); ((Command)Capitulate).RaiseCanExecuteChanged(); }
private void startButton_Click(object sender, EventArgs e) { if (this.memory != null && this.memory.isUseable()) { String currentSelecteWaypointName = (string)this.loadWaypointCombobox.SelectedItem; String currentSelecteConfigName = (string)this.loadConfigCombobox.SelectedItem; if (currentSelecteWaypointName != null && currentSelecteWaypointName.Length > 0 && currentSelecteConfigName != null && currentSelecteConfigName.Length > 0) { if (this.bot == null) { this.bot = BotLoader.loadBotModule(currentSelecteConfigName, currentSelecteWaypointName); if (this.bot != null) { SetForegroundWindow(this.memory.processMainWindowHandle()); this.bot.setCoreObjects(this.memory); this.bot.run(); } } else { this.bot.stop(); this.bot = null; } } } }
static void Main(string[] args) { Console.WriteLine("Welcome to LUCKY ROULETTE!"); Console.WriteLine(""); if (args.Length != 1) { Console.WriteLine("Incorrect amount of parameters. Only one needed."); return; } List <Type> bots = new BotLoader().FindBots(args[0], typeof(Bot)); if (bots == null) { return; } RouletteTable tableOne = new RouletteTable(); for (int x = 0; x < bots.Count; x++) { object[] parameters = { bots[x].Name, 1000 }; tableOne.AddPlayer((Player)Activator.CreateInstance(bots[x], parameters)); } for (int x = 0; x < 40; x++) { tableOne.Spin(); } Console.WriteLine(""); tableOne.ShowInfoAboutPlayers(); }
//IntPtr handle = static void Main(string[] args) { BotLoader.AddSearchPath("../../../UltraBot/Bots/"); var KenBot = BotLoader.LoadBotFromFile("KenBot"); KenBot.Init(0); Util.Init(); DX9Overlay.SetParam("process", "SSFIV.exe"); DX9Overlay.DestroyAllVisual(); TextLabel roundTimer = new TextLabel("Consolas", 10, TypeFace.NONE, new Point(390, 0), Color.White, "", true, true); TextLabel player1 = new TextLabel("Consolas", 10, TypeFace.NONE, new Point(90, 0), Color.White, "", true, true); TextLabel player2 = new TextLabel("Consolas", 10, TypeFace.NONE, new Point(480, 0), Color.White, "", true, true); //Stopwatch sw = new Stopwatch(); // Do something you want to time var ms = MatchState.getInstance(); var f1 = FighterState.getFighter(0); var f2 = FighterState.getFighter(1); KenBot.Init(0); while (true) { ms.Update(); roundTimer.Text = String.Format("Frame:{0}", ms.FrameCounter); UpdateOverlay(player1, f1); UpdateOverlay(player2, f2); KenBot.Run(); } }
public void FindBotTest() { List <Type> bots = new BotLoader().FindBots("../../../Dll", typeof(Bot)); Assert.AreEqual(bots.Count, 3); Assert.AreEqual(bots[0], typeof(BotDAlembert)); Assert.AreEqual(bots[1], typeof(BotLabouchere)); Assert.AreEqual(bots[2], typeof(BotMartingale)); }
public void LoadLibraryTest() { BotLoader.LoadBots("../../../../Bots.dll", 500); Assert.AreEqual(0, BotLoader.Bots.Count); BotLoader.LoadBots("../../../../Bots/Bots.dll", 500); Assert.AreEqual(3, BotLoader.Bots.Count); Assert.Pass(); }
/// <summary> /// Randomly select simulation parameters. /// </summary> public void Randomize() { title = "Random Settings"; numberOfTests = 3; environmentName = EnvLoader.RandomEnvironmentName(); robotName = BotLoader.RandomRobotName(); navigationAssemblyName = NavLoader.RandomPluginName(); randomizeDestination = true; continueOnNavObjectiveComplete = true; continueOnRobotIsStuck = true; }
static void Main(string[] args) { XmlConfigurator.Configure(); var botComponents = new List <BotComponent>() { new ConnectorComponent(Configs.Login, Configs.Password), new SearchResultsScannerComponent(Configs.BaseDir, Configs.LinksFileName, Configs.ResultsFileName, Configs.GetConfig().SearchLinks.ToRun), new UserProfileScannerComponent(Configs.BaseDir, Configs.ProfilePhotosCount, Configs.GalleryPhotosCount, Configs.PostsCount, Configs.ResultsFileName, Configs.LoadFromSavedResults) }; BotLoader loader = new BotLoader(botComponents, typeof(ChromeDriver), Configs.BaseDir); loader.Start(); }
public static void Main(string[] args) { Console.WriteLine("This program is a blackjack game using bots from a library."); Console.WriteLine("Loading bots..."); int sum = 500; Game game = new Game(); game.Players = BotLoader.LoadBots("../../../../Bots/Bots.dll", sum); Console.WriteLine(game.Players.Count + " bots were found in the libary.\n"); Console.WriteLine("The game starts here."); game.PlayGame(sum); }
private void BotSelector_SelectionChanged(object sender, SelectionChangedEventArgs e) { StatusLabel.Content = "Loading " + (string)BotSelector.SelectedValue + "..."; //try { bot = BotLoader.LoadBotFromFile((string)BotSelector.SelectedValue); bot.Init(P1CheckBox.IsChecked.Value ? 0 : 1); BotSelector.Items.Refresh(); RefreshBotData(); } //catch(Exception err) { //StatusLabel.Content = err.ToString(); //throw err; } }
private void LoadBots() { BotEntries.Clear(); foreach (var searchDir in SEARCH_PATH) { FileSystemWatcher watcher = new FileSystemWatcher(); watcher.Path = searchDir; watcher.NotifyFilter = NotifyFilters.LastWrite; watcher.Filter = "*.*"; watcher.Changed += new FileSystemEventHandler(FolderOnChanged); watcher.EnableRaisingEvents = true; BotLoader.AddSearchPath(searchDir); foreach (var botfile in Directory.EnumerateFiles(searchDir, "*.cs")) { BotEntries.Add(Path.GetFileNameWithoutExtension(botfile)); } } BotSelector.ItemsSource = BotEntries; BotSelector.SelectedIndex = 0; }
/// <summary> /// Halt current simulation. /// Load the next simulation in batch, or /// change state to State.end if at the end of batch. /// </summary> public static void NextSimulation() { // stop current simulation if (state == State.simulating) { Halt(StopCode.Unspecified); } // next in batch simulationNumber++; if (simulationNumber > batch.Count) { // end of batch Halt(StopCode.Unspecified); End(); return; } Debug.Log("Simulation NextSimulation: " + simulationNumber + " of " + batch.Count); // load simulation settings settings = batch[simulationNumber - 1]; Log.Settings(); // load environment EnvLoader.SearchForEnvironments(); environment = EnvLoader.LoadEnvironment(settings.environmentName); destination.transform.position = RandomInBounds(Instance.bounds); // load robot if (robot) { CamController.RemoveAreaOfInterest(robot); } BotLoader.SearchForRobots(); robot = BotLoader.LoadRobot(settings.robotName); robot.navigation = NavLoader.LoadPlugin(settings.navigationAssemblyName); // configure camera CamController.AddAreaOfInterest(robot); CamController.SetViewMode(CamController.ViewMode.Birdseye); CamController.SetAreaOfInterest(robot); // reset test number testNumber = 0; NextTest(); }
public void Init() { if (this._floorItems.Count > 0) { this._floorItems.Clear(); } if (this._wallItems.Count > 0) { this._wallItems.Clear(); } if (this._petsItems.Count > 0) { this._petsItems.Clear(); } if (this._botItems.Count > 0) { this._botItems.Clear(); } List <Item> Items = ItemLoader.GetItemsForUser(_userId); foreach (Item Item in Items.ToList()) { if (Item.IsFloorItem) { if (!this._floorItems.TryAdd(Item.Id, Item)) { continue; } } else if (Item.IsWallItem) { if (!this._wallItems.TryAdd(Item.Id, Item)) { continue; } } else { continue; } } List <Pet> Pets = PetLoader.GetPetsForUser(Convert.ToInt32(_userId)); foreach (Pet Pet in Pets) { if (!this._petsItems.TryAdd(Pet.PetId, Pet)) { Console.WriteLine("Error whilst loading pet x1: " + Pet.PetId); } } List <Bot> Bots = BotLoader.GetBotsForUser(Convert.ToInt32(_userId)); foreach (Bot Bot in Bots) { if (!this._botItems.TryAdd(Bot.Id, Bot)) { Console.WriteLine("Error whilst loading bot x1: " + Bot.Id); } } }
private async Task DoStartWithProgress(string filePath) { if (GameStatus == GameStatus.Finished) { gameService.StopGame(); GameProgress.Clear(); DebugMessages.Clear(); } GameStatus = GameStatus.Unloaded; if (string.IsNullOrWhiteSpace(DllPathInput)) { await NotificationService.Show(Captions.PvB_ErrorMsg_NoDllPath, Captions.ND_OkButtonCaption); return; } if (!File.Exists(DllPathInput)) { await NotificationService.Show($"{Captions.PvB_ErrorMsg_FileDoesNotExist} [{DllPathInput}]", Captions.ND_OkButtonCaption); return; } Assembly dllToLoad; try { dllToLoad = Assembly.LoadFile(DllPathInput); } catch { await NotificationService.Show($"{Captions.PvB_ErrorMsg_FileIsNoAssembly} [{DllPathInput}]", Captions.ND_OkButtonCaption); return; } var uninitializedBotAndBotName = BotLoader.LoadBot(dllToLoad); if (uninitializedBotAndBotName == null) { await NotificationService.Show($"{Captions.PvB_ErrorMsg_BotCanNotBeLoadedFromAsembly} [{dllToLoad.FullName}]", Captions.ND_OkButtonCaption); return; } var progressFilePath = string.Empty; if (string.IsNullOrWhiteSpace(filePath)) { var dialog = new OpenFileDialog { Filter = "text-file|*.txt" }; var result = dialog.ShowDialog(); if (result.HasValue) { if (result.Value) { progressFilePath = dialog.FileName; } } } else { progressFilePath = filePath; } var progressText = File.ReadAllText(progressFilePath); var fileVerifier = progressFileVerifierFactory.CreateVerifier(); var verificationResult = fileVerifier.Verify(progressText, Constants.GameConstraint.MaximalMovesPerGame); switch (verificationResult) { case FileVerificationResult.EmptyOrInvalidFile: { await NotificationService.Show($"{Captions.PvB_ErrorMsg_ProgressFileCannotBeLoaded} [{progressFilePath}]" + $"\n\n{Captions.PvB_ErrorMsg_Reason}:" + $"\n{Captions.FVR_EmptyOrInvalidFile}", Captions.ND_OkButtonCaption); return; } case FileVerificationResult.FileContainsInvalidMove: { await NotificationService.Show($"{Captions.PvB_ErrorMsg_ProgressFileCannotBeLoaded} [{progressFilePath}]" + $"\n\n{Captions.PvB_ErrorMsg_Reason}:" + $"\n{Captions.FVR_FileContainsInvalidMove}", Captions.ND_OkButtonCaption); return; } case FileVerificationResult.FileContainsTerminatedGame: { await NotificationService.Show($"{Captions.PvB_ErrorMsg_ProgressFileCannotBeLoaded} [{progressFilePath}]" + $"\n\n{Captions.PvB_ErrorMsg_Reason}:" + $"\n{Captions.FVR_FileContainsTerminatedGame}", Captions.ND_OkButtonCaption); return; } case FileVerificationResult.FileContainsMoreMovesThanAllowed: { await NotificationService.Show($"{Captions.PvB_ErrorMsg_ProgressFileCannotBeLoaded} [{progressFilePath}]" + $"\n\n{Captions.PvB_ErrorMsg_Reason}:" + $"\n{Captions.FVR_FileContainsMoreMovesThanAllowed}", Captions.ND_OkButtonCaption); return; } case FileVerificationResult.ValidFile: { applicationSettingsRepository.LastUsedBotPath = DllPathInput; MovesLeft = (Constants.GameConstraint.MaximalMovesPerGame + 1).ToString(); gameService.CreateGame(uninitializedBotAndBotName.Item1, uninitializedBotAndBotName.Item2, new GameConstraints(TimeSpan.FromSeconds(Constants.GameConstraint.BotThinkingTimeSeconds), Constants.GameConstraint.MaximalMovesPerGame), progressText); ((Command)Capitulate).RaiseCanExecuteChanged(); return; } } }
/// <summary> /// Edit Simulation.Settings window function (always top of _windows stack) /// </summary> /// <param name="windowID">Window ID.</param> void SimulationSettingsWindow(int windowID) { GUILayout.BeginHorizontal(); if (!_settings.active) { // if this settings is already batched if (Simulation.batch.Contains(_settings)) { // button to remove from batch if (GUILayout.Button("Remove from batch")) { Simulation.batch.Remove(_settings); _windows.Pop(); return; } // cancel button if (GUILayout.Button("Close window")) { _windows.Pop(); return; } } // this settings isn't in the batch else { // button to add valid settings to batch if (_settings.isValid) { if (GUILayout.Button("Add to batch")) { Simulation.batch.Add(_settings); _windows.Pop(); return; } } // cancel button if (GUILayout.Button("Cancel")) { _windows.Pop(); return; } } } else { GUILayout.Button("Simulation running!"); if (GUILayout.Button("Close")) { _windows.Pop(); return; } } GUILayout.EndHorizontal(); float lw = 200f; // copy settings for UI string title = settings.title; string robotName = settings.robotName; string environmentName = settings.environmentName; string navigationAssemblyName = settings.navigationAssemblyName; string numberOfTests = settings.numberOfTests.ToString(); string testTime = settings.maximumTestTime.ToString(); bool randomDest = settings.randomizeDestination; bool randomStart = settings.randomizeOrigin; bool repeatOnComplete = settings.continueOnNavObjectiveComplete; bool repeatOnStuck = settings.continueOnRobotIsStuck; // if settings is in use by Simulation if (settings.active) { // display only GUILayout.Label(settings.title + "\n" + settings.robotName + "\n" + settings.environmentName + "\n" + settings.navigationAssemblyName); } else { // provide controls for editing // edit title GUILayout.BeginHorizontal(); GUILayout.Label("Title", GUILayout.Width(lw)); title = GUILayout.TextField(title); GUILayout.EndHorizontal(); // edit number of tests GUILayout.BeginHorizontal(); GUILayout.Label("Number of tests: ", GUILayout.Width(lw)); numberOfTests = GUILayout.TextField(numberOfTests); GUILayout.EndHorizontal(); // change the robot GUILayout.BeginHorizontal(); GUILayout.Label("Robot selection: ", GUILayout.Width(lw)); if (GUILayout.Button(robotName)) { BotLoader.SearchForRobots(); _windows.Push(RobotGalleryWindow); } GUILayout.EndHorizontal(); // change the environment GUILayout.BeginHorizontal(); GUILayout.Label("Environment selection: ", GUILayout.Width(lw)); if (GUILayout.Button(environmentName)) { EnvLoader.SearchForEnvironments(); _windows.Push(EnvironmentGalleryWindow); } GUILayout.EndHorizontal(); // change the navigation assembly GUILayout.BeginHorizontal(); GUILayout.Label("Algorithm selection: ", GUILayout.Width(lw)); if (GUILayout.Button(navigationAssemblyName)) { NavLoader.SearchForPlugins(); _windows.Push(NavListWindow); } GUILayout.EndHorizontal(); } // toggle random start position GUILayout.BeginHorizontal(); GUILayout.Label("Randomize Start: ", GUILayout.Width(lw)); randomStart = GUILayout.Toggle(randomStart, ""); GUILayout.EndHorizontal(); // toggle random destination position GUILayout.BeginHorizontal(); GUILayout.Label("Randomize Destination: ", GUILayout.Width(lw)); randomDest = GUILayout.Toggle(randomDest, ""); GUILayout.EndHorizontal(); // if settings is in use by Simulation if (settings.active) { // display time remaining and edit maximum test time GUILayout.BeginHorizontal(); GUILayout.Label("Time (s): " + Simulation.time.ToString("G2"), GUILayout.Width(lw)); testTime = GUILayout.TextField(testTime); GUILayout.EndHorizontal(); } else { // edit maximum test time GUILayout.BeginHorizontal(); GUILayout.Label("Maximum Simulation Time (s): ", GUILayout.Width(lw)); testTime = GUILayout.TextField(testTime); GUILayout.EndHorizontal(); } // edit toggle for automatically starting a new test GUILayout.BeginHorizontal(); GUILayout.Label("Repeat on complete: ", GUILayout.Width(lw)); repeatOnComplete = GUILayout.Toggle(repeatOnComplete, ""); GUILayout.EndHorizontal(); // edit toggle for stuck detection GUILayout.BeginHorizontal(); GUILayout.Label("Repeat on stuck: ", GUILayout.Width(lw)); repeatOnStuck = GUILayout.Toggle(repeatOnStuck, ""); GUILayout.EndHorizontal(); // check for valid data input before copying back to settings object bool valid = true; foreach (char c in Strings.invalidFileNameChars) { if (title.Contains(c.ToString())) { valid = false; } } if (valid) { settings.title = title; } if (Strings.IsDigitsOnly(numberOfTests)) { try { settings.numberOfTests = Convert.ToInt32(numberOfTests); } catch { Debug.Log("User should enter a number..."); } } if (Strings.IsDigitsOnly(testTime)) { try { settings.maximumTestTime = Convert.ToInt32(testTime); } catch { Debug.Log("User should enter a number..."); } } // copy valid data back to settings settings.robotName = robotName; settings.environmentName = environmentName; settings.navigationAssemblyName = navigationAssemblyName; settings.randomizeDestination = randomDest; settings.randomizeOrigin = randomStart; settings.continueOnNavObjectiveComplete = repeatOnComplete; settings.continueOnRobotIsStuck = repeatOnStuck; GUI.DragWindow(); }