All pastes #1940472 Raw Edit

Unnamed

public text v1 · immutable
#1940472 ·published 2010-09-14 12:01 UTC
rendered paste body
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;
	}
	
}