Esempio n. 1
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."));
Esempio n. 2
0
    public void Play()
    {
        var ballContest = new BallContest(0.4f, "{0} controls the tap", _io, _random);

        while (true)
        {
            _io.WriteLine("Center jump");
            ballContest.Resolve(_scoreboard);

            _io.WriteLine();

            while (true)
            {
                var isFullTime = _scoreboard.Offense.ResolvePlay(_scoreboard);
                if (isFullTime && IsGameOver())
                {
                    return;
                }
                if (_clock.IsHalfTime)
                {
                    break;
                }
            }
        }
    }