///////////////////////////////////////
//Pawn Movement
///////////////////////////////////////

function pawn(location){
getlocation(location);

if(document.getElementById(location-10).alt == "nothing" || document.getElementById(location-10).alt == "nothing"){
--h;
parray.push(h+l);
blockcolor.push(h/1+l/1);
altarray.push(document.getElementById(h+l).alt);
document.getElementById(h+l).src="psq/possiblemove.png";//maynotwork

if(pawnmoved(location) && document.getElementById(location-20).alt == "nothing"){
--h;
parray.push(h+l);
blockcolor.push(h/1+l/1);
altarray.push(document.getElementById(h+l).alt);
document.getElementById(h+l).src="psq/possiblemove.png";//maynotwork
}
}

getlocation(location);
if(!yourpiece(location-11) && document.getElementById(location-11).alt != "nothing"){
--h;
--l;
defaultfunction()
}

getlocation(location);
if(!yourpiece(location-9) && document.getElementById(location-9).alt != "nothing"){
--h;
l++;
defaultfunction()
}
}


///////////////////////////////////////
//Rook Movement
///////////////////////////////////////
function rook(location){

//Up
getlocation(location);
endloop="0";
while(h>1 && endloop!="1"){
--h;
defaultfunction();
}

//Down
getlocation(location);
endloop="0";
while(h<8 && endloop!="1"){
h++;
defaultfunction();
}

//Left
getlocation(location);
endloop="0";
while(l>1 && endloop!="1"){
--l;
defaultfunction();
}

//Right
getlocation(location);
endloop="0";
while(l<8 && endloop!="1"){
l++;
defaultfunction();
}
}//if removed this works


///////////////////////////////////////
//Knight Movement
///////////////////////////////////////
function knight(location){
getlocation(location);

h=h-2;
l++;
knightfunction();
l=l-2;
knightfunction();
h++;
--l;
knightfunction();
h=h-0+2;
knightfunction();
h++;
l++;
knightfunction();
l=l-0+2;
knightfunction();
--h;
l++;
knightfunction();
h=h-2;
knightfunction();
}

///////////////////////////////////////
//Bishop Movement
///////////////////////////////////////
function bishop(location){

//upper left
getlocation(location);
endloop="0";
while(!(l<2 || h<2 || l>9 || h>9) && endloop!="1"){////////////upper left movement
--h;
--l;
defaultfunction();
}

//lower right
getlocation(location);
endloop="0";
while(!(l<0 || h<0 || l>7 || h>7) && endloop!="1"){////////////upper left movement
h++;
l++;
defaultfunction()
}

//lower left
getlocation(location);
endloop="0";
while(!(l<2 || h<0 || l>9 || h>7) && endloop!="1"){////////////upper left movement
h++;
--l;
defaultfunction()
}

//upper right
getlocation(location);
endloop="0";
while(!(l<0 || h<2 || l>7 || h>9) && endloop!="1"){////////////upper left movement
--h;
l++;
defaultfunction()
}
}

///////////////////////////////////////
//King Movement
///////////////////////////////////////
function king(location){

getlocation(location);
h++;
l++
defaultfunction();

getlocation(location);
h++;
defaultfunction();

getlocation(location);
l++;
defaultfunction();

getlocation(location);
h++;
--l;
defaultfunction();

getlocation(location);
--h;
l++;
defaultfunction();

getlocation(location);
--h;
defaultfunction();

//Up
getlocation(location);
--l;
defaultfunction();

//Up Left
getlocation(location);
--h;
--l;
defaultfunction();
}

///////////////////////////////////////
//Queen Movement
///////////////////////////////////////
function queen(location){

getlocation(location);
endloop="0";
while(!(l<2 || h<2 || l>9 || h>9) && endloop!="1"){////////////upper left movement
h++;
l++;
defaultfunction();
}

getlocation(location);
endloop="0";
while(!(l<2 || h<2 || l>9 || h>9) && endloop!="1"){////////////upper left movement
h++;
defaultfunction();
}

getlocation(location);
endloop="0";
while(!(l<2 || h<2 || l>9 || h>9) && endloop!="1"){////////////upper left movement
l++;
defaultfunction();
}

getlocation(location);
endloop="0";
while(!(l<2 || h<2 || l>9 || h>9) && endloop!="1"){////////////upper left movement
h++;
--l;
defaultfunction();
}

getlocation(location);
endloop="0";
while(!(l<2 || h<2 || l>9 || h>9) && endloop!="1"){////////////upper left movement
--h;
l++;
defaultfunction();
}

getlocation(location);
endloop="0";
while(!(l<2 || h<2 || l>9 || h>9) && endloop!="1"){////////////upper left movement
--h;
defaultfunction();
}

getlocation(location);
endloop="0";
while(!(l<2 || h<2 || l>9 || h>9) && endloop!="1"){////////////upper left movement
--l;
defaultfunction();
}

getlocation(location);
endloop="0";
while(!(l<2 || h<2 || l>9 || h>9) && endloop!="1"){////////////upper left movement
--h;
--l;
defaultfunction();
}
}






///////////////////////////////////////
//FUNCTIONS
///////////////////////////////////////

///////////////////////////////////////
//Rook, Bishop and King Function
///////////////////////////////////////
function defaultfunction(){
moveto=h+''+l;
if(ongameboard() && !yourpiece(moveto)){
parray.push(moveto);
blockcolor.push(h/1+l/1);
altarray.push(document.getElementById(moveto).alt);
if(document.getElementById(moveto).alt == "nothing"){document.getElementById(moveto).src="psq/possiblemove.png";}//maynotwork
else{document.getElementById(moveto).src = "psq/" + opponentcolor + document.getElementById(moveto).alt + ".png";endloop="1";}
}else{endloop="1";};
}

///////////////////////////////////////
//Knight Function
///////////////////////////////////////
function knightfunction(){
moveto=h+''+l;
if(ongameboard() && !yourpiece(moveto)){
blockcolor.push(h/1+l);
altarray.push(document.getElementById(moveto).alt);
parray.push(moveto);
if(document.getElementById(moveto).alt == "nothing"){document.getElementById(moveto).src = "psq/possiblemove.png";}//maynotwork
else{document.getElementById(moveto).src = "psq/" + opponentcolor + document.getElementById(moveto).alt + ".png";}
}
}

///////////////////////////////////////
//Test if pawn moved
///////////////////////////////////////
function pawnmoved(a){
pawnrow=a;
if(pawnrow > 70){return true}//if it's on the 7th row essentially
}