I'm making a class that uses a 2D array to move a queen around a chess board. The real challenge, I think, is to create a rule that determines which moves are illegal and which moves are legal. If statements are what I think would work.
My method accepts the coordinates of
- an element that will be moved (the Queen) -> from row and from column
- the square the Queen will be moved to -> to row and to column
public String move(int fr, int fc, int tr, int tc)
{
if ((fr < 0 && fr > 7) || (fc < 0 && fc > 7))
{
return "Invalid from coordinate";
}
if ((tr < 0 && tr > 7) || (tc < 0 && tc > 7))
{
return "Invalid to coordinate";
}
if (board[fr][fc] == SPACE)
{
return "Queen is not at from coordinate";
}
if (board[fr][fc] == board[tr][tc])
{
return "Cannot move to same square";
}
}
The last two things I want to accomplish are to
1) make a rule that returns an error if the queen's move is illigal
2) return a success message if the move is ok
Can anyone push me the right way?