Implemented isLegalPosition method