Beispiel #1
0
        public static void Run()
        {
            var players = new[]
            {
                Player.CreateCustom("TrickBoy1", new MaxTrickBoy()),
                Player.CreateCustom("O1", new Opportunist()),
                Player.CreateCustom("TrickBoy2", new MaxTrickBoy()),
                Player.CreateCustom("O1", new Opportunist()),
                Player.CreateCustom("O1", new Opportunist()),
                Player.CreateCustom("O1", new Opportunist()),
            };

            for (int repeat = 0; repeat <= 10; repeat++)
            {
                var scoreTracker = new ScoreTracker();
                // scoreTracker.PrintHeader(players);
                for (int games = 0; games < 1000; games++)
                {
                    var gameDef = new EumelGameRoomDefinition(
                        "the game",
                        players.Select(p => p.Info).ToImmutableList().WithValueSemantics(),
                        EumelGamePlan.For(players.Length),
                        new GameRoomSettings(0)
                        );
                    var botController = new BotController(players.Select(p => p.Invocable), gameDef);
                    var room          = new ActiveLobby(botController, gameDef, GameProgress.NotStarted);
                    room.SubscribeWithPreviousEvents(scoreTracker);
                    while (room.HasMoreRounds)
                    {
                        room.StartNextRound();
                    }
                }
                Console.WriteLine("Total scores: " + string.Join(", ", Enumerable.Zip(players.Select(p => p.Info.Name), scoreTracker.Scores)));
            }
        }
Beispiel #2
0
        static void PlayAgainstBots()
        {
            var players = new[]
            {
                Player.CreateBot("Fatz!"),
                Player.CreateBot("Hans"),
                Player.CreateCustom("YOU", new ConsolePlayer()),
            };

            var playerFactory = new PlayerFactory()
                                .RegisterOrOverrideCreator(nameof(ConsolePlayer), () => new ConsolePlayer());

            var gameDef = new EumelGameRoomDefinition(
                "the game",
                players.Select(p => p.Info).ToImmutableList().WithValueSemantics(),
                EumelGamePlan.For(players.Length),
                new GameRoomSettings(0)
                );
            var botController = new BotController(players.Select(p => p.Invocable), gameDef);
            var lobby         = new ActiveLobby(botController, gameDef, GameProgress.NotStarted);

            var logger = new ConsoleGameObserver();

            lobby.SubscribeWithPreviousEvents(logger);
            lobby.GameContext.SubscribeWithPreviousEvents(logger);
            while (lobby.HasMoreRounds)
            {
                lobby.StartNextRound();
            }
        }
Beispiel #3
0
        private static EumelGameRoomDefinition GenGameRoomDefinitionFor3Players()
        {
            var players = Enumerable.Range(1, 3)
                          .Select(_ => new PlayerInfo("unnamed", PlayerType.Bot))
                          .ToImmutableList()
                          .WithValueSemantics();
            var plan        = EumelGamePlan.For(3);
            var gameRoomDef = new EumelGameRoomDefinition("test", players);

            return(gameRoomDef);
        }
Beispiel #4
0
 public GameEventHub(EumelGameRoomDefinition definition, GameProgress progress)
 {
     _gameEventContext = new(definition.Name, -1);
     _numPlayers       = definition.Players.Count;
     _plan             = definition.Plan;
     // TODO: join event types. Make GameSeriesStarted contents static data of the room
     _events = new EventCollection <GameEvent>();
     if (progress.LastRoundEvents.Any())
     {
         ForwardTo(progress);
     }
 }
Beispiel #5
0
        public Task GameSeriesStarted(GameSeriesDto data)
        {
            _deck = new GameCardDeck((Rank)data.MinCardRank);
            var plannedRounds = data.PlannedRounds
                                .Select(setting => new EumelRoundSettings(setting.StartingPlayer, setting.TricksToPlay));
            var plan    = new EumelGamePlan(plannedRounds, _deck);
            var players = data.PlayerInfos.Select(p => new PlayerInfo(p.Name, p.Type)).ToList();
            var e       = new GameSeriesStarted(data.GameId, players, plan);

            _gameSeriesEventCallback(e);
            return(Task.CompletedTask);
        }
        public void GameSeriesStartIsMappedAndBack()
        {
            var playerInfos = new List <PlayerInfo> {
                new PlayerInfo("a", "t1"),
                new PlayerInfo("b", "t2"),
                new PlayerInfo("c", "t1")
            };
            var plan          = EumelGamePlan.For(3);
            var seriesStarted = new GameSeriesStarted("uuid", playerInfos, plan);

            var persistable = GameSeriesEventSerializer.Convert(seriesStarted);
            var recreated   = GameSeriesEventSerializer.Convert(persistable) as GameSeriesStarted;

            Assert.Equal(seriesStarted.Plan, recreated.Plan);
            Assert.Equal(seriesStarted.Players, recreated.Players);
            Assert.Equal(seriesStarted, recreated);
        }
Beispiel #7
0
        public static PersistedEumelGame CreateFrom(EumelGameRoomDefinition room)
        {
            if (room.Plan != EumelGamePlan.For(room.Players.Count))
            {
                throw new NotImplementedException($"can only persist simple variants of {nameof(EumelGamePlan)}");
            }

            return(new PersistedEumelGame
            {
                Name = room.Name,
                Players = room.Players
                          .Select(pi => new PersistedPlayer {
                    Name = pi.Name, Type = pi.Type
                })
                          .ToList(),
                // Rounds = room.Events.OfType<RoundStarted>().Select((rse, index) => new PersistedGameRound{
                //     Index = index,
                //     StartingPlayerIndex = rse.Settings.StartingPlayerIndex,
                //     NumTricks = rse.Settings.TricksToPlay,
                // }).ToList()
            });
        }