public async Task MakeSureTwoRunningRoundsAsync() { using (await RoundsListLock.LockAsync()) { int runningRoundCount = Rounds.Count(x => x.Status == CcjRoundStatus.Running); if (runningRoundCount == 0) { var round = new CcjRound(RpcClient, UtxoReferee, RoundConfig); round.StatusChanged += Round_StatusChangedAsync; await round.ExecuteNextPhaseAsync(CcjRoundPhase.InputRegistration); Rounds.Add(round); var round2 = new CcjRound(RpcClient, UtxoReferee, RoundConfig); round2.StatusChanged += Round_StatusChangedAsync; await round2.ExecuteNextPhaseAsync(CcjRoundPhase.InputRegistration); Rounds.Add(round2); } else if (runningRoundCount == 1) { var round = new CcjRound(RpcClient, UtxoReferee, RoundConfig); round.StatusChanged += Round_StatusChangedAsync; await round.ExecuteNextPhaseAsync(CcjRoundPhase.InputRegistration); Rounds.Add(round); } } }
public async Task MakeSureTwoRunningRoundsAsync(Money feePerInputs = null, Money feePerOutputs = null) { using (await RoundsListLock.LockAsync().ConfigureAwait(false)) { int runningRoundCount = Rounds.Count(x => x.Status == CoordinatorRoundStatus.Running); int confirmationTarget = await AdjustConfirmationTargetAsync(lockCoinJoins : true).ConfigureAwait(false); if (runningRoundCount == 0) { var round = new CoordinatorRound(RpcClient, UtxoReferee, RoundConfig, confirmationTarget, RoundConfig.ConfirmationTarget, RoundConfig.ConfirmationTargetReductionRate); round.CoinJoinBroadcasted += Round_CoinJoinBroadcasted; round.StatusChanged += Round_StatusChangedAsync; await round.ExecuteNextPhaseAsync(RoundPhase.InputRegistration, feePerInputs, feePerOutputs).ConfigureAwait(false); Rounds.Add(round); var round2 = new CoordinatorRound(RpcClient, UtxoReferee, RoundConfig, confirmationTarget, RoundConfig.ConfirmationTarget, RoundConfig.ConfirmationTargetReductionRate); round2.StatusChanged += Round_StatusChangedAsync; round2.CoinJoinBroadcasted += Round_CoinJoinBroadcasted; await round2.ExecuteNextPhaseAsync(RoundPhase.InputRegistration, feePerInputs, feePerOutputs).ConfigureAwait(false); Rounds.Add(round2); } else if (runningRoundCount == 1) { var round = new CoordinatorRound(RpcClient, UtxoReferee, RoundConfig, confirmationTarget, RoundConfig.ConfirmationTarget, RoundConfig.ConfirmationTargetReductionRate); round.StatusChanged += Round_StatusChangedAsync; round.CoinJoinBroadcasted += Round_CoinJoinBroadcasted; await round.ExecuteNextPhaseAsync(RoundPhase.InputRegistration, feePerInputs, feePerOutputs).ConfigureAwait(false); Rounds.Add(round); } } }
private void UpdateRounds() { Game game = gameManager.Game; if (Rounds == null || Rounds.Count() != game.RoundCounter) { Rounds = Enumerable.Range(1, game.RoundCounter); } }
public bool IsFinished() { if ((Rounds.Count(o => o.GoalScorer == Team1.ID) >= 10) || (Rounds.Count(o => o.GoalScorer == Team2.ID) >= 10)) { return(true); } return(false); }
public IDictionary <int, int> Result() { IDictionary <int, int> result = new Dictionary <int, int>(); int score1 = Rounds.Count(o => o.GoalScorer == Team1.ID); result.Add(Team1.ID, score1); int score2 = Rounds.Count(o => o.GoalScorer == Team2.ID); result.Add(Team2.ID, score2); return(result); }
public void Init() { if (CurrentRound == null && Players.Any(x => x.Chunk != null)) { CurrentRound = new Round(); CurrentRound.ID = Rounds.Count() + 1; CurrentRound.Locked = false; CurrentRound.Players = new SortableList <Player>(); foreach (Player player in Players.Where(x => !string.IsNullOrEmpty(x.Chunk))) { CurrentRound.Players.Add(player); } } }
public void NextRound(int chunks) { Locked = true; if (CurrentRound != null) { Rounds.Add(CurrentRound.Copy()); } Rounds.ForEach(x => x.Locked = true); foreach (Player player in Players) { player.Chunk = string.Empty; } CurrentRound = new Round(); CurrentRound.ID = Rounds.Count() + 1; foreach (Player player in Players.Where(x => x.Alive && x.ID > 0)) { CurrentRound.Players.Add(player); } List <List <Player> > chunksList = new List <List <Player> >(); for (int i = 0; i < chunks; i++) { chunksList.Add(new List <Player>()); } foreach (var player in CurrentRound.Players.Where(x => !string.IsNullOrEmpty(x.SeedChunk))) { if (int.TryParse(player.SeedChunk, out int chunk) && chunksList.Count() >= chunk) { player.Chunk = chunk.ToString(); chunksList[chunk - 1].Add(player); } } foreach (var player in RandomPermutation(CurrentRound.Players.Where(x => string.IsNullOrEmpty(x.Chunk)))) { List <Player> chunk = chunksList.FirstOrDefault(x => x.Count() == chunksList.Min(y => y.Count())); chunk.Add(player); player.Chunk = (chunksList.IndexOf(chunk) + 1).ToString(); } }