Home > database >  Function need a loop solution
Function need a loop solution

Time:12-29

I have this function and i wanna do when function "play" is executed one time that the function bot stop any idea but i still need to check all the matrix values because it can be one of all the positions.function play is a void function to.

void bot(char board[8][8],char color){
    int i;
    char j;
    for(i=0;i<8;i  ){
        for(j=0;j<8;j  ){
            if (board[i][j]=='.'){
                if (flanked(board,i,j,color)>0){
                    play(board,i,j,color);
                }
            }        
        }
    }
    
}

CodePudding user response:

If you want the call to bot to end after a single call to play, just return at that time.

void bot(char board[8][8],char color){
    int i;
    char j;
    for(i=0;i<8;i  ){
        for(j=0;j<8;j  ){
            if (board[i][j]=='.'){
                if (flanked(board,i,j,color)>0){
                    play(board,i,j,color);
                    return;
                }
            }        
        }
    }
}
  • Related