Exemple #1
0
 private void GetGuess(GameEventHub ctx, PlayerIndex nextTurn, IInvokablePlayer bot)
 {
     // TODO async
     Delay();
     while (true)
     {
         var count = bot.GetGuess(ctx.State);
         if (ctx.TryGiveGuess(nextTurn, count))
         {
             break;
         }
     }
 }
Exemple #2
0
 private void GetMove(GameEventHub ctx, PlayerIndex nextTurn, IInvokablePlayer bot)
 {
     // TODO async
     Delay();
     while (true)
     {
         var card = bot.GetMove(ctx.State);
         if (ctx.TryPlayCard(nextTurn, card))
         {
             break;
         }
     }
 }
Exemple #3
0
        public ActiveLobby(BotController botController, EumelGameRoomDefinition room, GameProgress progress)
        {
            Room           = room ?? throw new ArgumentException(nameof(room));
            _botController = botController ?? throw new ArgumentException(nameof(botController));
            _events        = new EventCollection <GameSeriesEvent>();

            GameContext = new GameEventHub(room, progress);

            // TODO when / how is an active lobby disposed
            GameContext.OnGameEvent += async(s, e) => await GameEventHandler(s, e);

            GameContext.OnGameEvent += async(s, e) => await _botController.OnGameEvent(s, e);


            SetProgress(progress);
        }
Exemple #4
0
        private void HandleBotMoves(GameEventHub ctx)
        {
            var turn     = ctx.State.Turn;
            var nextTurn = turn.PlayerIndex;

            if (!HasBotFor(nextTurn))
            {
                return;
            }

            var bot = BotFor(nextTurn);

            if (turn.NextEventType == typeof(GuessGiven))
            {
                GetGuess(ctx, nextTurn, bot);
            }
            else if (turn.NextEventType == typeof(CardPlayed))
            {
                GetMove(ctx, nextTurn, bot);
            }
        }