import javax.swing.ImageIcon;


public class King extends Piece{
	Chess chess;

	


	public boolean wasPressed(int clickx, int clicky) {
		return false;
	
		}
	//Function that the rating class uses to determine score in relation to King. Creates a list of safe moves the king can make in order to avoid check.
	public static String posibleA(int i) {
        String list="";
        int r=i/8, c=i%8;
        for (int j=0;j<9;j++) {
            if (j!=4) {
                try {
                    if (Chess.pieces[r][c].canMove(r,c, r-1+j/3, c-1+j%3)) {
                    	
                     
                        if (BoardMouseListener.kingSafe()) {
                            list=list+r+c+(r-1+j/3)+(c-1+j%3)+Chess.pieces[r-1+j/3][c-1+j%3].pieceletter;
                        }
                        
                        
                    }
                } catch (Exception e) {}
            }
           
            
        }
        //need to add casting later
        return list;
    }

	


	public boolean canMove(int x, int y, int finx, int finy) {
		// TODO Auto-generated method stub
		//move king forward and backward
		if ((Math.abs(y-finy)==1 && Math.abs(x-finx)==0) && ( (" ".equals(chess.pieces[finy][finx].pieceletter))||chess.pieces[finy][finx].isWhite!=chess.pieces[y][x].isWhite)){
		
				return true;
			
		}
		//move king side to side
		else if ((Math.abs(x-finx)==1 && Math.abs(y-finy)==0)&&((" ".equals(chess.pieces[finy][finx].pieceletter))||chess.pieces[finy][finx].isWhite!=chess.pieces[y][x].isWhite)){ 
			
				return true;
			
		}
		//move king diagionally
		else if ((Math.abs(x-finx)==1 && Math.abs(y-finy)==1) &&((" ".equals(chess.pieces[finy][finx].pieceletter)) || chess.pieces[finy][finx].isWhite!=chess.pieces[y][x].isWhite)){ 
			
				return true;
				//System.out.println(chess.pieces[finy][finx]+"it went through");
		}
			
		return false;
	}


	void drawPiece() {
		// TODO Auto-generated method stub
		
	}
	public King(boolean isWhite, Chess chess) {
		// TODO Auto-generated constructor stub
		//set king color
		//this.isWhite=isWhite;
		this.chess=chess;
		if (isWhite){
			img=new ImageIcon ("wking.gif");
			pieceletter="A";
			
		}
		else 
		{
			img=new ImageIcon ("bking.gif");
			pieceletter="a";
		}
	}
}

@@ -1010,16 +1010,608 @@
 ;%0A    %7D%0A
+    static void updatekingposition()%7B%0A%09%09int kingPositionC=0;%0A%09%09int kingPositionL=0;%0A%09%09%09%09%0A%09%09while (!%22A%22.equals(Chess.pieces%5BkingPositionC/8%5D%5BkingPositionC%258%5D.pieceletter))%0A%09%09%7B%0A%09%09%09//System.out.println(%22A%22.equals(pieces%5BkingPositionC/8%5D%5BkingPositionC%258%5D.pieceletter));%0A%09%09%09%09%09kingPositionC++;%0A%09%09%09%09%0A%09%09%09%7D%0A%09%09while ( !%22a%22.equals(Chess.pieces%5BkingPositionL/8%5D%5BkingPositionL%258%5D.pieceletter)) %7B%0A%0A%09%09%09kingPositionL++;%0A    %09%09%7D%0A%09%09Chess.kingPositionC=kingPositionC;%0A%09%09Chess.kingPositionL=kingPositionL;%0A%09%09System.out.println(%22kingPositionC = %22+Chess.kingPositionC+%22 kingPositionL = %22+Chess.kingPositionL);%0A%09%7D%0A%0A
 %0A%09%0A%0A%0A%09pu

Update King.java