Example #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();
Example #2
0
        public static GameTask Default(string playerName)
        {
            PlayerSpec[] players = new PlayerSpec[]
            {
                new PlayerSpec {
                    PlayerType = PlayerType.Async, PlayerName = playerName
                },
                new PlayerSpec {
                    PlayerType = PlayerType.Cpu, PlayerName = "Bob"
                },
                new PlayerSpec {
                    PlayerType = PlayerType.Cpu, PlayerName = "Alice"
                },
                new PlayerSpec {
                    PlayerType = PlayerType.Cpu, PlayerName = "Carol"
                }
            };
            players = players.OrderBy(x => _rnd.Next()).ToArray();//shuffle players
            var spec = TbGameSpecModule.initClassicQuick(players.Length);

            return(new GameTask(spec, players));
        }