Exemplo n.º 1
0
 private GuessHistoryLogRecord GetWinnerLogRecord(int secretValue)
 {
     // if there's a clear winner player
     if (this.Contains(secretValue))
     {
         var lastRecord = GuessHistoryLog.Last();
         if (lastRecord.GuessValue == secretValue)
         {
             return(lastRecord);
         }
         else
         {
             throw new InvalidGameCompletionException("Invalid winner player");
         }
     }
     else
     {
         // find minimal difference between the target value and the guess history
         var minDif = GameGuessHistory.Min(GuessValue => Math.Abs(GuessValue - secretValue));
         // find the first closest guess player
         return(GuessHistoryLog.First(e => Math.Abs(e.GuessValue - secretValue) == minDif));
     }
 }
Exemplo n.º 2
0
 private int GetNumberOfAttempts(IGuessGamePlayer player)
 {
     return(GuessHistoryLog.Count(e => e.Player.Equals(player)));
 }