Beispiel #1
0
        static async Task Main(string[] args)
        {
            var players = new PlayerSpec[]
            {
                new PlayerSpec {
                    Name = "Bob", Type = PlayerType.Cpu
                },
                new PlayerSpec {
                    Name = "Alice", Type = PlayerType.Cpu
                },
                new PlayerSpec {
                    Name = "Orri", Type = PlayerType.Console
                }
            };
            var playerNames = players.Select(p => p.Name).ToArray();
            var spec        = TbGameSpecModule.initClassicQuick(players.Length);
            var game        = TbGameModule.create(spec);
            var asyncGame   = new AsyncGame <TbState, TbAction, TbVisible>(game, playerNames);

            Task[] playerTasks = players.Select((p, i) => {
                return(p.Type switch
                {
                    PlayerType.Cpu => new AsyncCpuPlayer(asyncGame.Players[i], spec).Start(),
                    PlayerType.Console => new AsyncConsolePlayer(asyncGame.Players[i]).RunPlayer(),
                    _ => throw new Exception("Death"),
                });
            }).ToArray();
Beispiel #2
0
        public async Task Start()
        {
            var playerNames = _playerSpecs.Select(p => p.PlayerName).ToArray();
            var game        = TbGameModule.create(_spec);

            _game = new AsyncGame <TbState, TbAction, TbVisible>(game, playerNames);
            Task[] cpuPlayerTasks =
                _playerSpecs.Select((p, i) => {
                if (p.PlayerType == PlayerType.Cpu)
                {
                    return(new AsyncCpuPlayer(_game.Players[i], _spec).Start());
                }
                else
                {
                    return(null);
                }
            }).Where(p => p != null).ToArray();
            await _game.Start();

            Task.WaitAll(cpuPlayerTasks);
        }