Combinatorial Game Theory/Game of NIM/gameNIM.c
// A C function to play the Game of Nim 
A C function to play the Game of Nim
A C function to play the Game of Nim
void playGame(int piles[], int n, int whoseTurn) 
{ 
    printf("\nGAME STARTS\n\n"); 
    struct move moves; 
    while (gameOver (piles, n) == false) 
    { 
        showPiles(piles, n); 
        makeMove(piles, n, &moves); 
        if (whoseTurn == COMPUTER) 
        { 
            printf("COMPUTER removes %d stones from pile "
                   "at index %d\n", moves.stones_removed, 
                   moves.pile_index); 
            whoseTurn = HUMAN; 
        } 
        else
        { 
            printf("HUMAN removes %d stones from pile at "
                   "index %d\n", moves.stones_removed, 
                   moves.pile_index); 
            whoseTurn = COMPUTER; 
        } 
    } 
    showPiles(piles, n); 
    declareWinner(whoseTurn); 
    return; 
}
void playGame ( int piles [ ] , int n , int whoseTurn ) { printf ( " \n \n \n " ) ; struct move moves ; while ( gameOver ( piles , n ) == false ) { showPiles ( piles , n ) ; makeMove ( piles , n , & moves ) ; if ( whoseTurn == COMPUTER ) { printf ( " " " \n " , moves . stones_removed , moves . pile_index ) ; whoseTurn = HUMAN ; } else { printf ( " " " \n " , moves . stones_removed , moves . pile_index ) ; whoseTurn = COMPUTER ; } } showPiles ( piles , n ) ; declareWinner ( whoseTurn ) ; return ; }
A C function to play the Game of Nim
A C function to play the Game of Nim