package Battleship; import Battleship.Ship.Direction; public class AI { public AI() { } public boolean generateShip(Board board) { int boardHeight = board.getHeight(); int boardWidth = board.getWidth(); int x, y; int length; int randomDir; Direction direction; Direction[] dirArray = {Direction.NORTH, Direction.SOUTH, Direction.EAST, Direction.WEST}; length = (int)(Math.random()*5 + 2); randomDir = (int)(Math.random()*4); direction = dirArray[randomDir]; x = (int)(Math.random()*(boardWidth-1)); y = (int)(Math.random()*(boardHeight-1)); boolean b = board.placeShip(x, y, length, dirArray[randomDir]); return b; } }