public void GetAllFields_FieldsNumberEqualsFieldsNumberFromGameSettings() { _fixture.Customizations.Add( new RandomNumericSequenceGenerator(0, 9)); for (int i = 0; i < 20; i++) { var ship1 = _fixture.CreateMany <Coordinates>(5).ToList(); var ship2 = _fixture.CreateMany <Coordinates>(4).ToList(); var ship3 = _fixture.CreateMany <Coordinates>(4).ToList(); _shipBuilder.Build(Arg.Is <int>(x => x == 4 || x == 5), Arg.Any <IEnumerable <Coordinates> >()) .Returns(ship1, ship2, ship3); _grid.Initialize(); Dictionary <Coordinates, FieldType> allFields = _grid.GetAllFields(); allFields.Count.Should().Be((int)Math.Pow(_gameSettings.GridSize, 2)); } }
private void Initialise(Size boardSize, IEnumerable <ShipRequest> shipRequests) { _logger.LogDebug("Build board"); _gameBoard = _gameBoardBuilder.Build(boardSize); _logger.LogDebug("Build ships"); _ships = _shipBuilder.Build(shipRequests); _logger.LogDebug("Place ships"); _shipPlacementService.PlaceShips(_ships, _gameBoard); }
public IEnumerable <List <Cell> > CalculatePossiblePlacements(Ship ship, bool[][] grid) { var cellsForPlacement = GetCellsForPlacement(grid); var relativeShipCells = shipBuilder.Build(ship); for (var y = 0; y < grid.Length; y++) { for (var x = 0; x < grid.Length; x++) { var startingCell = new Cell(y, x); var shipCells = GetAbsoluteCells(relativeShipCells, startingCell); if (CanShipBePlaced(cellsForPlacement, shipCells)) { yield return(shipCells); } } } }
public void Initialize() { foreach (var shipType in _gameSettings.ShipTypes) { var ship = _shipBuilder.Build(shipType, _ships.SelectMany(n => n)); _ships.Add(ship); } for (int i = 0; i < _gameSettings.GridSize; i++) { for (int j = 0; j < _gameSettings.GridSize; j++) { if (!_ships.SelectMany(n => n).Contains(new Coordinates(i, j))) { _fields[new Coordinates(i, j)] = FieldType.See; } else { _fields[new Coordinates(i, j)] = FieldType.Ship; } } } }
public void Build_ShouldReturnCoordinatesNumberEqualShipLength(int shipLength) { _builder.Build(shipLength, _existingShips).Count.Should().Be(shipLength); }