AI - Rock Paper Scissors Game
AI - Rock Paper Scissors Game
A J Component Report
submitted by
TEAM MEMBERS:
in
COMPUTER SCIENCE ENGINEERING
of
1
School of Computer Science and Engineering
DECLARATION
Signature Signature
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
IMPLEMENTATION
2. 9
APPENDICES 14
3
1. INTRODUCTION
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
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
6
1.4 OUTPUT
7
1.5 MARKOV CHAINING PROCESS
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
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.
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.
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
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
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
13
APPENDICES
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