I am building a Nim game in scheme that prompt users to enter the pile number and the number of items they want to remove. The computer will simply remove 1 from the first pile, if the first pile is empty, it will remove from 2nd pile, than 3rd.

My code won’t work correctly, can someone please point out where I make mistakes? Thanks in advance.

Here is my code:

```
(define play-with-turns
(lambda (game-state player)
(display-game-state game-state)
(cond ((over? game-state)
(announce-winner player))
((equal? player 'human)
(play-with-turns (human-move game-state) 'computer))
((equal? player 'computer)
(play-with-turns (computer-move game-state) 'human))
(else
(error "player wasn't human or computer:" player)))))
(define computer-move
(lambda (game-state)
(let ((pile (if (> (size-of-pile game-state 1) 0)
1
2)))
(display "I take 1 coin from pile ")
(display pile)
(newline)
(remove-coins-from-pile game-state 1 pile))))
(define prompt
(lambda (prompt-string)
(newline)
(display prompt-string)
(newline)
(read)))
(define human-move
(lambda (game-state)
(let ((p (prompt "Which pile will you remove from?")))
(let ((n (prompt "How many coins do you want to remove?")))
(remove-coins-from-pile game-state n p)))))
(define over?
(lambda (game-state)
(= (total-size game-state) 0)))
(define announce-winner
(lambda (player)
(if (equal? player 'human)
(display "You lose. Better luck next time.")
(display "You win. Congratulations."))))
(define remove-coins-from-pile
(lambda (game-state num-coins pile-number)
(cond ((= pile-number 1)
(make-game-state (- (size-of-pile game-state 1)
num-coins)
(size-of-pile game-state 2)
(size-of-pile game-state 3)))
((= pile-number 2)
(make-game-state (size-of-pile game-state 1)
(- (size-of-pile game-state 2)
num-coins)
(size-of-pile game-state 3)))
((= pile-number 3)
(make-game-state (size-of-pile game-state 1)
(size-of-pile game-state 2)
(- (size-of-pile game-state 3)
num-coins))))))
(define exponent-of-in
(lambda (n int)
(if (= (remainder int n) 0)
(+ 1 (exponent-of-in n (quotient int n)))
0)))
(define make-game-state
;Returns a game state with n coins in the first pile
;m coins in the second pile, and k coins in the third pile.
(lambda (n m k)
(lambda (x)
(cond ((= x 1) n)
((= x 2) m)
((= x 3) k)))))
(define size-of-pile
;Returns an integer equal to the number of coins in
;pile pile-number of the game-state.
(lambda (game-state pile-number)
(game-state pile-number)))
;; Utilities
(define display-game-state
(lambda (game-state)
(newline)
(newline)
(display " Pile 1: ")
(display (size-of-pile game-state 1))
(newline)
(display " Pile 2: ")
(display (size-of-pile game-state 2))
(newline)
(display " Pile 3: ")
(display (size-of-pile game-state 3))
(newline)
(newline)))
(define total-size
(lambda (game-state)
(+(+ (size-of-pile game-state 1)
(size-of-pile game-state 2)) (size-of-pile game-state 3))))
```