import java.awt.*;

public class Square implements Shape
{
	public static int num_comps = 0;

	private int center_x;
	private int center_y;

	private int up_left_x;
	private int up_left_y;

	private int length;
	private int magnification;
	private int mut_scale;

	public Square(int x, int y, int length, int magnify)
	 {
		 this.length = length;
		 magnification = magnify;
		 move(x,y);
		 mut_scale = 5;
     }

    public Shape offspring()
       {
		  return(new Square(center_x,center_y,length,magnification));
	   }

    public void move(int new_x, int new_y)
      {
		center_x = new_x;
		center_y = new_y;

		up_left_x = center_x - length/2;
		up_left_y = center_y - length/2;

      }

    public void mutate()
      {
	     center_x += (int) (SqueezePanel.rand.nextGaussian() * mut_scale);
	     if(center_x < 30) center_x = 30;
	        else if(center_x > 69) center_x = 69;

	     center_y += (int) (SqueezePanel.rand.nextGaussian() * mut_scale);
	     if(center_y < 30) center_y = 30;
	        else if(center_y > 69) center_y = 69;
      }

	public void paint(Graphics g)
	  {
		  Color oldColor = g.getColor();
		  g.setColor(Color.green);
		  g.drawRect(up_left_x*magnification,up_left_y*magnification,
		       	     length*magnification,length*magnification);
		  g.setColor(oldColor);
	  }

	public int get_center_x()  { return center_x;}
	public int get_center_y()  { return center_y;}

	public int overlap_amount(Shape sh)
	  {
		  Square other = (Square) sh;

		  int other_x = other.get_center_x();
		  int other_y = other.get_center_y();

		  int x_diff = Math.abs(center_x - other_x);
		  int x_overlap = length - x_diff;
		  if (x_overlap < 0) x_overlap = 0;

		  int y_diff = Math.abs(center_y - other_y);
		  int y_overlap = length - y_diff;
		  if (y_overlap < 0) y_overlap = 0;

		  num_comps++;

		  return x_overlap * y_overlap;
		//  if (x_overlap > 0 && y_overlap > 0) return 1;    //  Temp., for testing
		//   			else return 0;							// idea for MAX Clique
	  }

	public boolean overlap(Shape sh)
	   {
		  return overlap_amount(sh) > 0;
	   }

	public boolean right_of(int x)
	   { return x < up_left_x+length; }
	public boolean left_of(int x)
	   { return up_left_x < x; }
	public boolean above(int y)
	   { return up_left_y < y; }
	public boolean below(int y)
	   { return y < up_left_y + length; }


	public static void main(String [] arguments)
	  {

	  }

}
