I have this list of at least seven else-if
, when. When their condition is met, I change the same boolean boolean is_attacked
to truetrue
. This should be simple but I can't figure out in what way I can achieve the same onin a more readable way.
if(request_is_attacked){
if(as_knight){
if(piece_abs_val==2){//knight
is_attacked=true;
}
}else if(piece_abs_val==6){//king
if(i==0){
is_attacked=true;
}
}else if(piece_abs_val==5){//queen
is_attacked=true;
}else if(piece_direction%2){
if(piece_abs_val==4){//rook
is_attacked=true;
}
}else if(piece_abs_val==3){//bishop
is_attacked=true;
}else if(i==0 && piece_abs_val==1){
if(piece_val!=-1){//w_pawn
if(piece_direction==4 || piece_direction==6){
is_attacked=true;
}
}else{//b_pawn
if(piece_direction==2 || piece_direction==8){
is_attacked=true;
}
}
}
}
For more context, this is happening inside a loop (hence the i
), when the i
is the first it means it is one square apart (i==0
), so pawnsPawns and kingsKings use this, but this information shouldn't matter much.
Also, when piece_direction%2
is truetrue
, we are moving in a +
(that's why I check for rooksRooks), else it means we are in moving x
direction, so I proceed to check for bishopsBishops and pawnsPawns.