package Rectangles;

import ui.*;
import Rectangles.*;
import java.awt.Color;
import java.util.Random;
import java.util.Vector;

public final class Group3PlayerSL implements IFCPlayer {
	private static Color _playerColor = new Color( 0.0f, 0.0f, 1.0f );
	private Rectangles _rectangles = null;
	private TracebackRobot[] _robots;
	private boolean[][] _targetedOpponents;
	private static Random _randomizer = new Random();

	public Robot[] register( Rectangles __rectangles ) throws Exception {
		if( __rectangles == null ) {
			throw new Exception( "Game Object is null!" );
		}
		
		_rectangles = __rectangles;
		_robots = new TracebackRobot[_rectangles.numRobots()];
		_targetedOpponents = new boolean[_rectangles.numPlayers()][_rectangles.numRobots()];

		for( int i = 0; i < _rectangles.numRobots(); i++ ) {
			_robots[i] = new TracebackRobot( _randomizer.nextInt( _rectangles.size() ), 
				_randomizer.nextInt( _rectangles.size() ), _rectangles.indexOf( this ), 
				_rectangles 
			);
		}

		return( _robots );
	}

	public char[] move() throws Exception {
		if( _rectangles == null ) {
			throw new Exception( "Game Object is null!" );
		}

		if( _robots == null ) {
			throw new Exception( "Robots have not been registered!" );
		}

		char moves[] = new char[_rectangles.numRobots()];

		// collect each enemy robot's trail into an array
		Trail[][] enemyRobotTrails = Hunter.traceAllRobots( _rectangles, _rectangles.indexOf( this ) );

		for( int i = 0; i < moves.length; i++ ) {
			moves[i] = _robots[i].move( enemyRobotTrails, _targetedOpponents );
		}
		
		return( moves );
	}

	public String name() throws Exception {
		return( "Raging Bull" );
	}

	public boolean interactive() throws Exception {
		return( false );
	}

	public Color color() throws Exception {
		return( _playerColor );
	}
}
