Exemple #1
0
int main(int argc, char *argv[]){
    lHead = NULL;
    printFlag = 1;
    printf("Author: Muxuan Wang\n");
    printf("Program 5: Mancala\n");
    printf("TA: Sean Deitz, W 9:00 AM\n");
    printf("Nov.28,2012\n");
    printf("\n");
    
    printf("Welcome to the game of Mancala, where you are playing against\n");
    printf("a computer opponent. You may enter 'u' to undo a move or \n");
    printf("'x' to exit. Your holes are on the bottom row and you get\n");
    printf("to go first.\n");
    printf("\n");
    printf("\n");
    

    Hole board[14];
    initBoard(board);
    if (argc > 1) {
	commandLineArg(board, argv);
    }
    
    addToTail(&lHead, board);

    int player = 0;
    char userInput;
    int notDone = 1;
    int gameNum = 1;

    //each loop is a turn, and involves user and computer to play.
    while(notDone){
	printf("----------------------------------------------------------\n");
	playerToMove(player,board, &gameNum);
	notDone = checkEndGame(board);
	if (notDone == 0) {
	    break;
	}
	player = (++player) % 2;
	playerToMove(player,board, &gameNum);	    
	notDone = checkEndGame(board);
	gameNum++;
	player = (++player) % 2;
	addToTail(&lHead, board);
    }

    endGameScore(board);
    printf("The final board is: \n");
    displayBoard(board);
    if(board[13].capacity > board[6].capacity){
	printf("Computer Won!!\n");
    }else if(board[13].capacity < board[6].capacity){
	printf("You Won!!\n");
    }else{
	printf("Play Even!!");
    }

} // end of main
Exemple #2
0
void ChessGame::onMoveMade(const Chess::Move& move)
{
	ChessPlayer* sender = qobject_cast<ChessPlayer*>(QObject::sender());
	Q_ASSERT(sender != nullptr);

	Q_ASSERT(m_gameInProgress);
	Q_ASSERT(m_board->isLegalMove(move));
	if (sender != playerToMove())
	{
		qDebug("%s tried to make a move on the opponent's turn", qPrintable(sender->name()));
		return;
	}

	m_scores[m_moves.size()] = sender->evaluation().score();
	m_moves.append(move);
	addPgnMove(move, evalString(sender->evaluation()));

	// Get the result before sending the move to the opponent
	m_board->makeMove(move);
	m_result = m_board->result();
	if (m_result.isNone())
	{
		if (m_board->reversibleMoveCount() == 0)
			m_adjudicator.resetDrawMoveCount();

		m_adjudicator.addEval(m_board, sender->evaluation());
		m_result = m_adjudicator.result();
	}
	m_board->undoMove();

	ChessPlayer* player = playerToWait();
	player->makeMove(move);
	m_board->makeMove(move);

	if (m_result.isNone())
	{
		emitLastMove();
		startTurn();
	}
	else
	{
		stop(false);
		emitLastMove();
	}
}