(define human 'Human)
(define computer 'Computer)
(define nobody 'Nobody)
(define rock 'Rock)
(define paper 'Paper)
(define scissors 'Scissors)
(define human-wins 0)
(define computer-wins 0)
(define ties 0)
(define (computer-choose)
(begin (random-seed (abs (current-milliseconds)))
(case (random 3)
((0) rock)
((1) paper)
((2) scissors))))
(define (human-choose)
(begin
(printf "Choose Rock, Paper or Scissors:~n>")
(case (read)
((r R rock Rock) rock)
((p P paper Paper) paper)
((s S scissors Scissors) scissors)
(else (begin
(printf "Wrong input, ")
(human-choose))))))
(define (winner? human-choice computer-choice)
(if (eq? human-choice computer-choice)
nobody
(if (or (and (eq? human-choice rock) (eq? computer-choice scissors))
(and (eq? human-choice paper) (eq? computer-choice rock))
(and (eq? human-choice scissors) (eq? computer-choice paper)))
human
computer)))
(define (play)
(let* ((human-choice (human-choose))
(computer-choice (computer-choose))
(winner (winner? human-choice computer-choice)))
(begin
(printf "Human: ~v, Computer: ~v -> ~v wins!~n" human-choice computer-choice winner)
(cond
((eq? winner human) (set! human-wins (add1 human-wins)))
((eq? winner computer) (set! computer-wins (add1 computer-wins)))
((eq? winner nobody) (set! ties (add1 ties))))
(printf "Score: Human ~v Computer ~v Ties ~v~n" human-wins computer-wins ties)
(printf "Play again?~n>")
(case (read)
((y Y yes Yes) (play))
(else (printf "Good bye!~n"))))))
(play)