Ejemplo 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));
     }
 }
Ejemplo n.º 2
0
 public bool Contains(int value)
 {
     return(GameGuessHistory.Contains(value));
 }
Ejemplo n.º 3
0
 public void AddGuessHistoryItem(int value, IGuessGamePlayer player)
 {
     GuessHistoryLog.Add(new GuessHistoryLogRecord(player, value));
     GameGuessHistory.Add(value);
 }