Exemplo n.º 1
0
        private void RunGame(int gameNumber, ChosenStartingConfiguration startingConfig)
        {
            var game    = startingConfig.CreateGame(Players.Keys);
            var clients = new List <IGameClient>();

            var host = new LockingGameHost(game);

            foreach (var player in game.Players)
            {
                IGameClient client = new GameClient(player.Id, player.Name);
                clients.Add(client);

                var ai = _aiFactory.Create(Players[player.Name]);
                ai.Attach(client);

                host.RegisterGameClient(client, player);
            }

            host.AcceptMessage(new BeginGameMessage());

            var firstClient = clients.First();

            while (!firstClient.GetGameState().Status.GameIsComplete)
            {
                Thread.Sleep(500);
            }

            var state = firstClient.GetGameState();

            File.WriteAllText(Path.Combine(Name, string.Format("game_{0}.txt", gameNumber)), state.Log);

            _results[gameNumber] = state.Results;
        }
Exemplo n.º 2
0
        public void GivenANewGameWithPlayersAndBank(int playerCount, string bankCardNames)
        {
            var cardNameList   = bankCardNames.Split(new char[] { ',', ' ' }, StringSplitOptions.RemoveEmptyEntries);
            var startingConfig = new ChosenStartingConfiguration(playerCount, cardNameList, false);
            var names          = playerCount.Items(i => "Player" + i);

            _game = startingConfig.CreateGame(names);
        }
Exemplo n.º 3
0
        public void Run(Action <Task <ResultsSummary> > onUpdateResults, Action <Task> onDone)
        {
            _results = new GameResultsViewModel[NumberOfGamesToExecute];
            var startingConfig = new ChosenStartingConfiguration(Players.Count, Cards, false);

            TaskScheduler syncContext = TaskScheduler.FromCurrentSynchronizationContext();

            Task[] tasks = new Task[NumberOfGamesToExecute];

            for (int i = 0; i < NumberOfGamesToExecute; i++)
            {
                int temp = i;
                tasks[i] = Task.Factory.StartNew(() => RunGame(temp, startingConfig))
                           .ContinueWith(t => CreateSummary())
                           .ContinueWith(onUpdateResults, syncContext);
            }

            Task.Factory
            .ContinueWhenAll(tasks, WriteResults)
            .ContinueWith(onDone, syncContext);
        }