public async void Run() { var scenario = this.configurationReader.ReadTournament(this.Name); int count; if (int.TryParse(this.gamesCount, out count)) { scenario.GamesCount = count; } var blackInstance = this.configurationReader.ReadBotInstance(scenario.BlackBot); var whiteInstance = this.configurationReader.ReadBotInstance(scenario.WhiteBot); BotKind blackKind = this.configurationReader.ReadBotKind(blackInstance.Kind); BotKind whiteKind = this.configurationReader.ReadBotKind(whiteInstance.Kind); for (var i = 0; i < scenario.GamesCount; i++) { this.taskResult = new TaskCompletionSource <GameResult>(); IGoBot blackBot = this.botFactory.CreateBotInstance(blackKind, blackInstance.Name); IGoBot whiteBot = this.botFactory.CreateBotInstance(whiteKind, whiteInstance.Name); blackBot.BoardSize = scenario.BoardSize; whiteBot.BoardSize = scenario.BoardSize; blackBot.Level = blackInstance.Level; whiteBot.Level = whiteInstance.Level; this.RunBotRunner(blackBot, whiteBot, scenario); this.OutputStatistic(await this.taskResult.Task, blackInstance.Name, whiteInstance.Name); } }
public LiveStatisticsViewModel(IGoBot goBot, IPokestopsHandler pokestopHandler, ICatchPokemonHandler catchPokemonHandler, IEvolvePokemonHandler evolvePokemonHandler, ITransferPokemonHandler transferPokemonHandler) { _goBot = goBot; _pokestopHandler = pokestopHandler; _catchPokemonHandler = catchPokemonHandler; _evolvePokemonHandler = evolvePokemonHandler; _transferPokemonHandler = transferPokemonHandler; _goBot.OnLogin += OnLogin; _pokestopHandler.OnPokestopFound += OnPokestopFound; _pokestopHandler.OnPokestopVisited += OnPokestopVisited; _pokestopHandler.OnExperienceAwarded += OnExperienceAwarded; _catchPokemonHandler.OnExperienceAwarded += OnExperienceAwarded; _evolvePokemonHandler.OnExperienceAwarded += OnExperienceAwarded; _transferPokemonHandler.OnTranfer += OnTransferPokemon; Runtime = "00:00:00"; Level = "#"; Stardust = "#"; Pokemons = "#"; Pokestops = "0/0"; Experience = "#"; _dispatcher = new DispatcherTimer(); _dispatcher.Tick += RunTimeDispatcher; _dispatcher.Interval = new TimeSpan(0, 0, 1); }
public LoginViewModel(ISettingsHandler settingsHandler, IGoBot goBot) { _settingsHandler = settingsHandler; _goBot = goBot; LoginCommand = DelegateCommand.FromAsyncHandler(Login, CanLogin); LoginTypes = new ObservableCollection <LoginType>(new List <LoginType>() { new LoginType() { LoginAuth = LoginAuth.Google }, new LoginType() { LoginAuth = LoginAuth.PCT } }); SelectedLoginType = LoginTypes.FirstOrDefault(t => t.LoginAuth == _settingsHandler.Settings.LoginAuth); UserName = _settingsHandler.Settings.Username; Password = _settingsHandler.Settings.Password; LoginCommand.RaiseCanExecuteChanged(); _dispatcher = new DispatcherTimer(); _dispatcher.Tick += LoginDispatcher; _dispatcher.Interval = new TimeSpan(0, 0, 1); }
public void GoBotFactoryCreateBotInstanceTest() { var injector = new Mock <ISimpleInjectorWrapper>(); var fileService = new Mock <IFileService>(); fileService.Setup(s => s.FileExists("gnugo.exe")).Returns(() => true); fileService.Setup(s => s.PathCombine(It.IsAny <string>(), It.IsAny <string>())).Returns(() => "gnugo.exe"); injector.Setup(s => s.GetInstance <IFileService>()).Returns(() => fileService.Object); var processFactory = new Mock <IProcessManagerFactory>(); processFactory.Setup(s => s.Create(It.IsAny <string>(), It.IsAny <string>())).Returns(() => new Mock <IProcessManager>().Object); var confServ = new Mock <IConfigurationService>(); injector.Setup(s => s.GetInstance <IConfigurationService>()).Returns(() => confServ.Object); injector.Setup(s => s.GetInstance <IProcessManagerFactory>()).Returns(() => processFactory.Object); IGoBotFactory botFactory = new GoBotFactory(injector.Object); BotKind kind = new BotKind { FullClassName = "GoTournament.GnuGoBot", BinaryPath = "bot.exe" }; IGoBot result = botFactory.CreateBotInstance(kind, "superName"); Assert.NotNull(result); Assert.Equal("superName", result.Name); BotKind kind2 = new BotKind { FullClassName = "GoTournament.NotExistedGoBot", BinaryPath = "bot.exe" }; IGoBot result2 = botFactory.CreateBotInstance(kind2, "superName"); Assert.Null(result2); }
public BotRunner(IAdjudicator adjudicator, IGoBot black, IGoBot white) { if (adjudicator == null) { throw new ArgumentNullException(nameof(adjudicator)); } if (black == null) { throw new ArgumentNullException(nameof(black)); } if (white == null) { throw new ArgumentNullException(nameof(white)); } if (ReferenceEquals(black, white)) { throw new ArgumentException("Two instances cannot point to the same object"); } if (black.Name == white.Name) { throw new NotSupportedException("Give unique names to the bot instances. Be creative."); } this.bots = new List <IDisposable> { black, white, adjudicator }; this.EndGame = delegate { }; black.MovePerformed = adjudicator.BlackMoves; white.MovePerformed = adjudicator.WhiteMoves; adjudicator.BlackMoveValidated = white.PlaceMove; adjudicator.WhiteMoveValidated = black.PlaceMove; /* black.MovePerformed = adjudicator.BlackMoves; * white.MovePerformed = adjudicator.WhiteMoves;*/ /* adjudicator.BlackMoveValidated = m => * { * Console.WriteLine("white {0}", m); * white.PlaceMove(m); * }; * adjudicator.WhiteMoveValidated = m => * { * Console.WriteLine("black {0}", m); * black.PlaceMove(m); * };*/ adjudicator.Resigned = stat => { this.EndGame(stat); this.IsFinished = true; }; white.StartGame(false); black.StartGame(true); }
private void RunBotRunner(IGoBot botBlack, IGoBot botWhite, Tournament tourn) { // var finished = false; var sync = new object(); var judge = new Adjudicator(this.simpleInjector, tourn) { BoardUpdated = board => { lock (sync) { // if (!finished) Console.Clear(); Console.WriteLine("------------------------------------------"); foreach (var line in board) { Console.WriteLine(line); } Console.WriteLine("------------------------------------------"); } }, SaveGameResults = true }; // var cancelToken = new CancellationTokenSource(); Task.Run(() => { IBotRunner botRunner = new BotRunner(judge, botBlack, botWhite) { EndGame = stat => { lock (sync) { // finished = true; Console.WriteLine("Bot '{0}' won the game with the score: {1}. Total moves: {2}", stat.WinnerName, stat.FinalScore, stat.TotalMoves); this.taskResult.SetResult(stat); } } }; }); // , cancelToken.Token); /* Console.ReadLine(); * * if (botRunner != null && !botRunner.IsFinished) * { * botRunner.Cancel(); * cancelToken.Cancel(); * Console.WriteLine("Game was canceled"); * } * else Console.WriteLine("Press enter to exit"); * Console.ReadLine();*/ }
public GeneralViewModel(IGoBot goBot, IPlayerPokemonViewModel playerPokemonViewModel, ILiveStatisticsViewModel liveStatisticsViewModel, ILogger logger) { _goBot = goBot; LiveStatisticsViewModel = liveStatisticsViewModel; PlayerPokemonViewModel = playerPokemonViewModel; Logger = logger; StartCommand = DelegateCommand.FromAsyncHandler(StartBot, CanStartBot); StopCommand = new DelegateCommand(StopBot, CanStopBot); StartCommand.RaiseCanExecuteChanged(); }
public PlayerPokemonViewModel(IGoBot goBot, ITransferPokemonHandler transferPokemonHandler, IEvolvePokemonHandler evolvePokemonHandler, ICatchPokemonHandler catchPokemonHandler, ILogger logger) { _goBot = goBot; _transferPokemonHandler = transferPokemonHandler; _evolvePokemonHandler = evolvePokemonHandler; _catchPokemonHandler = catchPokemonHandler; _logger = logger; _goBot.OnLogin += GetPlayerPokemons; _transferPokemonHandler.OnTranfer += TransferedPokemon; _catchPokemonHandler.OnCatch += CatchedPokemon; _evolvePokemonHandler.OnEvolve += EvolvedPokemon; }
public void GnuGoBotCtorTest() { IGoBot bot = null; try { bot = new GnuGoBot(null, null, null); Assert.True(false, "Should fail on previous statement"); } catch (Exception ex) { Assert.IsType(typeof(ArgumentNullException), ex); Assert.Equal("Value cannot be null.\r\nParameter name: simpleInjector", ex.Message); } var injector = new Mock <ISimpleInjectorWrapper>(); try { bot = new GnuGoBot(injector.Object, null, null); Assert.True(false, "Should fail on previous statement"); } catch (Exception ex) { Assert.IsType(typeof(ArgumentNullException), ex); Assert.Equal("Value cannot be null.\r\nParameter name: binaryPath", ex.Message); } try { bot = new GnuGoBot(injector.Object, "bot.exe", null); Assert.True(false, "Should fail on previous statement"); } catch (Exception ex) { Assert.IsType(typeof(ArgumentNullException), ex); Assert.Equal("Value cannot be null.\r\nParameter name: botInstanceName", ex.Message); } var fileService = new Mock <IFileService>(); fileService.Setup(s => s.FileExists("bot.exe")).Returns(() => true); fileService.Setup(s => s.PathCombine(It.IsAny <string>(), "noFile")).Returns(() => "noFile"); fileService.Setup(s => s.PathCombine(It.IsAny <string>(), "bot.exe")).Returns(() => "bot.exe"); injector.Setup(s => s.GetInstance <IFileService>()).Returns(() => fileService.Object); var processFactory = new Mock <IProcessManagerFactory>(); processFactory.Setup(s => s.Create(It.IsAny <string>(), It.IsAny <string>())) .Returns(() => new Mock <IProcessManager>().Object); injector.Setup(s => s.GetInstance <IProcessManagerFactory>()).Returns(() => processFactory.Object); var confServ = new Mock <IConfigurationService>(); injector.Setup(s => s.GetInstance <IConfigurationService>()).Returns(() => confServ.Object); bot = new GnuGoBot(injector.Object, "bot.exe", "Goodman"); Assert.NotNull(bot); Assert.NotNull(bot.MovePerformed); fileService.Setup(s => s.FileExists("noFile")).Returns(() => false); try { bot = new GnuGoBot(injector.Object, "noFile", "BotName"); Assert.True(false, "Should fail on previous statement"); } catch (Exception ex) { Assert.IsType(typeof(FileNotFoundException), ex); Assert.Equal("Bot binary not found,", ex.Message); } }