Example #1
0
 private bool Resolve(Shot shot, Scoreboard scoreboard) =>
 Resolve(shot.ToString(), _defense / 7)
 .Do(0.4f, () => scoreboard.AddBasket("Shot is good.  Two points."))
 .Or(0.7f, () => ResolveShotOffTheRim(scoreboard))
 .Or(0.875f, () => ResolveFreeThrows(scoreboard, "Shooter fouled.  Two shots."))
 .Or(0.925f, () => scoreboard.Turnover($"Shot blocked. {scoreboard.Visitors}'s ball."))
 .Or(() => scoreboard.Turnover($"Charging foul.  {scoreboard.Home} loses ball."));
Example #2
0
 // The Resolve* methods resolve the probabilistic outcome of the current game state.
 // They return true if the Home team should continue the play and attempt a layup, false otherwise.
 private bool Resolve(JumpShot shot, Scoreboard scoreboard) =>
 Resolve(shot.ToString(), _defense / 8)
 .Do(0.341f, () => scoreboard.AddBasket("Shot is good"))
 .Or(0.682f, () => ResolveShotOffTarget(scoreboard))
 .Or(0.782f, () => _ballContest.Resolve(scoreboard))
 .Or(0.843f, () => ResolveFreeThrows(scoreboard, "Shooter is fouled.  Two shots."))
 .Or(() => scoreboard.Turnover($"Charging foul.  {scoreboard.Home} loses ball."));
Example #3
0
 private void ResolvePossibleSteal(Scoreboard scoreboard)
 {
     if (_defense == 6 && _random.NextFloat() > 0.6f)
     {
         scoreboard.Turnover();
         scoreboard.AddBasket($"Pass stolen by {scoreboard.Visitors} easy layup.");
         _io.WriteLine();
     }
     _io.Write("Ball passed back to you. ");
 }
    private bool ResolveVisitorsRebound(Scoreboard scoreboard)
    {
        _io.Write($"{scoreboard.Visitors} controls the rebound.");
        if (_defense == 6 && _random.NextFloat() <= 0.25f)
        {
            _io.WriteLine();
            scoreboard.Turnover();
            scoreboard.AddBasket($"Ball stolen.  Easy lay up for {scoreboard.Home}.");
            return(false);
        }

        if (_random.NextFloat() <= 0.5f)
        {
            _io.WriteLine();
            _io.Write($"Pass back to {scoreboard.Visitors} guard.");
            return(false);
        }

        return(true);
    }
 private bool Resolve(Shot shot, Scoreboard scoreboard) =>
 Resolve(shot.ToString(), _defense / 7)
 .Do(0.413f, () => scoreboard.AddBasket("Shot is good."))
 .Or(() => ResolveBadShot(scoreboard, "Shot is missed.", 6 / _defense));
 // The Resolve* methods resolve the probabilistic outcome of the current game state.
 // They return true if the Visiting team should continue the play and attempt a layup, false otherwise.
 private bool Resolve(JumpShot shot, Scoreboard scoreboard) =>
 Resolve(shot.ToString(), _defense / 8)
 .Do(0.35f, () => scoreboard.AddBasket("Shot is good."))
 .Or(0.75f, () => ResolveBadShot(scoreboard, "Shot is off the rim.", _defense * 6))
 .Or(0.9f, () => ResolveFreeThrows(scoreboard, "Player fouled.  Two shots."))
 .Or(() => _io.WriteLine($"Offensive foul.  {scoreboard.Home}'s ball."));