示例#1
0
        public void TestPlayerRaceRandomization()
        {
            Game         Game    = null;
            IGameBuilder builder = NewGameBuilder.Create().
                                   SetMap(new DemoMap()).
                                   SetPlayerName("Player 1").
                                   SetPlayerName("Player 2").
                                   SetPlayerName("Player 3");
            IDictionary <Type, IDictionary <string, int> > racesResults =
                new Dictionary <Type, IDictionary <string, int> >();
            IDictionary <String, int> dict = null;

            int i = 0;

            while (i++ < 1000)
            {
                Game = builder.Build();
                for (var j = 0; j < Game.Players.Count; j++)
                {
                    var name = Game.Players[j].Name;
                    var race = Game.Players[j].Race;
                    if (racesResults.ContainsKey(race.GetType()))
                    {
                        dict = racesResults[race.GetType()];
                        if (dict.ContainsKey(name))
                        {
                            dict[name]++;
                        }
                        else
                        {
                            dict[name] = 1;
                        }
                    }
                    else
                    {
                        dict = new Dictionary <String, int>();
                        dict.Add(name, 1);
                        racesResults[race.GetType()] = dict;
                    }
                }
            }

            var normalDistribMean = 1.0 / racesResults.Keys.Count;

            foreach (var type in racesResults.Keys)
            {
                foreach (var name in racesResults[type].Keys)
                {
                    var percentage = racesResults[type][name] / (double)racesResults[type].Values.Sum();
                    Assert.IsTrue(normalDistribMean - 0.1 < percentage && percentage < normalDistribMean + 0.1);
                }
            }
        }
示例#2
0
        public IActionResult Create([FromBody] CreateGameModel model)
        {
            if (model.Size < 0)
            {
                return(BadRequest("Board size can't be less than 0."));
            }

            _builder.WithBoardSize(model.Size);
            var game = _builder.Build();

            var report = _simulator.Simulate(_gameHost, game);

            return(Ok(report));
        }
        public void RunGame()
        {
            var keepPlaying = true;

            _displayManager.DisplayInstructions();
            _displayManager.PromptWaitAnyInput();
            _inputManager.WaitForAnyInput();

            while (keepPlaying)
            {
                var gameState = _gameBuilder.Build(MAX_GRID_ROWS, MAX_GRID_COLUMNS, MAX_PLAYER_LIVES, MAX_MINES);
                _displayManager.DisplayGameState(gameState);

                var gameEnded = false;
                while (!gameEnded)
                {
                    _displayManager.PromptControlGuidance();
                    var playerDirection = EnsurePlayerDirection();
                    _gameStateProcessor.PlayStep(gameState, playerDirection);
                    _displayManager.DisplayGameState(gameState);

                    if (gameState.HasWon())
                    {
                        gameEnded = true;
                        _displayManager.DisplayWin(gameState);
                    }

                    if (gameState.HasLost())
                    {
                        gameEnded = true;
                        _displayManager.DisplayGameOver(gameState);
                    }
                }
                _displayManager.PromptPlayAgain();
                keepPlaying = _inputManager.GetYesNoResponse();
            }
        }