Вы находитесь на странице: 1из 14

Rock-Paper-Scissors-Lizard-Spock Game

A J Component Report
submitted by
TEAM MEMBERS:

NAME REG. NO.

ARUSHI GOYAL 16BCE0977

MEHAK MALIK 16BCE0802

in partial fulfillment for the award of the degree of


B.Tech

in
COMPUTER SCIENCE ENGINEERING

Under the guidance

of

Faculty: Prof. Delhi Babu R

School of Computing Science And Engineering


APRIL 2019

1
School of Computer Science and Engineering

DECLARATION

We hereby declare that the J Component report entitled “Rock-Paper-


Scissors-Lizard-Spock Game” submitted by us to Vellore Institute of
Technology, Vellore-14 in partial fulfillment of the requirement for the
award of the degree of B.Tech in Computer science and engineering
is a record of bonafide undertaken by me under the supervision of Dr.
R. Delhi Babu. We further declare that the work reported in this report
has not been submitted and will not be submitted, either in part or in
full, for the award of any other degree or diploma in this institute or
any other institute or university.

Signature Signature

Name: ARUSHI GOYAL Name: MEHAK MALIK


Reg. Number: 16BCE0977 Reg. Number: 16BCE0802

2
TABLE OF CONTENTS

CHAPTER PAGE
TITLE
NO. NO.

1. INTRODUCTION 4

1.1 Abstract 4

1.2 Requirements 5

1.3 Input 6

1.4 Output 7

1.5 Markov Chaining Process


8

IMPLEMENTATION
2. 9

2.1 Code Screenshots 9

2.2 Output Screenshots 11

APPENDICES 14

3
1. INTRODUCTION

Rock-Paper-Scissors-Spock-Lizard is a game that is a version of the age old


Rock Paper-Scissors with more possibilities and outcomes.
The aim of our project is to devise an interface that can play this game with a
human by recognizing their gesture and even deciding who has won that
particular round.

For the Artificial Intelligence (AI) of our RPSLS Game, we are going to use a
Markov Chain. It will let us to predict the next move that should be played by
the user. Like that, we could react consequently and choosing an item against
which the predicted item will lose.

1.1 Abstract

Rock–paper–scissors (also known as scissors-paper-rock or other variants) is a


hand game usually played between two people, in which each player
simultaneously forms one of three shapes with an outstretched hand. These
shapes are "rock" (a closed fist), "paper" (a flat hand), and "scissors" (a fist with
the index finger and middle finger extended, forming a V). "Scissors" is identical
to the two-fingered V sign (aka "victory" or "peace sign") except that it is pointed
horizontally instead of being held upright in the air. A simultaneous, zero-sum
game, it has only two possible outcomes: a draw, or a win for one player and a
loss for the other.

Rules of the game are:

Scissors cuts Paper --> Paper covers Rock --> Rock crushes Lizard --> Lizard
poisons Spock --> Spock smashes Scissors --> Scissors decapitates Lizard -->
Lizard eats Paper --> Paper disproves Spock --> Spock vaporizes Rock --> (and
as it always has) Rock crushes Scissors

4
Figure 0: Rules of the game

1.2 REQUIREMENTS

Software Specification
• Compiler must support tensor flow environment
• Python 3.5.0 or above

Hardware Specification

• 4 GB RAM
• 20 GB Disk Space
• GPU is preferable
• Webcam

Libraries
• NUMPY
• MATPLOTLIB
• SCIPY
• CV2
• KERAS
• PANDAS
• H5PY

5
1.3 INPUT

A gesture made by the user representing their choice i.e.:


1. Stone
2. Paper
3. Scissors
4. Lizard
5. Spock

Figure 1: Image of Scissors Gesture Made by User


Figure 2: Image of Lizard Gesture Made by User

6
1.4 OUTPUT

A symbol representing the computer’s choice and the result of the


game which can be:
1. CPU wins
2. User wins
3. Draw

