Beispiel #1
0
        public void GetValidConnectionsForPlayerInfrastructure_ShephardsCrook_ExpectedConnectionsWithNoDuplicates()
        {
            var gameBoard   = new GameBoard(BoardSizes.Standard);
            var queryEngine = new GameBoardQuery(gameBoard);
            var playerId    = Guid.NewGuid();

            gameBoard.PlaceStartingInfrastructure(playerId, 21, 22);
            gameBoard.PlaceStartingInfrastructure(playerId, 33, 22);
            gameBoard.PlaceRoadSegment(playerId, 33, 34);
            gameBoard.PlaceRoadSegment(playerId, 35, 34);
            gameBoard.PlaceRoadSegment(playerId, 35, 24);

            var results = queryEngine.GetValidConnectionsForPlayerInfrastructure(playerId);

            var expected = new HashSet <Connection>();

            expected.Add(new Connection(11, 21));
            expected.Add(new Connection(21, 20));
            expected.Add(new Connection(22, 23));
            expected.Add(new Connection(33, 32));
            expected.Add(new Connection(34, 44));
            expected.Add(new Connection(35, 36));
            expected.Add(new Connection(24, 25));
            expected.Add(new Connection(23, 24));
            results.ShouldMatch(expected);
        }
Beispiel #2
0
        public void GetValidConnectionsForPlayerInfrastructure_NoInfrastructure_ReturnsExpectedException()
        {
            var    gameBoard   = new GameBoard(BoardSizes.Standard);
            var    queryEngine = new GameBoardQuery(gameBoard);
            var    playerId    = Guid.NewGuid();
            Action action      = () => { queryEngine.GetValidConnectionsForPlayerInfrastructure(playerId); };

            action.ShouldThrow <Exception>().Message.ShouldBe($"Player {playerId} not recognised.");
        }
Beispiel #3
0
        public void GetLocationsWithBestYield_FirstFiveLocationsFromEmptyBoard_ReturnsExpectedLocations()
        {
            var gameBoard   = new GameBoard(BoardSizes.Standard);
            var queryEngine = new GameBoardQuery(gameBoard);

            var results = queryEngine.GetLocationsWithBestYield(5);

            results.ShouldContainExact(new[] { 12u, 31u, 35u, 41u, 43u });
        }
Beispiel #4
0
        public void GetLocationsWithBestYield_FiveLocationsWhenLocationIsTaken_ReturnsExpectedLocations(uint settlementLocation, uint roadEndLocation, uint firstLocation, uint secondLocation, uint thirdLocation, uint fourthLocation, uint fifthLocation)
        {
            var gameBoard = new GameBoard(BoardSizes.Standard);

            gameBoard.PlaceStartingInfrastructure(Guid.NewGuid(), settlementLocation, roadEndLocation);
            var queryEngine = new GameBoardQuery(gameBoard);

            var results = queryEngine.GetLocationsWithBestYield(5);

            results.ShouldContainExact(new[] { firstLocation, secondLocation, thirdLocation, fourthLocation, fifthLocation });
        }
Beispiel #5
0
        public Bot(string name, Guid gameId, IPlayerRequestReceiver playerActionReceiver, GameBoardQuery gameBoardQuery)
        {
            this.Name   = name;
            this.gameId = gameId;
            this.playerActionReceiver = playerActionReceiver;
            this.gameBoardQuery       = gameBoardQuery;

            this.jsonSerializerSettings = new JsonSerializerSettings();
            this.jsonSerializerSettings.ReferenceLoopHandling      = ReferenceLoopHandling.Serialize;
            this.jsonSerializerSettings.PreserveReferencesHandling = PreserveReferencesHandling.Objects;
            this.jsonSerializerSettings.TypeNameHandling           = TypeNameHandling.Objects;

            this.processingTask = Task.Factory.StartNew(o => { this.ProcessAsync(); }, CancellationToken.None);
        }
Beispiel #6
0
        public void GetValidConnectionsForPlayerInfrastructure_StartingInfrastructurePlaced_ExpectedConnections()
        {
            var gameBoard   = new GameBoard(BoardSizes.Standard);
            var queryEngine = new GameBoardQuery(gameBoard);
            var playerId    = Guid.NewGuid();

            gameBoard.PlaceStartingInfrastructure(playerId, 0, 8);
            gameBoard.PlaceStartingInfrastructure(playerId, 19, 18);

            var results = queryEngine.GetValidConnectionsForPlayerInfrastructure(playerId);

            var expected = new HashSet <Connection>();

            expected.Add(new Connection(0, 1));
            expected.Add(new Connection(8, 7));
            expected.Add(new Connection(8, 9));
            expected.Add(new Connection(17, 18));
            expected.Add(new Connection(18, 29));
            expected.Add(new Connection(9, 19));
            expected.Add(new Connection(19, 20));
            results.ShouldMatch(expected);
        }
Beispiel #7
0
        private GameManagerToken LaunchGame(GameSessionDetails gameSessionDetails)
        {
            if (gameSessionDetails == null)
            {
                throw new ArgumentNullException(nameof(gameSessionDetails));
            }

            var playerIds = new Queue <Guid>();

            var connectionIdsByPlayerId = new Dictionary <Guid, string>();

            gameSessionDetails.Players.ForEach(player =>
            {
                connectionIdsByPlayerId.Add(player.Id, player.ConnectionId);
                playerIds.Enqueue(player.Id);
            });

            var gameBoard      = new GameBoard(BoardSizes.Standard);
            var gameBoardQuery = new GameBoardQuery(gameBoard);

            Dictionary <Guid, IEventReceiver> eventReceiversByPlayerId = null;
            List <Bot> bots = null;

            if (gameSessionDetails.TotalBotCount > 0)
            {
                bots = new List <Bot>();
                eventReceiversByPlayerId = new Dictionary <Guid, IEventReceiver>();
                while (gameSessionDetails.TotalBotCount-- > 0)
                {
                    var bot = new Bot("Bot #" + (bots.Count + 1), gameSessionDetails.Id, this, gameBoardQuery);
                    bots.Add(bot);
                    eventReceiversByPlayerId.Add(bot.Id, bot);
                    playerIds.Enqueue(bot.Id);
                }
            }

            var eventSender = new EventSender(this.gameHubContext, connectionIdsByPlayerId, eventReceiversByPlayerId);

            var gameManager = new GameManager(
                gameSessionDetails.Id,
                gameSessionDetails.PlayerStarts ? new PlayerStartsNumberGenerator() : this.numberGenerator,
                gameBoard,
                new DevelopmentCardHolder(),
                new PlayerFactory(),
                eventSender,
                new GameOptions
            {
                Players           = gameSessionDetails.NumberOfPlayers,
                TurnTimeInSeconds = gameSessionDetails.TurnTimeoutInSeconds
            }
                );

            gameManager.SetIdGenerator(() => { return(playerIds.Dequeue()); });

            gameSessionDetails.Players.ForEach(player =>
            {
                gameManager.JoinGame(player.UserName);
            });

            if (bots != null)
            {
                bots.ForEach(bot =>
                {
                    gameManager.JoinGame(bot.Name);
                });
            }

            return(new GameManagerToken(gameManager, gameManager.StartGameAsync(), eventSender));
        }