public void CheckShipCoordinatesY_ShipCoordinatesGreaterThan0_ReturnsFalse(int length, int x, int y) { matrix = DummyShips(matrix); var check = Coordinates.CheckShipCoordinatesY(matrix, length, x, y); check.Should().BeFalse(); }
public void CheckShipCoordinatesY_ShipCoordinatesEqual0_ReturnsTrue(int length, int x, int y) { matrix = DummyShips(matrix); var check = Coordinates.CheckShipCoordinatesY(matrix, length, x, y); check.Should().BeTrue(); }
private static int[,] RandomShipAllocation(int[,] matrix, int rows, int shipLength, int shipNumber) { var coordinates = Coordinates.RandomCoordinates(matrix); var x = coordinates.Item1; var y = coordinates.Item2; // run till ship gets allocated coordinates while (true) { // horizontal // right if (y + shipLength <= rows) { if (Coordinates.CheckShipCoordinatesY(matrix, shipLength, x, y)) { Coordinates.WriteShipCoordinatesY(matrix, shipLength, x, y, shipNumber); return(matrix); } } // left if (y - (shipLength - 1) >= 0) { if (Coordinates.CheckShipCoordinatesY(matrix, shipLength, x, y - (shipLength - 1))) { Coordinates.WriteShipCoordinatesY(matrix, shipLength, x, y - (shipLength - 1), shipNumber); return(matrix); } } // vertically // down if (x + shipLength <= rows) { if (Coordinates.CheckShipCoordinatesX(matrix, shipLength, x, y)) { Coordinates.WriteShipCoordinatesX(matrix, shipLength, x, y, shipNumber); return(matrix); } } // up if (x - (shipLength - 1) >= 0) { if (Coordinates.CheckShipCoordinatesX(matrix, shipLength, x - (shipLength - 1), y)) { Coordinates.WriteShipCoordinatesX(matrix, shipLength, x - (shipLength - 1), y, shipNumber); return(matrix); } } // new coordinates need to be set up var newCoordinates = Coordinates.RandomCoordinates(matrix); x = newCoordinates.Item1; y = newCoordinates.Item2; } }