public void NotBuildField_WhenThereAreTooManyShips() { shipsCount = new Dictionary <ShipType, int> { { ShipType.Submarine, 1 }, { ShipType.Destroyer, 2 } }; rules = new GameRules(fieldSize, shipsCount); builder = new GameFieldBuilder(rules); var cells = new[] { new CellPosition(0, 0), new CellPosition(7, 2), new CellPosition(9, 7), new CellPosition(6, 4), new CellPosition(6, 5), new CellPosition(2, 1), new CellPosition(2, 2) }; foreach (var cell in cells) { builder.TryAddShipCell(cell); } foreach (var shipType in Enum.GetValues(typeof(ShipType)).Cast <ShipType>()) { shipsCount[shipType] = 0; } builder.Build().Should().BeNull(); }
public void SayCorrectSize() { fieldSize = new Size(12, 2); builder = new GameFieldBuilder(new GameRules(fieldSize, new Dictionary <ShipType, int>())); builder.Size.Should().Be(fieldSize); }
public void SetUp() { rules = GameRules.Default; fieldSize = rules.FieldSize; shipsCount = rules.ShipsCount.ToDictionary(x => x.Key, x => x.Value); builder = new GameFieldBuilder(rules); }
public void BuildField_WhenDataCorrect() { shipsCount = new Dictionary <ShipType, int> { { ShipType.Submarine, 3 }, { ShipType.Destroyer, 2 } }; rules = new GameRules(fieldSize, shipsCount); builder = new GameFieldBuilder(rules); var cells = new[] { new CellPosition(0, 0), new CellPosition(7, 2), new CellPosition(9, 7), new CellPosition(6, 4), new CellPosition(6, 5), new CellPosition(2, 1), new CellPosition(2, 2) }; foreach (var cell in cells) { builder.TryAddShipCell(cell); } builder.Build().Should().NotBeNull(); }
public void ReturnCorrectShipsLeftCounter_WhenAllShipsUsed() { shipsCount = new Dictionary <ShipType, int> { { ShipType.Submarine, 3 }, { ShipType.Destroyer, 2 } }; rules = new GameRules(fieldSize, shipsCount); builder = new GameFieldBuilder(rules); var cells = new[] { new CellPosition(0, 0), new CellPosition(7, 2), new CellPosition(9, 7), new CellPosition(6, 4), new CellPosition(6, 5), new CellPosition(2, 1), new CellPosition(2, 2) }; foreach (var cell in cells) { builder.TryAddShipCell(cell); } foreach (var shipType in Enum.GetValues(typeof(ShipType)).Cast <ShipType>()) { shipsCount[shipType] = 0; } builder.ShipsLeft.Should().BeEquivalentTo(shipsCount); }
private static IGameField FromLines(GameRules rules, string[] lines) { var builder = new GameFieldBuilder(rules); for (var row = 0; row < rules.FieldSize.Height; row++) { for (var column = 0; column < rules.FieldSize.Width; column++) { if (lines[row][column] == 'X') { builder.TryAddShipCell(new CellPosition(row, column)); } } } return(builder.Build()); }
protected IGameField GenerateNewPrediction() { var builder = new GameFieldBuilder(); foreach (var position in OpponentFieldKnowledge.EnumeratePositions()) { if (OpponentFieldKnowledge[position] == true) { builder.TryAddShipCell(position); } } var generator = new RandomFieldGenerator(builder); var damagedShip = FindDamagedShip().ToList(); if (damagedShip.Any()) { foreach (var cell in damagedShip) { builder.TryRemoveShipCell(cell); } var variants = new[] { 4, 3, 2, 1 }.SelectMany(x => new[] { new { Ship = (ShipType)x, Vertical = true }, new { Ship = (ShipType)x, Vertical = false } }).SelectMany(x => GenerateContinuesForDamagedShip(damagedShip, builder, x.Vertical, x.Ship)); foreach (var variant in variants) { builder.TryAddFullShip(variant.Item1, variant.Item2, variant.Item3); var prediction = generator.Generate(x => OpponentFieldKnowledge[x] != false); if (prediction != null) { return(prediction); } builder.TryRemoveFullShip(variant.Item1, variant.Item2, variant.Item3); } } return(generator.Generate(x => OpponentFieldKnowledge[x] != false)); }
public void BuildCorrectField() { shipsCount = new Dictionary <ShipType, int> { { ShipType.Submarine, 3 }, { ShipType.Destroyer, 2 } }; rules = new GameRules(fieldSize, shipsCount); builder = new GameFieldBuilder(rules); var cells = new[] { new CellPosition(0, 0), new CellPosition(7, 2), new CellPosition(9, 7), new CellPosition(6, 4), new CellPosition(6, 5), new CellPosition(2, 1), new CellPosition(2, 2) }; foreach (var cell in cells) { builder.TryAddShipCell(cell); } foreach (var shipType in Enum.GetValues(typeof(ShipType)).Cast <ShipType>()) { shipsCount[shipType] = 0; } var field = builder.Build(); foreach (var cell in field.EnumeratePositions()) { cells.Contains(cell).Should().Be(field[cell] is IShipCell); } }
void Start() { GameFieldBuilder gameFieldBuilder = new GameFieldBuilder(); gameField = gameFieldBuilder.BuildGameField(width, height, gameFieldCellPrefab); }