diff --git a/07_Basketball/csharp/IReadWriteExtensions.cs b/07_Basketball/csharp/IReadWriteExtensions.cs index 9a066f2e..6197ff97 100644 --- a/07_Basketball/csharp/IReadWriteExtensions.cs +++ b/07_Basketball/csharp/IReadWriteExtensions.cs @@ -13,11 +13,11 @@ internal static class IReadWriteExtensions } } - private static bool TryReadInteger(this IReadWrite io, string prompt, out int value) + private static bool TryReadInteger(this IReadWrite io, string prompt, out int intValue) { var floatValue = io.ReadNumber(prompt); - value = (int)floatValue; - return value == floatValue; + intValue = (int)floatValue; + return intValue == floatValue; } public static Shot? ReadShot(this IReadWrite io, string prompt) diff --git a/07_Basketball/csharp/Probably.cs b/07_Basketball/csharp/Probably.cs index 018a8108..0ba5864a 100644 --- a/07_Basketball/csharp/Probably.cs +++ b/07_Basketball/csharp/Probably.cs @@ -14,28 +14,28 @@ internal struct Probably private readonly IRandom _random; private readonly bool? _result; - internal Probably(float defenseFactor, IRandom random, bool? result = false) + internal Probably(float defenseFactor, IRandom random, bool? result = null) { _defenseFactor = defenseFactor; _random = random; _result = result; } - public Probably Do(float probability, Func action) => - ShouldResolveAction(probability) - ? new Probably(_defenseFactor, _random, _result | Resolve(action)) - : this; - public Probably Do(float probability, Action action) => ShouldResolveAction(probability) - ? new Probably(_defenseFactor, _random, _result | Resolve(action)) + ? new Probably(_defenseFactor, _random, Resolve(action) ?? false) + : this; + + public Probably Do(float probability, Func action) => + ShouldResolveAction(probability) + ? new Probably(_defenseFactor, _random, Resolve(action) ?? false) : this; public Probably Or(float probability, Action action) => Do(probability, action); - public Probably Or(float probability, Func action) => Do(probability, action); + public Probably Or(float probability, Func action) => Do(probability, action); - public bool Or(Action action) => _result | Resolve(action) ?? false; + public bool Or(Action action) => _result ?? Resolve(action) ?? false; private bool? Resolve(Action action) { @@ -43,10 +43,8 @@ internal struct Probably return _result; } - private bool? Resolve(Func action) => action.Invoke(); + private bool? Resolve(Func action) => action.Invoke(); - private readonly bool ShouldResolveAction(float probability) - { - return _result is null && _random.NextFloat() <= probability * _defenseFactor; - } + private readonly bool ShouldResolveAction(float probability) => + _result is null && _random.NextFloat() <= probability * _defenseFactor; }