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
3 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

This School Year, Let Their Belongings Come Back Home Too with Our Ultimate Labelling Kit

Blog banner

Install Ubuntu Easily

Blog banner

WHAT IS TWITTER AND HOW DOES IT WORK

Blog banner

Sensory Play for Toddlers: Boosting Curiosity Through Touch, Sound, and Colour

Blog banner

Data Warehousing

Blog banner

Cloud Technology and its Implications for Entrepreneurship

Blog banner

Improving the Accuracy of GPS and GNSS

Blog banner

Threats To Computer System

Blog banner

Basic Security For SOAP Services

Blog banner

virtual machine

Blog banner

How the mobile IP is used in GSM architecture.

Blog banner

MAHAKAL LOK UJJAIN

Blog banner

Utilizing Data-Hiding and Retrieval Techniques in Cyber Forensics

Blog banner

virtual memory

Blog banner

Flipkart

Blog banner

Deadlock and Starvation

Blog banner

The Right way of cooking

Blog banner

Virtual machine

Blog banner

Kernel Modes: User Mode vs. Kernel Mode - 80

Blog banner

Defining youtubr

Blog banner

OPERATING SYSTEM

Blog banner

Review on Cyber Forensics and its Analysis Tools

Blog banner

Impacts of Data Breach On Companies Challenges and Prevention

Blog banner

IOT Hacking Techniques

Blog banner

?Why Social and Emotional Skills Matter More Than ABCs in Early Years?

Blog banner

GIS info about Bermuda Triangle

Blog banner

RAID

Blog banner

HTML vs HTML5

Blog banner

operating system

Blog banner

Apple

Blog banner

DATA SCIENCE IN BUSINESS AND MARKETING

Blog banner

internet email and it's applications

Blog banner

Malicious softwares

Blog banner

Multithreading in Operating System

Blog banner

10 Reasons to Date a South Indian Girl

Blog banner

Firewall / IDS Evasion Techniques

Blog banner

VIRTUAL MACHINES

Blog banner

The 60-Minute Window: What to Do (And What NOT to Do) When You Knock Out a Tooth

Blog banner

Virtual Machine

Blog banner

MODERN OPERATING SYSTEM

Blog banner

Things You Should Leave Behind In 2025, Whilst In 2026

Blog banner

Why Dry Fruits Make the Perfect Gifting Choice for Every Occasion?

Blog banner