public async Task<RoundResult> PerformNextRoundAsync() { if (_player1 == null || _player2 == null) { throw new Exception("There are no players to perform next round."); } var result = new RoundResult() { History = new List<RoundPartialHistory>(), IsFinished = false }; foreach (var competitor in _competitors) { if (IsBoardFull()) { ClearTheBoard(); } result.History.Add(await PerformNextMove(competitor)); await DelayHelper.DelayAsync(_configuration.NextMoveDelay); if (await IsPlayerWon(competitor)) { result.IsFinished = true; result.FinalResult = GetResults(); break; } } return result; }
public override async void Execute(object parameter = null) { _viewModel.IsGameInProgress = false; var competitors = _viewModel.Elimination.GetNextCompetitors(); var window = new WinnerSelectionDialog(competitors); window.ShowDialog(); if (window.DialogResult.HasValue && window.DialogResult.Value) { var result = new RoundResult() { FinalResult = competitors.ToDictionary(comp => comp, comp => comp.Id == window.SelectedWinner.Id ? 1.0 : 0.0), IsFinished = true }; await _viewModel.MakeEndGameConfiguration(result); } else { _viewModel.IsGamePaused = true; } }
public async Task<RoundResult> PlayBotMovesAsync(int delayTime, int roundNumber) { var result = new RoundResult() { FinalResult = null, IsFinished = false, History = new List<RoundPartialHistory>() }; foreach (var dynaBlasterBot in _field.Bots.Where(bot => !bot.IsDead)) { BotMove move; try { move = await dynaBlasterBot.NextMoveAsync(GetBotBattlefieldInfo(dynaBlasterBot, roundNumber)); } catch (Exception e) { move = new BotMove() { Action = BotAction.None, Direction = null }; result.OutputText += string.Format("Bot {0} threw exception:\n{1}\n", dynaBlasterBot.Name, e.Message); } if (IsMoveValid(dynaBlasterBot, move)) { result.History.Add(PerformMove(dynaBlasterBot, move, roundNumber)); _field.OnArenaChanged(); } await DelayHelper.DelayAsync(delayTime); } return result; }
public async Task MakeEndGameConfiguration(RoundResult result) { Elimination.SetLastDuelResult(result.FinalResult); ScoreList.SaveScore(result.FinalResult); await SetArenaMessage(ArenaMessageHelper.GetEndGameMessage(result.FinalResult)); }