Esempio n. 1
0
        public async Task Initialize(GameBoardNavigationArgs args)
        {
            _gameConnectionType = args.GameConnectionType;
            _gameMode           = args.GameMode;

            _tileManager = TileManager.GetInstance();
            await _tileManager.InitializeForNewGame();

            _botManager = BotManager.GetInstance();

            _gameBoard = GameBoard.GetInstance();
            _gameBoard.ClearBoard();

            _dictionary = Dictionary.GetInstance();
            await _dictionary.PopulateDictionary();

            InitializeGameClock();

            _humanPlayer = new HumanPlayer();

            _localPlayers.Clear();
            _localPlayers.Add(_humanPlayer);

            _botManager.ClearBotList();

            for (int i = 0; i < args.BotCount; i++)
            {
                _botManager.CreateBot(5);
            }

            foreach (IRobot bot in _botManager.BotList)
            {
                _localPlayers.Add(bot);
            }

            foreach (IPlayer player in _localPlayers)
            {
                player.InitializeForGame();
            }

            OnInitializeComplete();
        }
Esempio n. 2
0
        public async Task OnCopy()
        {
            var ids = View.SelectedBotIds;

            if (IsValid(ids))
            {
                var dlg = new ChooseAccount.ChooseAccount(_keys, _logger);
                var dr  = dlg.ShowDialog(View);
                if (dr == DialogResult.OK)
                {
                    dr = _mbs.ShowQuestion($"Copy {ids.Count} Bots in Account '{dlg.Account.Name}' now?");
                    if (dr == DialogResult.Yes)
                    {
                        var cancellationTokenSource = new CancellationTokenSource();
                        var loadingView             = new ProgressView.ProgressView("Bots are now being copied", cancellationTokenSource, ids.Count);
                        loadingView.Show(View);

                        var botMgr = new BotManager(_keys, _logger);

                        int i = 0;
                        foreach (var botId in ids)
                        {
                            i++;
                            loadingView.SetProgress(i);

                            if (cancellationTokenSource.IsCancellationRequested)
                            {
                                break;
                            }

                            var bot = await botMgr.GetBotById(botId);

                            bot.AccountId = dlg.Account.Id;
                            var res = await botMgr.CreateBot(dlg.Account.Id, bot.Strategy, bot);

                            if (res.IsSuccess)
                            {
                                if (bot.IsEnabled)
                                {
                                    await botMgr.Enable(res.Data.Id);
                                }
                                _logger.LogInformation($"Bot {botId} created");
                            }
                            else
                            {
                                _logger.LogError($"Could not copy Bot {botId}. Reason: {res.Error}");
                            }
                        }

                        loadingView.Close();
                        if (cancellationTokenSource.IsCancellationRequested)
                        {
                            _logger.LogInformation("Operation cancelled");
                            _mbs.ShowError("Operation cancelled!", "");
                        }
                        else
                        {
                            _mbs.ShowInformation("Bulk Copy finished. See output section for details.");
                        }

                        _logger.LogInformation("Refreshing Bots");
                        await RefreshBots();
                    }
                }
            }
        }