Figure 3: Output for Scissors Gesture Made by User

Figure 4: Output for Lizard Gesture Made by User

7
1.5 MARKOV CHAINING PROCESS

Like said by Wikipedia, A Markov chain is “a stochastic


model describing a sequence of possible events in which the
probability of each event depends only on the state attained in the
previous event”.

Figure 5: Markov Chain

In the above figure, you can see a diagram representing a two-state


Markov process, with the states labelled E and A. Each number represents
the probability of the Markov process changing from one state to another
state, with the direction indicated by the arrow.
In our RPSLS Game, each state will be represented by an Item. During the
game, we will store in a Matrix the number of events passing from an item
to another item. Thus, if the user has played ROCK at the previous throw
and then, he plays PAPER, we will increment the ROCK to PAPER
counter in the matrix
To choose the next move to play for our AI, We need to know the
previous throw made by the user. With that, we choose in the matrix the
corresponding line. We iterate on the elements of that line and we choose

8
the item for which the column has the maximum number of events. This is
the predicted item for next move of the user.

2. IMPLEMENTATION

Filtering Image to Get Contours

First a binary mask of the gesture is created in order to determine the contour.
This happens by converting the frames which have been captured by OpenCV
to HLS (Hue, Lightness, Saturation) color space. This is followed by removal of
noise, blurring and reapplying the binary mask. This is followed by detection of
the contours.

Convolutional Neural Network for Training the Model

Convolution Neural network, are deep artificial neural networks. They are very
often used to analyze images. We have collected 6000 images to train the
network. This is followed by the building of the CNN, data augmentation and
then training of the network using the dataset.

Now the model can be used to predict the gesture made by the user. The
computer will generate its choice based on the Markov Model prediction and
the result of the match and the choices are displayed on the screen that captured
the image in real time.

2.1 CODE SCREENSHOTS

CV2 is used to capture the gestures made by the user. Contours are extracted
from the image so as to train the model using images from which noise has been
removed.

9
Figure 6: Capturing the Gesture Made by User

There are 5 gestures that have been used. For each gesture we have used 1200
images to train the model, i.e., the dataset consists of 6000 images

Figure 8: Dataset Used for Training the Rock Gesture

Keras is used to predict the gesture made by the image. It uses TensorFlow as
backend

10
Figure 9: Using Keras to Predict the Gesture made by User

2.2 OUTPUT SCREENSHOTS

Figure 10: Contours Extracted for Scissors Gesture

11
Figure 11: Contours Extracted for Paper Gesture

The output is displayed on the screen capturing the image itself. This occurs in
real time. As the user makes the gesture, the output is displayed along with the
CPU’s choice for the game and the winner of that came. The user can withdraw
their gesture my moving their hand down and then play the game again by
making another gesture

12
Figure 12: Output for Lizard Gesture

Figure 13: Output for Scissors Gesture

13
APPENDICES

Appendix 1: Python Tensorflow

TensorFlow is an open source library for fast numerical computing.It was created and
is maintained by Google and released under the Apache 2.0 open source license. The
API is nominally for the Python programming language, although there is access to
the underlying C++ API.Unlike other numerical libraries intended for use in Deep
Learning like Theano, TensorFlow was designed for use both in research and
development and in production systems, not least RankBrain in Google search and the
fun DeepDream project.It can run on single CPU systems, GPUs as well as mobile
devices and large scale distributed systems of hundreds of machines..

Appendix 2: Keras

Keras is a high-level neural networks API, written in Python and capable of running on
top of TensorFlow, CNTK, or Theano. It was developed with a focus on enabling fast
experimentation. Being able to go from idea to result with the least possible delay is key
to doing good research.Use Keras if you need a deep learning library that:

 Allows for easy and fast prototyping (through user friendliness, modularity,
and extensibility).
 Supports both convolutional networks and recurrent networks, as well as
combinations of the two.
 Runs seamlessly on CPU and GPU..

14