Beispiel #1
0
        public IEnumerator DrawCardsCoro(IGenerator self, uint n, IChannel <ICardAgent> channel)
        {
            while (n-- > 0)
            {
                var card = Draw();
                yield return(self.After(card));

                if (!card.Available)
                {
                    yield break;
                }
                channel.Insert(card.Value);

                yield return(self.ResumeAfter(TimeSpan.FromSeconds(0.020)));
            }
        }
Beispiel #2
0
        private IEnumerator PlayerTurn(IGenerator self)
        {
            CurrentPlayerModel.StartTurn();

            ResetTurnTimer();

            // player can make as many valid actions as he can during his turn
            while (true)
            {
                if (GameState.Value == EGameState.Completed)
                {
                    self.Complete();
                    yield break;
                }

                Assert.IsTrue(self.Active);

                var future = CurrentPlayerAgent.Value.NextRequest(_timeOut);
                Assert.IsNotNull(future);

                yield return(self.After(future));

                if (future.HasTimedOut)
                {
                    Warn($"{CurrentPlayerModel} timed-out");
                    yield return(self.After(New.Coroutine(PlayerTimedOut)));

                    continue;
                }
                if (!future.Available)
                {
                    Warn($"{CurrentPlayerModel} didn't make a request");
                }

                // do the arbitration before we test for time out
                var request  = future.Value.Request;
                var response = Model.Arbitrate(request);
                response.Request = request;
                //_lastResponse.Value = response;
                future.Value.Responder?.Invoke(response);

                if (response.Failed)
                {
                    Warn($"{request} failed for {CurrentPlayerModel}");
                }

                var now = Kernel.Time.Now;
                var dt  = (float)(now - _timeStart).TotalSeconds;
                //if (dt < 1.0f/60.0f)    // give them a 60Hz frame of grace
                //{
                //    Warn($"{CurrentPlayerModel} ran out of time for turn");
                //    break;
                //}

                _timeStart = now;
                _timeOut  -= dt;

                if (request is TurnEnd && response.Success)
                {
                    ResetTurnTimer();
                }
            }
        }