Checkers Game - Double Jump Check

This is My Code. I am Trying to Restrict the Checker to Jump When it Can. And It Should Give Error if at that Time any other checker is moved instead. It Works Well In other Cases, But If i Have Got 2 Jumps OR a Jump which can be made by using any of two checker, then it gives the same error to jump.



[b]///////////////////////////////////////////////////////////


for(int i=0;i<8;i++)
{
for(int j=0;j<8;j++)
{

if( j>=2 && j<2 )
{
if( ( arr[i][j] == state_white) &&
(( arr[i-1][j+1] == state_black &&
arr[i-2][j+2] == state_board_m ) &&
( mf_row != i || mf_column != j ))
)

{

cout<<"You Have to Jump ! \n\n\n\n\n";

Sleep(3000);

goto try_again;

}
}

else if( j>=2 && j<6 )
{
if (
( arr[i][j] == state_white) &&
( arr[i-1][j+1] == state_black &&
arr[i-2][j+2] == state_board_m ) &&
( mf_row != i || mf_column != j )
)
{

cout<<"You Have to Jump ! \n\n\n\n\n";

Sleep(3000);

goto try_again;

}
else if( (arr[i][j] == state_white) &&
( arr[i-1][j-1] == state_black &&
arr[i-2][j-2] == state_board_m ) &&
(mf_row != i || mf_column != j)
)
{
cout<<"You Have to Jump ! \n\n\n\n\n";
Sleep(3000);
goto try_again;
}


}

else if( j>=6 && j<=7)
{
if( ( arr[i][j] == state_white) &&
(( arr[i-1][j-1] == state_black &&
arr[i-2][j-2] == state_board_m ) &&
( mf_row != i || mf_column != j ))
)

{
cout<<"You Have to Jump ! \n\n\n\n\n";
Sleep(3000);
goto try_again;

}
}
}

}


///////////////////////////////////////
///[/b]





Please HElp me Out !! :)




It's partly a design issue, the simplest fix is to run this section of code, and use it to determine if you HAVE to jump, if you do, set a flag such has haveJump to true, then when it comes time to move, if the flag is true, only allow them to do moves that involve jumps.

When I say partly a design issue, I mean you are using c with class's instead of c++. A checker should be a class, and should know if it can, or can not jump.

edit: It also hurts that there's a goto statement, and we can't see where it's jumping to. Also, not that you should be too concerned with this right now, but you are checking squares that are entirely invalid for move locations. Also, even after you determine that a square does not contain a white piece, the code will then proceed to check again for a white piece in that same location 3 times in a row.

edit2: A second look at this, why are you running this code at all if the user chooses to jump? It looks to me that the user triest to select a move, then checks to see if a jump was possible, if so give the error, but if the user selects to make a jump, why would you run this code at all? Even if they have to jump (which they would), it doesn't matter, because they chose to jump anyways.
Last edited on
thank you so much for ur concern....

can u explain to me what flags are ? and i am not so good at using classes that is why i avoided it...

i will think it over again and will try to come up with a better logic ..thanks :)
Topic archived. No new replies allowed.