public static string ToHumanReadableString(this BotStrategy strategy) { switch (strategy) { case RsiBotStrategy rsiBotStrategy: return($"RSI {rsiBotStrategy.Options.Time.ToHumanReadableString()} {rsiBotStrategy.Options.Points}"); case ManualStrategy manualStrategy: return("Manual"); case QflBotStrategy qflBotStrategy: return($"QFL {qflBotStrategy.Options.Type} {qflBotStrategy.Options.Percent}%"); case NonStopBotStrategy nonStopBotStrategy: return("NonStop"); case UltBotStrategy ultBotStrategy: return($"ULT {ultBotStrategy.Options.Time.ToHumanReadableString()} {ultBotStrategy.Options.Points}"); case TradingViewBotStrategy tradingViewBotStrategy: return($"TradingView {tradingViewBotStrategy.Options.Type} {tradingViewBotStrategy.Options.Time.ToHumanReadableString()}"); case TaPresetsBotStrategy taPresetsBotStrategy: return($"{taPresetsBotStrategy.Name} {taPresetsBotStrategy.Options.Type} {taPresetsBotStrategy.Options.Time.ToHumanReadableString()}"); case CqsPremiumBotStrategy cqsPremiumBotStrategy: case CqsTelegramBotStrategy cqsTelegramBotStrategy: case UnknownStrategy unknownStrategy: return(strategy.Name); default: throw new ArgumentOutOfRangeException(nameof(strategy)); } }
public void ExchangeRateObserver_Update_DoesNotUpdateBotCommandStrategy(string observerTestBotCommand) { // Arrange IBotStrategy expectedBotCommandStrategy = null; // Initialize test CommandStrategy for ExchangeRateObserver var testExchangeRateCommand = new ObserverTestCommand { CommandType = CommandType.ExchangeRate }; IEnumerable <ICommand> commands = new List <ICommand>() { testExchangeRateCommand }; var commandStrategy = new BotStrategy(commands); // Initialize the test bot var exchangeRateObserver = new ExchangeRateObserver(commandStrategy); var testBot = new ObserverTestBot(observerTestBotCommand, exchangeRateObserver); // Act testBot.Run(); var actualBotCommandStrategy = testBot.Strategy; //Assert Assert.AreEqual(actualBotCommandStrategy, expectedBotCommandStrategy); }
public void GivenExistingMatch_WhenDynamiteAvailableInTheGameAndAlreadyUsedByBot_ThenBotsMoveShouldBeOfOneThatBeatsPlayersPreviousHand() { // Assemble var botStrategy = new BotStrategy(); var strategyMock = new Mock <IBotStrategy>(); var sequence = strategyMock.SetupSequence(m => m.GetBotsNextMove(It.IsAny <Game>(), It.IsAny <bool>(), It.IsAny <bool>())); IMatchService service = new MatchService(strategyMock.Object); service.NewMatch(3, 1); Move playersMove = Move.Waterbomb; //Act //first game sequence.Returns(Move.Dynamite); service.AddGame(); var botsFirstMove = service.BotsMove(); var gameResult = service.GameResult(Outcome.Lose, playersMove); //second game sequence.Returns(botStrategy.GetBotsNextMove(gameResult, false, true)); service.AddGame(); var botsSecondMove = service.BotsMove(); MoveHelpers mh = new MoveHelpers(); var beaters = mh.GetBeaters(playersMove).ToList(); //Assert Assert.Contains(botsSecondMove, beaters); }
public void GivenExistingMatch_WhenPreviousGameWonAndNoDynamitesAvailableInTheGame_ThenBotsMoveShouldBeOfOneThatBeatsItsPreviousHandWithNoDynamitAndNoWaterbomb() { // Assemble var botStrategy = new BotStrategy(); IMatchService service = new MatchService(botStrategy); service.NewMatch(3, 0); //Act //first game service.AddGame(); var botsFirstMove = service.BotsMove(); service.GameResult(Outcome.Win, Move.Paper); //second game service.AddGame(); var botsSecondMove = service.BotsMove(); MoveHelpers mh = new MoveHelpers(); var beaters = mh.GetBeaters(botsFirstMove).ToList(); //Assert Assert.AreNotEqual(Move.Dynamite, botsSecondMove); Assert.AreNotEqual(Move.Waterbomb, botsSecondMove); Assert.Contains(botsSecondMove, beaters); }
public Game Move(Game game, Cell cell) { string step = game.NextStep == NextStep.PlayerFirst ? $"Player" : "Bot"; if (game.NextStep == NextStep.PlayerFirst) { Move(game, cell.number); } else { if (game.PrevLocation == 0) { _botStrategy = new RandomShot(); game.PrevLocation = _botStrategy.Shot(0); Move(game, game.PrevLocation); } else { _botStrategy = new ShotTheTarget(); game.PrevLocation = _botStrategy.Shot(game.PrevLocation); Move(game, game.PrevLocation); } } if (game.NextStep == NextStep.PlayerSecond) { Move(game, cell); } return(game); }
public void GivenNewMatch_WhenMoreDynamitesThanGames_ThenExceptionIsThrown() { // Assemble var botStrategy = new BotStrategy(); IMatchService service = new MatchService(botStrategy); // Act + Assert Assert.Throws <InvalidNumberOfDynamitesException>(() => service.NewMatch(4, 5)); }
public void GivenNewMatch_WhenNegativeNumberOfGamesSpecified_ThenExceptionIsThrown() { // Assemble var botStrategy = new BotStrategy(); IMatchService service = new MatchService(botStrategy); // Act + Assert Assert.Throws <InvalidNumberOfGamesException>(() => service.NewMatch(-34, 0)); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { var botStrategy = new BotStrategy(); services.AddSingleton(typeof(IMatchService), new MatchService(botStrategy)); services.AddControllers(); services.AddSwaggerGen(); }
private void okButton_Click(object sender, EventArgs e) { if (radioButtonRsi.Checked) { if (cmbRsiTime.SelectedItem == null) { MessageBox.Show("Time is missing"); return; } IndicatorTime.TryParse(cmbRsiTime.SelectedItem.ToString(), out IndicatorTime time); _strategy = new RsiBotStrategy() { Options = new RsiOptions(time, (int)numRsiPoints.Value) }; } if (radioButtonTradingView.Checked) { if (cmbTradingViewTime.SelectedItem == null) { MessageBox.Show("Time is missing"); return; } if (cmbTradingViewType.SelectedItem == null) { MessageBox.Show("Type is missing"); return; } TradingViewTime.TryParse(cmbTradingViewTime.SelectedItem.ToString(), out TradingViewTime time); TradingViewIndicatorType.TryParse(cmbTradingViewType.SelectedItem.ToString(), out TradingViewIndicatorType type); _strategy = new TradingViewBotStrategy() { Options = new TradingViewOptions(type, time) }; } if (radioButtonManual.Checked) { _strategy = new ManualStrategy(); } if (radioButtonNonstop.Checked) { _strategy = new NonStopBotStrategy(); } this.DialogResult = DialogResult.OK; }
public void GivenNewMatch_WhenFirstGameAndDynamitesAvailableInTheGame_ThenBotsMoveShouldBeMadeAccordingly() { // Assemble var botStrategy = new BotStrategy(); IMatchService service = new MatchService(botStrategy); service.NewMatch(3, 0); //Act service.AddGame(); var botsDecision = service.BotsMove(); //Assert Assert.That(Enum.IsDefined(typeof(Move), botsDecision)); Assert.Contains(botsDecision, Enum.GetValues(typeof(Move)).Cast <Move>().ToList()); }
public void GivenNewMatch_WhenFirstGameAndNoDynamitesAvailableInTheGame_ThenBotsMoveShouldBeMadeWithNoDynamiteAndNoWaterbomb() { // Assemble var botStrategy = new BotStrategy(); IMatchService service = new MatchService(botStrategy); service.NewMatch(3, 0); //Act service.AddGame(); var botsDecision = service.BotsMove(); //Assert Assert.AreNotEqual(Move.Dynamite, botsDecision); Assert.AreNotEqual(Move.Waterbomb, botsDecision); }
public override async Task RunAsync(string parameters, CancellationToken cancellationToken) { if (string.IsNullOrWhiteSpace(parameters)) { // Show the current strategy var allValues = Enum.GetValues(typeof(BotStrategy)) as BotStrategy[]; var values = allValues.Where(v => Program.Settings.Strategy.Value.HasFlag(v)); this.Logger?.LogCommandOutput($"The strategy is set to: {{value}}{string.Join(", ", values.Select(v => v.ToString()))}{{reset}}."); this.Logger?.LogCommandOutput($"You can change the strategy by appending any combination of the strategies to this command: {{command}}strategy {{param}}<strategy>{{reset}}"); this.Logger?.LogCommandOutput($"where {{param}}<strategy>{{reset}} is replaced with a list of strategies, seperated by either spaces or commas."); this.Logger?.LogCommandOutput(""); this.Logger?.LogCommandOutput($"Keep in mind that some strategies are incompatible with each other."); this.Logger?.LogCommandOutput($"If this happens, the first in the defined list below will take priority."); this.Logger?.LogCommandOutput($"Possible strategies are:"); this.Logger?.LogCommandOutput($" {string.Join($"{Environment.NewLine} ", allValues.Select(v => $"{{value}}{v}{{reset}}"))}"); } else { // Set the strategy string[] strategies = parameters.Split(new[] { ' ', ',' }, StringSplitOptions.RemoveEmptyEntries); try { var strategyValues = strategies.Select(s => (BotStrategy)Enum.Parse(typeof(BotStrategy), s)); BotStrategy strategy = strategyValues.Aggregate((BotStrategy)0, (a, b) => a | b); if (strategy == 0) { strategy = BotStrategy.FocusBosses | BotStrategy.MostDifficultPlanetsFirst | BotStrategy.MostCompletedPlanetsFirst | BotStrategy.MostDifficultZonesFirst | BotStrategy.LeastCompletedZonesFirst | BotStrategy.TopDown; } Program.Settings.Strategy.Value = strategy; this.Logger?.LogCommandOutput("Your strategy has been saved."); } catch (ArgumentException) { this.Logger?.LogCommandOutput("{err}Invalid input."); } } }
public void ExchangeRateObserver_Update_UpdatesBotCommandStrategy() { // Arrange var expectedCommandStrategyIsNull = false; var expectedCommandType = CommandType.ExchangeRate; // Initialize test CommandStrategy for ExchangeRateObserver var testExchangeRateCommand = new ObserverTestCommand { CommandType = CommandType.ExchangeRate }; IEnumerable <ICommand> commands = new List <ICommand>() { testExchangeRateCommand }; var commandStrategy = new BotStrategy(commands); // Initialize the test bot var exchangeRateObserver = new ExchangeRateObserver(commandStrategy); var testBot = new ObserverTestBot("/EXCHANGERATE", exchangeRateObserver); // Act testBot.Run(); var actualCommandStrategyIsNull = testBot.Strategy == null; CommandType?actualCommandType = null; if (actualCommandStrategyIsNull == false) { actualCommandType = testBot.Strategy.CommandType; } //Assert Assert.AreEqual(actualCommandStrategyIsNull, expectedCommandStrategyIsNull); if (actualCommandStrategyIsNull == false) { Assert.AreEqual(actualCommandType, expectedCommandType); } }
public void HelpObserver_Update_UpdatesBotCommandStrategy() { // Arrange var expectedCommandStrategyIsNull = false; var expectedCommandType = CommandType.Help; // Initialize test CommandStrategy for NowObserver var testHelpCommand = new ObserverTestCommand { CommandType = CommandType.Help }; IEnumerable <ICommand> commands = new List <ICommand>() { testHelpCommand }; var commandStrategy = new BotStrategy(commands); // Initialize the test bot var helpObserver = new HelpObserver(commandStrategy); var testBot = new ObserverTestBot("/HELP", helpObserver); // Act testBot.Run(); var actualCommandStrategyIsNull = testBot.Strategy == null; CommandType?actualCommandType = null; if (actualCommandStrategyIsNull == false) { actualCommandType = testBot.Strategy.CommandType; } //Assert Assert.AreEqual(actualCommandStrategyIsNull, expectedCommandStrategyIsNull); if (actualCommandStrategyIsNull == false) { Assert.AreEqual(actualCommandType, expectedCommandType); } }
public void ShowCurrListBYObserver_Update_UpdatesBotCommandStrategy() { // Arrange var expectedCommandStrategyIsNull = false; var expectedCommandType = CommandType.ShowCurrListBY; // Initialize test CommandStrategy for NowObserver var testShowCurrListBYCommand = new ObserverTestCommand { CommandType = CommandType.ShowCurrListBY }; IEnumerable <ICommand> commands = new List <ICommand>() { testShowCurrListBYCommand }; var commandStrategy = new BotStrategy(commands); // Initialize the test bot var showCurrListBYObserver = new ShowCurrListBYObserver(commandStrategy); var testBot = new ObserverTestBot("/SHOWCURRLISTBY", showCurrListBYObserver); // Act testBot.Run(); var actualCommandStrategyIsNull = testBot.Strategy == null; CommandType?actualCommandType = null; if (actualCommandStrategyIsNull == false) { actualCommandType = testBot.Strategy.CommandType; } //Assert Assert.AreEqual(actualCommandStrategyIsNull, expectedCommandStrategyIsNull); if (actualCommandStrategyIsNull == false) { Assert.AreEqual(actualCommandType, expectedCommandType); } }
private void okButton_Click(object sender, EventArgs e) { if (radioButtonQfl.Checked) { if (cmbQflType.SelectedItem == null) { MessageBox.Show("QFL Type is missing"); return; } if (numQflPercent.Value == 0) { MessageBox.Show("QFL Percentage is missing"); return; } QflType.TryParse(cmbQflType.SelectedItem.ToString(), out QflType type); _strategy = new QflBotStrategy() { Options = new QflOptions(type, numQflPercent.Value) }; } if (radioButtonRsi.Checked) { if (cmbRsiTime.SelectedItem == null) { MessageBox.Show("Time is missing"); return; } IndicatorTime.TryParse(cmbRsiTime.SelectedItem.ToString(), out IndicatorTime time); _strategy = new RsiBotStrategy() { Options = new RsiOptions(time, (int)numRsiPoints.Value) }; } if (radioButtonUlt.Checked) { if (cmbUltTime.SelectedItem == null) { MessageBox.Show("Time is missing"); return; } IndicatorTime.TryParse(cmbUltTime.SelectedItem.ToString(), out IndicatorTime time); _strategy = new UltBotStrategy() { Options = new UltOptions(time, (int)numUltPoints.Value) }; } if (radioButtonTradingView.Checked) { if (cmbTradingViewTime.SelectedItem == null) { MessageBox.Show("Time is missing"); return; } if (cmbTradingViewType.SelectedItem == null) { MessageBox.Show("Type is missing"); return; } TradingViewTime.TryParse(cmbTradingViewTime.SelectedItem.ToString(), out TradingViewTime time); TradingViewIndicatorType.TryParse(cmbTradingViewType.SelectedItem.ToString(), out TradingViewIndicatorType type); _strategy = new TradingViewBotStrategy() { Options = new TradingViewOptions(type, time) }; } if (radioButtonTaPresets.Checked) { if (cmbTaPresetsTime.SelectedItem == null) { MessageBox.Show("Time is missing"); return; } if (cmbTaPresetsType.SelectedItem == null) { MessageBox.Show("Type is missing"); return; } IndicatorTime.TryParse(cmbTaPresetsTime.SelectedItem.ToString(), out IndicatorTime time); TaPresetsType.TryParse(cmbTaPresetsType.SelectedItem.ToString(), out TaPresetsType type); _strategy = new TaPresetsBotStrategy { Options = new TaPresetsOptions(type, time) }; } if (radioButtonManual.Checked) { _strategy = new ManualStrategy(); } if (radioButtonNonstop.Checked) { _strategy = new NonStopBotStrategy(); } if (radioButtonCustom.Checked) { if (string.IsNullOrWhiteSpace(txtCustom.Text)) { MessageBox.Show("Name is missing"); return; } _strategy = new UnknownStrategy(txtCustom.Text); } if (radioButtonMarketplaceItems.Checked) { if (cmbMarketplaceSignals.SelectedItem == null) { MessageBox.Show("No Item selected"); return; } _strategy = new UnknownStrategy(((MarketplaceItem)cmbMarketplaceSignals.SelectedItem).StrategyKey); } this.DialogResult = DialogResult.OK; }