Beispiel #1
0
int main(int argc, char * argv[]) {
    bool compFirst = argc == 1;
    printf("\nConnect Four\n");
    printf("============\n");
    printf("\n");
    bool fiar = false;
    bool over = false;
    int playCount = 0;
    Board board;
    player computer = compFirst ? PLAYER_ONE : PLAYER_TWO;
    player human = compFirst ? PLAYER_TWO : PLAYER_ONE;
    showBoard(board);

    while (1) {
        over = compFirst ? computerMoves(board, computer, playCount)
            : playerMoves(board, human, playCount);
        if (over) break;
        if (compFirst) showBoard(board);
        over = compFirst ? playerMoves(board, human, playCount)
            : computerMoves(board, computer, playCount);
        if (over) break;
        if (!compFirst) showBoard(board);
    }

    board.displayBoard();

    return 0;
}
Beispiel #2
0
void GameSession::disconnectPlayers()
{
   QObject::disconnect(whitePlayer_, SIGNAL(isReady()), this, SLOT(white_isReady()));
   QObject::disconnect(whitePlayer_, SIGNAL(playerMoves(ChessMove)), this, SLOT(white_moves(ChessMove)));
   QObject::disconnect(whitePlayer_, SIGNAL(playerMoves(const std::string&)), this, SLOT(white_moves(const std::string&)));
   QObject::disconnect(whitePlayer_, SIGNAL(playerOffersDraw()), this, SLOT(white_offersDraw()));
   QObject::disconnect(whitePlayer_, SIGNAL(playerResigns()), this, SLOT(white_resigns()));
   QObject::disconnect(whitePlayer_, SIGNAL(playerSays(const QString&)), this, SLOT(white_says(const QString&)));
   QObject::disconnect(whitePlayer_, SIGNAL(playerRequestsTakeback()), this, SLOT(white_requestsTakeback()));
   QObject::disconnect(whitePlayer_, SIGNAL(playerRequestsAbort()), this, SLOT(white_requestsAbort()));
   //
   QObject::disconnect(blackPlayer_, SIGNAL(isReady()), this, SLOT(black_isReady()));
   QObject::disconnect(blackPlayer_, SIGNAL(playerMoves(ChessMove)), this, SLOT(black_moves(ChessMove)));
   QObject::disconnect(blackPlayer_, SIGNAL(playerMoves(const std::string&)), this, SLOT(black_moves(const std::string&)));
   QObject::disconnect(blackPlayer_, SIGNAL(playerOffersDraw()), this, SLOT(black_offersDraw()));
   QObject::disconnect(blackPlayer_, SIGNAL(playerResigns()), this, SLOT(black_resigns()));
   QObject::disconnect(blackPlayer_, SIGNAL(playerSays(const QString&)), this, SLOT(black_says(const QString&)));
   QObject::disconnect(blackPlayer_, SIGNAL(playerRequestsTakeback()), this, SLOT(black_requestsTakeback()));
   QObject::disconnect(blackPlayer_, SIGNAL(playerRequestsAbort()), this, SLOT(black_requestsAbort()));
}