Beispiel #1
0
        public IChannel <ICardAgent> DrawCards(uint n)
        {
            var channel = New.Channel <ICardAgent>();

            _Node.Add(New.Coroutine(DrawCardsCoro, n, channel));
            return(channel);
        }
Beispiel #2
0
        public override void StartGame()
        {
            base.StartGame();

            IEnumerator Coro(IGenerator self)
            {
                Name = "PlayerAgentCoro";
                while (!_end)
                {
                    while (_Requests.Count > 0 && _Futures.Count > 0)
                    {
                        var req = _Requests[0];
                        _Futures[0].Value = req;

                        _Requests.RemoveAt(0);
                        _Futures.RemoveAt(0);
                        yield return(null);
                    }

                    yield return(null);
                }
            }

            Verbose(50, $"Adding GameLoop for {Model}");
            _Node.Add(New.Coroutine(Coro).Named($"GameLoop for {Model}"));
        }
Beispiel #3
0
        public void TestCoro()
        {
            Root.Add(New.Coroutine(CountTo, 10).Named("Body"));

            _count = 0;
            Step(20);
            Assert.AreEqual(_count, 10);
        }
Beispiel #4
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.ResumeAfter(future));

                if (future.HasTimedOut)
                {
                    Warn($"{CurrentPlayerModel} timed-out");
                    yield return(self.ResumeAfter(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 as IGameRequest;
                var response = Model.Arbitrate(request);
                response.Request = request;
                future.Value.Responder?.Invoke(response);

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

                var now = Kernel.Time.Now;
                var dt  = (float)(now - _timeStart).TotalSeconds;

                _timeStart = now;
                _timeOut  -= dt;

                if (request is TurnEnd && response.Success)
                {
                    ResetTurnTimer();
                }
            }
        }
Beispiel #5
0
        //private IGenerator StartGameCoro()
        //{
        //    var rejectTimeOut = TimeSpan.FromSeconds(Parameters.MulliganTimer);
        //    //var kingPlaceTimeOut = TimeSpan.FromSeconds(Parameters.PlaceKingTimer);

        //    //return New.Barrier(
        //    //    New.Sequence(
        //    //        New.Barrier(
        //    //            _playerAgents.Select(p => p.StartGame())
        //    //        ).Named("InitGame"),
        //    //        New.Barrier(
        //    //            _playerAgents.Select(p => p.DrawInitialCards())
        //    //        ).Named("DealCards")
        //    //    ),
        //    //    ArbitrateFutures(
        //    //        rejectTimeOut,
        //    //        _playerAgents.Select(p => p.Mulligan())
        //    //    ).Named("Mulligan")
        //    //).Named("StartGame");
        //}

        public ITransient GameLoop()
        {
            return(New.Coroutine(PlayerTurn).Named("Turn"));

            //return New.Sequence(
            //    //StartGameCoro(),
            //    New.Coroutine(PlayerTurn).Named("Turn"),
            //    New.Coroutine(EndGame).Named("EndGame")
            //).Named("Done");
        }
Beispiel #6
0
        public void TestResumeAfterPred(int activateStep, int numSteps, bool ran)
        {
            var hasRun = false;

            IEnumerator Coro(IGenerator self)
            {
                yield return(null);

                hasRun = true;
            }

            var coro = New.Coroutine(Coro);

            coro.AddTo(Root);
            coro.ResumeAfter(() => Kernel.StepNumber > activateStep);
            Assert.IsFalse(hasRun);

            Step(numSteps);
            Print(Kernel.StepNumber);
            Print(hasRun);

            Assert.AreEqual(hasRun, ran);
        }
Beispiel #7
0
 public override void StartGame()
 {
     base.StartGame();
     _Node.Add(New.Coroutine(Coro));
 }
Beispiel #8
0
 public void StartGame()
 {
     Info($"{this} StartGame");
     BoardAgent.StartGame();
     _Node.Add(New.Coroutine(PlayerTurn).Named("ArbiterMain"));
 }