Rock, Paper, Scissors, Lizard, Spock

“Rock, Paper, Scissors, Lizard, Spock” is a variation of the children’s 3-way lock hand game called Rock Paper Scissors (or ‘Roshambo’). The ‘Lizard Spock’ version of the game has been made popular by the television show “Big Bang Theory.”

What is this all about?

This is actually quite an old post for me – I probably wrote it initially about8 years ago, however I couldn’t find it, and it turns out there were quite a few HTML statements in the original post I hadn’t cleaned up that prevented it from displaying correctly, so I am refreshing it with new graphics and updated content.

I decided to build a little application using Neo4J to 1) learn a bit of code and 2) show how to model RPSLS in a graph database.

Getting Started

Download Neo4j Desktop from the following location, and install it on your desktop / laptop:

Once installed, create a new local database, and open to the integrated browser.

Use the statement below to populate the graph with the objects and relationships.

CREATE p=(paper:object {name:"paper"})-[:covers]->(rock:object {name:"rock"})-[:crushes]->(scissors:object {name:"scissors"})-[:decapitates]->(lizard:animal {name:"lizard"})-[:poisons]->(spock:vulcan:person {name:"spock"})-[:vaporizes]->(rock)-[:crushes]->(lizard)-[:eats]->(paper)-[:disproves]->(spock)-[:smashes]->(scissors)-[:cuts]->(paper)

If you need to…

Use the code below at any time to wipe the database and start over…​


Explore the Graph

Let’s take a look at what we’ve got…

// Get some data
MATCH (n1)-[r]->(n2) RETURN r, n1, n2 LIMIT 25

What if….

We only wanted to see objects of type ‘object?’

match (n:object) return n

Find all non-objects

match (n) where NOT (n:object) return n

Find all vulcans

match (n:vulcan) return n

What are the actions for Rock?

MATCH (n:object{name:"rock"})-[r]->(x)
return n,r,x

What are the actions for Paper?

MATCH (n:object{name:"paper"})-[rel]->x
return n,r,x

What are the actions for Spock?

MATCH (n:vulcan{name:"Spock"})-[r]->x
return n,r,x

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s