ok...
Code:
int move_queen (Colour colour, int from_col, int from_row,
int to_col, int to_row)
{
if((from_row-to_row==0)&&(from_col-to_col==0))//check if same square
{printf("e1");
return 2;//return error
}
if((board[to_row][to_col].colour==colour)&&
(board[to_row][to_col].piece!=empty))
//check if destination has piece of same colour
{printf("e2");
return 2;//return error
}
int i;//initialization
int j;//initialization
if((to_col==from_col)&&(to_row!=from_row))//if vertical move
{
if((to_row-from_row)>0) //if upwards
for(i=1;i<(to_row-from_row);i++)//count in between spaces up
if (board[from_row+i][from_col].piece==empty||board[from_row+i][from_col].colour!=colour)
{
board[to_row][to_col].piece=queen;
board[to_row][to_col].colour=colour;
board[from_row][from_col].piece=empty;
board[from_row][from_col].colour=white;
return 0; //return success value
}
else
{printf("e3");
return 2; //return error value
}
}
else //if downwards
for(i=0;i<(from_row-to_row);i++)//count in between spaces down
{ if (board[from_row-i][from_col].piece!=empty)//if not a clear path
{printf("e4");
return 2; //return error value
}
else //move piece
{
board[to_row][to_col].piece=queen;
board[to_row][to_col].colour=colour;
board[from_row][from_col].piece=empty;
board[from_row][from_col].colour=white;
return 0; //return success value
}
}//end for
// }//end verticle move
if((to_row==from_row)&&(to_col!=from_col))//if horizontal move
{
if(to_col-from_col>=0)//if move right
for(i=1;i<(to_col-from_col);i++)//count in between spaces left
if(board[from_row][from_col+i].piece==empty)
{ printf("got here");
board[to_row][to_col].piece=queen;
board[to_row][to_col].colour=colour;
board[from_row][from_col].piece=empty;
board[from_row][from_col].colour=white;
printf("Here too");
return 0; //return success value
}
else
{printf("e5");
return 2;//return error value
}
else //if move left
{
for(i=1;i<(from_col-to_col);i++)
if(board[from_row][from_col-i].piece==empty)
{
board[to_row][to_col].piece=queen;
board[to_row][to_col].colour=colour;
board[from_row][from_col].piece=empty;
board[from_row][from_col].colour=white;
return 0; //return success value
}
else
{printf("e6");
return 2; //return an error value
}
} //end move left
}//end horizontal
if((abs(to_col-from_col))==(abs(to_row-from_row)))//if diagonal
{ printf("%d %d diagonal",(to_col-from_col),(to_row-from_row));
if((to_col-from_col)>0&&(to_row-from_row)>0) //*up and right
for(i=1;i<(to_col-from_col);i++) //count column
for(j=1;j<(to_row-from_row);j++) //count row
if(board[from_row+j][from_col+i].piece==empty)//if empty
{
printf("got here");
board[to_row][to_col].piece=queen;
board[to_row][to_col].colour=colour;
board[from_row][from_col].piece=empty;
board[from_row][from_col].colour=white;
printf("got here 2\n");
return 0; //return success value
}
else {printf("e8");
return 2;//return an error value
}
if(((to_col-from_col)>0)&&(to_row-from_row)<0) //down and right
{printf("........ this!");
for(i=1;i>(from_col-to_col);i++) //count column
{printf("past here");
for(j=1;j>(to_row-from_row);j++) //count row
{ printf("%d",(board[from_row-j][from_col+i].piece==empty));
if(board[from_row-j][from_col+i].piece==empty) //if empty
{
printf("down and Right");
board[to_row][to_col].piece=queen;
board[to_row][to_col].colour=colour;
board[from_row][from_col].piece=empty;
board[from_row][from_col].colour=white;
return 0; //return success value
}
else {printf("e9");
return 2;//return an error value
}
} } }
if((to_col-from_col)<0&&(to_row-from_row)>0) //*up and left
for(i=1;i,(to_col-from_col);i++)//count column
for(j=1;j<(to_row-from_row);j++) //count row
if(board[from_row+j][from_col-i].piece==empty)//if empty
{
printf("down and right repair");
board[to_row][to_col].piece=queen;
board[to_row][to_col].colour=colour;
board[from_row][from_col].piece=empty;
board[from_row][from_col].colour=white;
return 0; //return success value
}
else {printf("e10");
return 2;//return an error value
}
if((to_col-from_col)<0&&(to_row-from_row)<0) //*down and left
for(i=1;i<(from_col-to_col);i++) //count the column
for(j=1; j<(from_row-to_row);j++)//count the row
if(board[from_row-j][from_col-i].piece==empty)//if empty
{ printf("down and left");
board[to_row][to_col].piece=queen;
board[to_row][to_col].colour=colour;
board[from_row][from_col].piece=empty;
board[from_row][from_col].colour=white;
return 0; //return success value
}
else
{printf("error");
return 2; //return an error value
}
}//end if diagonal
} //end queens move