A C function to play the Game of Nim
void playGame ( int piles [ ] , int n , int whoseTurn ) { printf ( " GAME STARTS " 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 STRNEWLINE " , moves . stones_removed , moves . pile_index ) ; whoseTurn = HUMAN ; } else { printf ( " HUMAN ▁ removes ▁ % d ▁ stones ▁ from ▁ pile ▁ at ▁ " " index ▁ % d STRNEWLINE " , moves . stones_removed , moves . pile_index ) ; whoseTurn = COMPUTER ; } } showPiles ( piles , n ) ; declareWinner ( whoseTurn ) ; return ; } void knowWinnerBeforePlaying ( int piles [ ] , int n , int whoseTurn ) { printf ( " Prediction ▁ before ▁ playing ▁ the ▁ game ▁ - > ▁ " ) ; if ( calculateNimSum ( piles , n ) != 0 ) { if ( whoseTurn == COMPUTER ) printf ( " COMPUTER ▁ will ▁ win STRNEWLINE " ) ; else printf ( " HUMAN ▁ will ▁ win STRNEWLINE " ) ; } else { if ( whoseTurn == COMPUTER ) printf ( " HUMAN ▁ will ▁ win STRNEWLINE " ) ; else printf ( " COMPUTER ▁ will ▁ win STRNEWLINE " ) ; } return ; }