/
main.lisp
38 lines (28 loc) · 1.5 KB
/
main.lisp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
(defpackage rock-paper-scissors
(:use :cl))
(in-package :rock-paper-scissors)
(defun get-player-choice (options)
(format t "Please enter one of -> ~{~A~^, ~}: " options)
(force-output)
(or (find (read-line) options :test #'string-equal) (get-player-choice options)))
(defun game ()
(let* ((options '("rock" "paper" "scissors"))
(cpu-choice (nth (random (length options) (make-random-state t)) options))
(player-choice (get-player-choice options)))
(cond
((string-equal cpu-choice player-choice)
(format nil "You entered ~A, CPU entered ~A. It's a draw!" player-choice cpu-choice))
((and (string-equal player-choice "rock") (string-equal cpu-choice "scissors"))
(format nil "You entered ~A, CPU entered ~A. You win!" player-choice cpu-choice))
((and (string-equal player-choice "paper") (string-equal cpu-choice "rock"))
(format nil "You entered ~A, CPU entered ~A. You win!" player-choice cpu-choice))
((and (string-equal player-choice "scissors") (string-equal cpu-choice "paper"))
(format nil "You entered ~A, CPU entered ~A. You win!" player-choice cpu-choice))
(t
(format nil "You entered ~A, CPU entered ~A. You loose!" player-choice cpu-choice)))))
(defun game ()
(let* ((options '("rock" "paper" "scissors"))
(cpu-choice (nth (random (length options) (make-random-state t)) options))
(player-choice (get-player-choice options)))
`(,options ,cpu-choice ,player-choice)))
(game)