예제 #1
0
int main()
/* This is the main procedure of the tictactoe program
 * everything happens here.
 * Pre-condition: none
 * Post-condition: there was no problems
*/
{
	//program starts

	//create the intial game state structure
	infoPtr gameInfo = createInitialGameState();

	//find out if the user wishes to play and who must go first
	startAGame(gameInfo);

	//this is the main loop of the program
	//gameInfo->turn can only be EMPTY when the user doesn't want to play anymore
	while (gameInfo->turn != EMPTY)
	{
		//it's the user's turn to make a move
		if (gameInfo->turn == USER)
		{
			getUserMove(gameInfo);
		}else
		//it's the computer's turn to make a move
		{
			printf("Computing computer move...\n");
			getComputerMove(gameInfo);
		}

		//show how the game area now looks
		displayGameArea(gameInfo);

		//do we have a winner?, do we have a tie?, change turn?
		getMatchState(gameInfo);

		//if there was a tie or a win we need to ask if the user want's to play again
		if (gameInfo->turn == EMPTY)
		{
			//reset the play area
			resetPlayArea(gameInfo);
			//ask if we're playing
			startAGame(gameInfo);
		}
	}
	//shutdown everything
	shutDown(gameInfo);

	//program ends
}
예제 #2
0
파일: main.c 프로젝트: jasonhe89/hw3AI
int main()
{
    unsigned int cur_board[MAX_BOARD_SIZE];
    int won = 0;
    int i;
    
    for (i = 0; i < MAX_BOARD_SIZE; i++) cur_board[i] = 0;
    
    while (!won) {
        
        if (moves == MAX_CHILD_NODES) { printf("draw\n"); break; }
        
        emitBoard( cur_board );
        
        getHumanMove( X_PLAYER, cur_board );
        
        won = checkPlayerWin( X_PLAYER, cur_board );
        moves++;
        
        if (!won) {
            
            if (moves == MAX_CHILD_NODES) { printf("draw\n"); break; }
            
            emitBoard( cur_board );
            
            getComputerMove( cur_board );
            // getHumanMove( O_PLAYER, cur_board );
            moves++;
            
            won = checkPlayerWin( O_PLAYER, cur_board );
            
            if (won) { printf("\nPlayer 2 wins!\n"); }
            
        } else {
            printf("\nPlayer 1 wins!\n");
        }
        
    }
    
    emitBoard( cur_board );
    return 0;
}