wisemonkeys logo
FeedNotificationProfileManage Forms
FeedNotificationSearchSign in
wisemonkeys logo

Blogs

Rock, Paper, Scissors Game in Common Lisp

profile
Om Rawal
Jul 16, 2025
0 Likes
0 Discussions
5 Reads


1. Code Analysis

Let’s walk through how the code works, step by step:

a. Setup

(defun rock-paper-scissors ()
(let ((choices '("rock" "paper" "scissors"))
(random-state (make-random-state t)))
  1. I defined a function called rock-paper-scissors.
  2. Inside, I created a list of choices: "rock", "paper", and "scissors".
  3. I also made a random state to generate random numbers.

b. Welcome Message

(format t "~%--- Welcome to the Rock, Paper, Scissors Game! ---~%")
(format t "Instructions: Type 'rock', 'paper', or 'scissors' to play.~%")
(format t "You can also type 'quit' anytime to exit the game.~%~%")
  1. Prints a welcome message and tells the player how to play.

c. The Game Loop

(loop
(format t "Your move: ")
(let ((player-move (string-downcase (read-line))))
...
  1. Starts an infinite loop for continuous gameplay.
  2. Asks the player to type their move.
  3. Converts the input to lowercase so it works even if the player types “Rock” or “ROCK”.

d. Handling “quit”

(if (string= player-move "quit")
(progn
(format t "Thanks for playing! Goodbye.~%")
(return))
  1. If the user types quit, the program says goodbye and exits the loop.

e. Validating Input

(if (not (member player-move choices :test #'string=))
(format t "Oops! Please enter only 'rock', 'paper', or 'scissors'.~%")
  1. Checks if the user typed a valid move.
  2. If not, it prints a warning and loops back to ask again.

f. Computer’s Move

(let* ((computer-move (nth (random 3 random-state) choices)))
(format t "Computer chose: ~A~%" computer-move)
  1. Picks a random move from the list of choices.
  2. Prints out what the computer chose.

g. Determining the Winner

(cond
((string= player-move computer-move)
(format t "It's a tie! We both chose ~A.~%" player-move))

((or (and (string= player-move "rock") (string= computer-move "scissors"))
(and (string= player-move "scissors") (string= computer-move "paper"))
(and (string= player-move "paper") (string= computer-move "rock")))
(format t "You win! ~A beats ~A.~%" player-move computer-move))

(t
(format t "You lose! ~A beats ~A.~%" computer-move player-move))))
  1. Checks for a tie first.
  2. Then checks if the player wins.
  3. Otherwise, prints that the player lost.

2. Output

Here’s what a sample run looks like:



Comments ()


Sign in

Read Next

Supervised and Unsupervised Learning

Blog banner

Emotional Suppression: The Hidden Costs Of Unfelt Feelings

Blog banner

Disk cache

Blog banner

KAHAWA TEA

Blog banner

Question

Blog banner

Virtual Memory

Blog banner

Data Mining

Blog banner

Why Social Search Is Becoming the New Discovery Channel for Brands?

Blog banner

 " Healing of Yoga "

Blog banner

Top 5 Benefits of Artificial Intelligence

Blog banner

Blockchain uses and use cases

Blog banner

POVERTY:Causes and solutions to problems

Blog banner

Vaping vs. Chewing Gum: The Hidden ‘Stress Fix’ Destroying Sydney’s Teeth

Blog banner

Deadlock and Starvation

Blog banner

Exploring Human Factors in Cyber Forensics Investigations.

Blog banner

21ST CENTURY PATRIARCHY

Blog banner

Cache memory

Blog banner

Deadlock Prevention

Blog banner

Online Games

Blog banner

Sweet and Sour Mango Pickle (Gol Keri)

Blog banner

Affiliate Marketing V/S Influencer Marketing

Blog banner

Operating system

Blog banner

You'll get to know about Pankaj Negi

Blog banner

Utilizing Data-Hiding and Retrieval Techniques in Cyber Forensics

Blog banner

Understanding Toddler Tantrums: What They Really Mean

Blog banner

What if COVID does not exist!

Blog banner

How Does SSO Works

Blog banner

Predictive Analytics: How Data Science Predicts Trends(Weather ,Stock Market,Sales Forecasting ).

Blog banner

RACI model in IT services

Blog banner

Bharat Maps

Blog banner

HubSpot

Blog banner

“Shot on iPhone” : A campaign by Apple that turned into a prodigy

Blog banner

Smart Homes | Zigbee Alliance

Blog banner

How GIS in Agriculture Eliminates Guesswork

Blog banner

Efficiency of SQL Injection Method in Preventing E-Mail Hacking

Blog banner

Fashion design

Blog banner

GIS Bharat Maps

Blog banner

Four Stalls Every Vegetarian Needs To Eat At Outside Vile Parle Station

Blog banner

Banaras

Blog banner

MPL and how its effects?

Blog banner

Discover The Top 3 Places To Stay in London

Blog banner

Mumbai Metro 3

Blog banner