public void MakeCpuMovement_WhenGridWithoutHitsButWithShipsAndMisses_ShouldMakeValidMovement() { // Arrange var grid = new Grid(); grid.AddShip(new Ship(new Coordinates(1, 0), Orientation.Horizontal, 10)); grid.AddShip(new Ship(new Coordinates(3, 0), Orientation.Horizontal, 10)); grid.AddShip(new Ship(new Coordinates(5, 0), Orientation.Horizontal, 10)); grid.AddShip(new Ship(new Coordinates(7, 0), Orientation.Horizontal, 10)); for (int row = 1; row <= 7; row += 2) { for (int column = 0; column < 10; column++) { grid.CheckCell(row, column); } } var logic = new DefaultCpuMovementLogic(); // Act var movement = logic.MakeCpuMovement(grid); // Assert Assert.AreEqual(CellStatus.Miss, movement.CellStatus); Assert.AreEqual(9, movement.Coordinates.Row); }
public void MakeCpuMovement_WhenGridWithoutHits_ShouldMakeRandomMovement() { // Arrange var grid = new Grid(); var logic = new DefaultCpuMovementLogic(); // Act var movement = logic.MakeCpuMovement(grid); // Assert var numberOfEmptinesses = 0; for (int row = 0; row < 10; row++) { for (int column = 0; column < 10; column++) { if (grid[row, column] == CellStatus.Empty) { numberOfEmptinesses++; } } } Assert.AreEqual(99, numberOfEmptinesses); Assert.AreEqual(CellStatus.Miss, movement.CellStatus); }
public void MakeCpuMovement_WhenGridWithSomeHitsOfVerticalShips_ShouldMakeMovementsInCorrectOrder() { // Arrange var grid = new Grid(); grid.AddShip(new Ship(new Coordinates(0, 0), Orientation.Vertical, 3)); grid.AddShip(new Ship(new Coordinates(3, 4), Orientation.Vertical, 3)); grid.AddShip(new Ship(new Coordinates(7, 9), Orientation.Vertical, 3)); grid.CheckCell(0, 0); grid.CheckCell(4, 4); grid.CheckCell(9, 9); var logic = new DefaultCpuMovementLogic(); // Act // Assert // ship no 1 var movement = logic.MakeCpuMovement(grid); Assert.AreEqual(CellStatus.Miss, movement.CellStatus); Assert.AreEqual(0, movement.Coordinates.Row); Assert.AreEqual(1, movement.Coordinates.Column); movement = logic.MakeCpuMovement(grid); Assert.AreEqual(CellStatus.Hit, movement.CellStatus); Assert.AreEqual(1, movement.Coordinates.Row); Assert.AreEqual(0, movement.Coordinates.Column); movement = logic.MakeCpuMovement(grid); Assert.AreEqual(CellStatus.Sunk, movement.CellStatus); Assert.AreEqual(2, movement.Coordinates.Row); Assert.AreEqual(0, movement.Coordinates.Column); //ship no 2 movement = logic.MakeCpuMovement(grid); Assert.AreEqual(CellStatus.Hit, movement.CellStatus); Assert.AreEqual(3, movement.Coordinates.Row); Assert.AreEqual(4, movement.Coordinates.Column); movement = logic.MakeCpuMovement(grid); Assert.AreEqual(CellStatus.Miss, movement.CellStatus); Assert.AreEqual(2, movement.Coordinates.Row); Assert.AreEqual(4, movement.Coordinates.Column); movement = logic.MakeCpuMovement(grid); Assert.AreEqual(CellStatus.Sunk, movement.CellStatus); Assert.AreEqual(5, movement.Coordinates.Row); Assert.AreEqual(4, movement.Coordinates.Column); //ship no 3 movement = logic.MakeCpuMovement(grid); Assert.AreEqual(CellStatus.Hit, movement.CellStatus); Assert.AreEqual(8, movement.Coordinates.Row); Assert.AreEqual(9, movement.Coordinates.Column); movement = logic.MakeCpuMovement(grid); Assert.AreEqual(CellStatus.Sunk, movement.CellStatus); Assert.AreEqual(7, movement.Coordinates.Row); Assert.AreEqual(9, movement.Coordinates.Column); }