(define sim
(lambda (n)
(let ((player1 (player1-maker))
(player2 (player2-maker))
(total n))
(letrec ((display-results
(lambda (total)
(display "Player1 won ")
(display (send player1 'show-percent total))
(display "% of the games. Player2 won ")
(display (send player2 'show-percent total))
(display "% of the games.")
(newline)
))
(sim-helper
(lambda (n)
(if (zero? n)
(display-results total)
(case (hangman-guess-sim (send player2 'pick-new!))
((0) (begin
(send player2 'pick-new!)
(sim-helper n)))
((1) (begin
(send player1 'you-win!)
(send player1 'pick-new!)
(sim-helper (sub1 n))))
((2) (begin
(send player2 'you-win!)
(send player1 'pick-new!)
(sim-helper (sub1 n))))
(else
'error))))))
(begin
(send player1 'pick-new!)
(sim-helper n))))))
You are also given a helper procedure and a global variable:
(define get-new-letter
(lambda ()
(vector-ref alpha-bet (random 25))))
(define alpha-bet
(vector 'a 'b 'c 'd 'e 'f 'g 'h 'i 'j 'k 'l 'm 'n 'o
'p 'q 'r 's 't 'u 'v 'w 'x 'y 'z))
Do the following: