Hi, i am making a checkers game..and i have used array of enumerations to declare the states of the board..
enum state {state_black,state_white,state_board_m,state_board_im,state_black_k,state_white_k}; // shows states of pieces on board
// ( white, white_king, black, black_king and the board surface )
state arr[8][8]; // 8 x 8 state type array it takes values : (black,white,board)
My other checkers are declared on the board by the following code..
for(int i=0;i<8;i++) // loop to declare the states in the array (black,white,board)
{
for(int j=0;j<8;j++)
{
if( // conditions to declare black piece
(i==0 && (j==1 || j==3 || j==5 || j==7)) ||
(i==1 && (j==0 || j==2 || j==4 || j==6)) ||
(i==2 && (j==1 || j==3 || j==5 || j==7))
)
{
arr[i][j]=state_black;
When i move the king checker back to the board it turns back into normal checker....how can i make it a constant king..so that once it becomes king it does not change back no matter where i move it....
When i move the king checker back to the board it turns back into normal checker....how can i make it a constant king..so that once it becomes king it does not change back no matter where i move it....
Your move routine is probably incorrect. I'd guess you're setting the state on the destination field to e.g. state_black instead of the value on the source field.
And your initialization can be done with much less code:
1 2 3 4 5 6 7 8
for (int i=0;i<8;i++)
for (int j=0;j<8;j++)
{
if (j>=5 && (i+j)%2)arr[i][j]=state_white;
elseif (j<3 && (i+j)%2)arr[i][j]=state_black;
elseif ((i+j)%2==0)arr[i][j]=state_board_im;
else arr[i][j]=state_board_m;
}
i can move it....the problem is that when a normal checker turns to a king it should remain a king ...but when it becomes king when reaching the baseline of the opponent...then after that when i move it back to the other rows of the board it changes back to normal checker which should not happen... i want to know how it should retain being in the king state after being transformed to king...