Esempio n. 1
0
chessGame::chessGame(chessPlayer *p1, chessPlayer *p2) : lIsGameInProgress(true)
{
    player1 = p1;
    player2 = p2;
    player1->setIsWhite(true);
    player2->setIsWhite(false);
    if (!player1->isHuman())
        connect(player1, SIGNAL(haveMove()), this, SLOT(tM1()));
    if (!player2->isHuman())
        connect(player2, SIGNAL(haveMove()), this, SLOT(tM2()));
    cantStep = !player1->isHuman();
    player1->think(state);
}
Esempio n. 2
0
int main(void){
    int dimension;
    char board[26][26];
    int i,j;
    int out = 0;
    char row, col;
    char colour, diffColour;
    int deltaRow, deltaCol;
    int copy[26][26];
    printf("Enter the board dimension: ");
    scanf("%d",&dimension);
    
    
    for (i=0;i<dimension;i++){
        for (j=0;j<dimension;j++)
            board[i][j]='U';    //first set all the elements 'U'
    }
    
    
    board[dimension/2-1][dimension/2-1] = 'W';
    board[dimension/2-1][dimension/2] = 'B';
    board[dimension/2][dimension/2-1] = 'B';
    board[dimension/2][dimension/2] = 'W';  //define array in the range of dimension
    
    for(i=0;i<dimension;i++){
        for(j=0;j<dimension;j++){
            copy[i][j]=0;
        }
    }
    
    printf("Computer plays (B/W) : ");
    scanf(" %c",&colour);
    printBoard(board, dimension);   //print the board out
    
    if (colour == 'W')
        diffColour = 'B';
    if (colour == 'B')
        diffColour = 'W';
    
    if (colour == 'W'){
        printf("Enter move for colour %c (RowCol): ", diffColour);
        scanf(" %c %c", &row, &col);
        if (checkLegal(dimension, board, row, col, diffColour) == false){
            printf("Invalid move.\n%c player wins.",colour);
            return EXIT_SUCCESS;
        }
        else{
            board[row-'a'][col-'a']= diffColour;
            flipAllAfterLegal(dimension, board, diffColour, row, col);
            printBoard(board, dimension);
        }
    }
    
    
    
    while (out<1) {
        
        if (haveMove(dimension, board, colour)==true)
            
            changeBestMove(dimension, board, copy, colour);
            
        
        else{
            if (haveMove(dimension, board, diffColour)==true){
                printf("%c player has no valid move.\n",colour);
            }
            else{
                finalCompare(dimension, board, colour, diffColour);
                return EXIT_SUCCESS;
            }
        }
       
        
        
        if (haveMove(dimension, board, diffColour)==true){
            printf("Enter move for colour %c (RowCol): ", diffColour);
            scanf(" %c %c", &row, &col);
            if (checkLegal(dimension, board, row, col, diffColour) == false){
                printf("Invalid move.\n%c player wins.",colour);
                return EXIT_SUCCESS;
            }
            else{
                board[row-'a'][col-'a']= diffColour;
                flipAllAfterLegal(dimension, board, diffColour, row, col);
                printBoard(board, dimension);
            }
        }
        
        
        else{
            if (haveMove(dimension, board, colour)==true){
                printf("%c player has no valid move.\n", diffColour);
            }
            else{
                finalCompare(dimension, board, colour, diffColour);
                return EXIT_SUCCESS;
            }
        }
    }
}