public void SelectPLayerstoStartRound_multiple() { CompleteGameScores <IScore> gameScores = new CompleteGameScores <IScore>(); gameScores.StartNewRound(); var round1 = gameScores.GetCurrentRoundScores(); round1.AddScoreForPlayer(new UndeadScore(Color.white, 1, 0, 0, false, true)); round1.AddScoreForPlayer(new UndeadScore(Color.white, 2, 0, 0, false, false)); gameScores.StartNewRound(); var round2 = gameScores.GetCurrentRoundScores(); round2.AddScoreForPlayer(new UndeadScore(Color.white, 1, 0, 0, false, false)); round2.AddScoreForPlayer(new UndeadScore(Color.white, 2, 0, 0, false, true)); gameScores.StartNewRound(); var round3 = gameScores.GetCurrentRoundScores(); round3.AddScoreForPlayer(new UndeadScore(Color.white, 1, 0, 0, false, false)); round3.AddScoreForPlayer(new UndeadScore(Color.white, 2, 0, 0, false, false)); var playersToStartAsUndead = UndeadGameMode.SelectPlayersToStartAsUndead(gameScores, 1); Assert.AreEqual(playersToStartAsUndead.Length, 1); }
public static int[] SelectPlayersToStartAsUndead(CompleteGameScores <IScore> gameScores, int nStartingUndead) { var undeadAndNot = ExtractWhichPlayersHaveStartedAsUndeadAndNot(gameScores); var nPlayersThatShouldStartAsUndead = Mathf.Min(nStartingUndead, Mathf.Max(undeadAndNot[true].Count + undeadAndNot[false].Count - 1, 0)); var nPlayersThatHaventStartedAsUndeadYet = Mathf.Min(nPlayersThatShouldStartAsUndead, undeadAndNot[false].Count); var nPlayersThatHaveStartedAsUndeadYet = Mathf.Min(Mathf.Max(0, nPlayersThatShouldStartAsUndead - nPlayersThatHaventStartedAsUndeadYet), undeadAndNot[true].Count); var extractedNeverStartedAsUndead = CollectionUtils.ExtractRandomValues(undeadAndNot[false], nPlayersThatHaventStartedAsUndeadYet); var extractedHasStartedAsUndead = CollectionUtils.ExtractRandomValues(undeadAndNot[true], nPlayersThatHaveStartedAsUndeadYet); return(ArrayUtils.Merge(extractedNeverStartedAsUndead, extractedHasStartedAsUndead)); }
public void SelectPlayersToStartRound_should_choose_randomly_from_all_since_none_have_started_as_undead() { CompleteGameScores <IScore> gameScores = new CompleteGameScores <IScore>(); gameScores.StartNewRound(); var round = gameScores.GetCurrentRoundScores(); round.AddScoreForPlayer(new UndeadScore(Color.white, 1, 0, 0, false, false)); round.AddScoreForPlayer(new UndeadScore(Color.white, 2, 0, 0, false, false)); var playersToStart = UndeadGameMode.SelectPlayersToStartAsUndead(gameScores, 1); Assert.AreEqual(playersToStart.Length, 1); }
public void SelectPLayerstoStartRound_three_players_round_two() { CompleteGameScores <IScore> gameScores = new CompleteGameScores <IScore>(); gameScores.StartNewRound(); var round1 = gameScores.GetCurrentRoundScores(); round1.AddScoreForPlayer(new UndeadScore(Color.white, 1, 0, 0, false, true)); round1.AddScoreForPlayer(new UndeadScore(Color.white, 2, 0, 0, false, false)); round1.AddScoreForPlayer(new UndeadScore(Color.white, 3, 0, 0, false, true)); gameScores.StartNewRound(); var round2 = gameScores.GetCurrentRoundScores(); round2.AddScoreForPlayer(new UndeadScore(Color.white, 1, 0, 0, false, false)); round2.AddScoreForPlayer(new UndeadScore(Color.white, 2, 0, 0, false, false)); round2.AddScoreForPlayer(new UndeadScore(Color.white, 2, 0, 0, false, false)); var playersToStartAsUndead = UndeadGameMode.SelectPlayersToStartAsUndead(gameScores, 2); Assert.AreEqual(playersToStartAsUndead.Length, 2); Assert.IsTrue(ArrayUtils.Contains(2, playersToStartAsUndead)); Assert.AreEqual(1, ArrayUtils.CountOccurrences(2, playersToStartAsUndead)); }
private static Dictionary <bool, List <int> > ExtractWhichPlayersHaveStartedAsUndeadAndNot(CompleteGameScores <IScore> gameScores) { Dictionary <int, bool> PlayerHasStartedAsUndead = new Dictionary <int, bool>(); foreach (var round in gameScores.roundScores) { foreach (var playerScore in round.Scores) { if (PlayerHasStartedAsUndead.ContainsKey(playerScore.PlayerNumber())) { PlayerHasStartedAsUndead[playerScore.PlayerNumber()] = PlayerHasStartedAsUndead[playerScore.PlayerNumber()] || ((UndeadScore)playerScore).StartedAsUndead; } else { PlayerHasStartedAsUndead[playerScore.PlayerNumber()] = ((UndeadScore)playerScore).StartedAsUndead; } } } var notStarted = new List <int>(); var hasStarted = new List <int>(); foreach (var keyvalue in PlayerHasStartedAsUndead) { if (keyvalue.Value) { hasStarted.Add(keyvalue.Key); } else { notStarted.Add(keyvalue.Key); } } var output = new Dictionary <bool, List <int> > { { true, hasStarted }, { false, notStarted } }; return(output); }