SlideShare a Scribd company logo
1 of 9
Download to read offline
10.11.2016
Group No 7
Aashaka Shah​ (14114001)
Abhishek Jaisingh​ (14114002)
Akashdeep Goel​ (14114004)
Akshit Kalra​ (14114006)
Ambar Zaidi​ (14114009)
Problem Statement
This project aims to build a snake game which satisfies following requirements clearly :
1. Snake can enter a wall and emerge from the other (opposite) side.
2. Speed and size of snake must increase on eating a unit of food, thus increasing
difficulty as the game progresses.
3. Game gets over as soon as snake touches its own body.
Main Objects
1. Snake
a. Attributes of Snake object - Length (Size) => 1 (Initially)
b. Snake starts at bottom-left corner or grid-point (0, 0).
c. Snake’s length increases as it consumes more food.
d. Snake’s speed increases according to the equation:
i. Speed = 4.6 + Score * 0.66
ii. Linear variation
2. Food
a. Single unit increases the length of snake by 1.
b. Each food unit appears at random locations on the grid.
c. Food cannot appear on any of the cells currently occupied by snake.
3. Grid
a. Grid size can be adjusted.
b. Number of rows and columns can be adjusted.
c. Length and Width of columns can also be adjusted.
Technologies Used:
1. HTML & CSS (for Frontend)
2. JavaScript (three.JS Library)
three.js Basic Workflow
Three.js is a cross-browser JavaScript library/API used to create and display animated 3D
computer graphics in a web browser. Three.js uses ​WebGL​. WebGL in turn is based on
OpenGL​ ES 2.0 and provides an API for 3D graphics.
Everything made using three.JS library has three basic elements:
1. Camera​: Used to define view point, front-plane, back-plane and aspect-ratio and
viewing angle. Camera can be Perspective or Parallel.
2. Mesh​: It is the basic form of any object which in turn is made up of geometry and
material.
3. Light​: Light sources must also be defined appropriately otherwise the object
cannot be seen clearly. There are various kinds of light sources like Ambient Light,
Directional Light etc.
Outline of Steps taken:
1. Create the Scene
2. Create the Renderer
3. Create a Camera
4. Add Lighting
5. Add Meshes(Geometry+Material) to Scene
6. Add Controls
7. Render the Scene
Algorithms & Data Structures
Data Structure
We needed to model the snake using an appropriate data-structure, which fulfils the
following requirements:
1. Maintains length dynamically, i.e. length should not be constant.
2. When no food is eaten, length must remain same, but snake must move forward.
a. A new cube must be added at the front of current snake.
b. The last cube must be removed.
3. If food is eaten by the snake, length should be increased by one.
a. Here we need only to add a new cube at front of snake.
b. No removal is required as the length is supposed to increase by one unit.
As only the head and tail of the snake needs to be updated, we require a data structure
that supports the removal and addition at its two ends. So, we must use queues. But, we
need to support these addition and removal operations at both ends.
The data structure that supports all these requirements is ​Dequeue (Double Ended
Queue). In dequeue, elements can be added to or removed from either the front (head)
or back (tail) efficiently and easily.
Dequeue General JavaScript API
Operation Common name(s) JavaScript
insert element at back inject, snoc push
insert element at front push, cons unshift
remove last element eject pop
remove first element pop shift
examine last element peek last <obj>[<obj>.length - 1]
examine first element peek first <obj>[0]
Algorithm / Pseudocode:
There are basically two main functions having some algorithmic logic:
Function​ getRandomFreeLocation​():
x ​=​ random​(​0​,​ rows)
y ​=​ random​(​0​,​ cols)
for​ i ​in​ ​(​0​,​ rows​):
for​ j ​in​ ​(​0​,​ cols​):
if​ ​((​x ​+​ i ​)​ ​%​ rows​,​ ​(​y ​+​ j ​)%​ cols​)​ ​not​ ​in​ queue:
return​ ​((​x ​+​ i ​)​ ​%​ rows​,​ ​(​y ​+​ j ​)%​ cols)
Function​ ​MainRenderLoop​():
takeInput​();
IF collision​(​positionX​,​ positionY​):
Display​ ​Score
OUTPUT​(​"GAME OVER")
Stop​ ​RenderLoop
dequeue​.​push​(​newcube​)
IF foodEaten​(​positionX​,​ positionY​):
SCORE ​=​ SCORE ​+​ 1
food​.​location ​=​ getRandomFreeLocation​()
ELSE​:
dequeue​.​shift​()
calculateNewPosition​(​positionX​,​ positionY​);
Snapshots
Start of Game
Snake starts from bottom-left corner of grid with a score of zero.
Initial Score = 0
Growth of Snake
As the snake eats more food, its length and speed increases. Speed has been modeled as
a linear function of length / score.
Score = 25
Emergence from other side of wall
A snake can enter the wall and emerge from the opposite side.
Score = 21
Game Over
When snake touches any part of its own body, game is over and final score is displayed.
Final Score = 27
Snake Game Report

More Related Content

What's hot

presentation of make a calendar in c language.
presentation of make a calendar in c language.presentation of make a calendar in c language.
presentation of make a calendar in c language.
Najmul Hoq
 
Software Engineering ppt
Software Engineering pptSoftware Engineering ppt
Software Engineering ppt
shruths2890
 
Inheritance in java
Inheritance in javaInheritance in java
Inheritance in java
Tech_MX
 
Multithreading in java
Multithreading in javaMultithreading in java
Multithreading in java
Raghu nath
 

What's hot (20)

Snake Game in Python Progress report
Snake Game in Python Progress reportSnake Game in Python Progress report
Snake Game in Python Progress report
 
Project report 393_395
Project report 393_395Project report 393_395
Project report 393_395
 
JAVA AWT
JAVA AWTJAVA AWT
JAVA AWT
 
Tic Tac Toe ppt
Tic Tac Toe pptTic Tac Toe ppt
Tic Tac Toe ppt
 
OpenGL Mini Projects With Source Code [ Computer Graphics ]
OpenGL Mini Projects With Source Code [ Computer Graphics ]OpenGL Mini Projects With Source Code [ Computer Graphics ]
OpenGL Mini Projects With Source Code [ Computer Graphics ]
 
Arrays in Java
Arrays in JavaArrays in Java
Arrays in Java
 
presentation of make a calendar in c language.
presentation of make a calendar in c language.presentation of make a calendar in c language.
presentation of make a calendar in c language.
 
Applets in java
Applets in javaApplets in java
Applets in java
 
Applet Architecture - Introducing Java Applets
Applet Architecture - Introducing Java AppletsApplet Architecture - Introducing Java Applets
Applet Architecture - Introducing Java Applets
 
Java Streams
Java StreamsJava Streams
Java Streams
 
Flappy bird game in c#
Flappy bird game in c#Flappy bird game in c#
Flappy bird game in c#
 
Identifiers
Identifiers Identifiers
Identifiers
 
Software Engineering ppt
Software Engineering pptSoftware Engineering ppt
Software Engineering ppt
 
Java Networking
Java NetworkingJava Networking
Java Networking
 
Snake Game Flow Chart
Snake Game Flow ChartSnake Game Flow Chart
Snake Game Flow Chart
 
Final project report of a game
Final project report of a gameFinal project report of a game
Final project report of a game
 
Introduction to Python - Training for Kids
Introduction to Python - Training for KidsIntroduction to Python - Training for Kids
Introduction to Python - Training for Kids
 
Inheritance in java
Inheritance in javaInheritance in java
Inheritance in java
 
Multithreading in java
Multithreading in javaMultithreading in java
Multithreading in java
 
Mini Project PPT
Mini Project PPTMini Project PPT
Mini Project PPT
 

Similar to Snake Game Report

Data structures and algorithms lab4
Data structures and algorithms lab4Data structures and algorithms lab4
Data structures and algorithms lab4
Bianca Teşilă
 
Please make the complete program, distinguishing between each class .pdf
Please make the complete program, distinguishing between each class .pdfPlease make the complete program, distinguishing between each class .pdf
Please make the complete program, distinguishing between each class .pdf
faxteldelhi
 
Beholder#Giant center eye and twelve eye stalks above it. It is a.docx
Beholder#Giant center eye and twelve eye stalks above it.  It is a.docxBeholder#Giant center eye and twelve eye stalks above it.  It is a.docx
Beholder#Giant center eye and twelve eye stalks above it. It is a.docx
ikirkton
 

Similar to Snake Game Report (20)

Advanced core java
Advanced core javaAdvanced core java
Advanced core java
 
Data structures and algorithms lab4
Data structures and algorithms lab4Data structures and algorithms lab4
Data structures and algorithms lab4
 
CEN 235 4. Abstract Data Types - Queue and Stack.pdf
CEN 235 4. Abstract Data Types - Queue and Stack.pdfCEN 235 4. Abstract Data Types - Queue and Stack.pdf
CEN 235 4. Abstract Data Types - Queue and Stack.pdf
 
Please make the complete program, distinguishing between each class .pdf
Please make the complete program, distinguishing between each class .pdfPlease make the complete program, distinguishing between each class .pdf
Please make the complete program, distinguishing between each class .pdf
 
stacks and queues for public
stacks and queues for publicstacks and queues for public
stacks and queues for public
 
Animal Project
Animal Project Animal Project
Animal Project
 
STRINGS IN JAVA
STRINGS IN JAVASTRINGS IN JAVA
STRINGS IN JAVA
 
Circular queue
Circular queueCircular queue
Circular queue
 
Circular queue
Circular queueCircular queue
Circular queue
 
Lecture 2d queues
Lecture 2d queuesLecture 2d queues
Lecture 2d queues
 
Machine(s) Learning with Neural Networks
Machine(s) Learning with Neural NetworksMachine(s) Learning with Neural Networks
Machine(s) Learning with Neural Networks
 
HP-3 Presentation.pptx
HP-3 Presentation.pptxHP-3 Presentation.pptx
HP-3 Presentation.pptx
 
Transfer learning, active learning using tensorflow object detection api
Transfer learning, active learning  using tensorflow object detection apiTransfer learning, active learning  using tensorflow object detection api
Transfer learning, active learning using tensorflow object detection api
 
VCE Unit 03vv.pptx
VCE Unit 03vv.pptxVCE Unit 03vv.pptx
VCE Unit 03vv.pptx
 
adjava_23_bcs_vision_academy_sachinsir.pdf
adjava_23_bcs_vision_academy_sachinsir.pdfadjava_23_bcs_vision_academy_sachinsir.pdf
adjava_23_bcs_vision_academy_sachinsir.pdf
 
Queue
QueueQueue
Queue
 
Beholder#Giant center eye and twelve eye stalks above it. It is a.docx
Beholder#Giant center eye and twelve eye stalks above it.  It is a.docxBeholder#Giant center eye and twelve eye stalks above it.  It is a.docx
Beholder#Giant center eye and twelve eye stalks above it. It is a.docx
 
Queue
QueueQueue
Queue
 
deep learning
deep learningdeep learning
deep learning
 
Fast Object Recognition from 3D Depth Data with Extreme Learning Machine
Fast Object Recognition from 3D Depth Data with Extreme Learning MachineFast Object Recognition from 3D Depth Data with Extreme Learning Machine
Fast Object Recognition from 3D Depth Data with Extreme Learning Machine
 

More from Abhishek Jaisingh

More from Abhishek Jaisingh (10)

Movie recommendation project
Movie recommendation projectMovie recommendation project
Movie recommendation project
 
Deep Q-learning Flappy Bird
Deep Q-learning Flappy BirdDeep Q-learning Flappy Bird
Deep Q-learning Flappy Bird
 
Traffic Lights Controller in VHDL
Traffic Lights Controller in VHDLTraffic Lights Controller in VHDL
Traffic Lights Controller in VHDL
 
Airline Database Design
Airline Database DesignAirline Database Design
Airline Database Design
 
Client Server Model and Distributed Computing
Client Server Model and Distributed ComputingClient Server Model and Distributed Computing
Client Server Model and Distributed Computing
 
Forget Me Not Report
Forget Me Not ReportForget Me Not Report
Forget Me Not Report
 
Skype
SkypeSkype
Skype
 
Quantum Computing Report
Quantum Computing ReportQuantum Computing Report
Quantum Computing Report
 
Quantum Computing
Quantum ComputingQuantum Computing
Quantum Computing
 
Innovative Business Models Presentation
Innovative Business Models PresentationInnovative Business Models Presentation
Innovative Business Models Presentation
 

Recently uploaded

Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 

Recently uploaded (20)

Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
A Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source MilvusA Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source Milvus
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024
 

Snake Game Report

  • 1. 10.11.2016 Group No 7 Aashaka Shah​ (14114001) Abhishek Jaisingh​ (14114002) Akashdeep Goel​ (14114004) Akshit Kalra​ (14114006) Ambar Zaidi​ (14114009) Problem Statement This project aims to build a snake game which satisfies following requirements clearly : 1. Snake can enter a wall and emerge from the other (opposite) side. 2. Speed and size of snake must increase on eating a unit of food, thus increasing difficulty as the game progresses. 3. Game gets over as soon as snake touches its own body.
  • 2. Main Objects 1. Snake a. Attributes of Snake object - Length (Size) => 1 (Initially) b. Snake starts at bottom-left corner or grid-point (0, 0). c. Snake’s length increases as it consumes more food. d. Snake’s speed increases according to the equation: i. Speed = 4.6 + Score * 0.66 ii. Linear variation 2. Food a. Single unit increases the length of snake by 1. b. Each food unit appears at random locations on the grid. c. Food cannot appear on any of the cells currently occupied by snake. 3. Grid a. Grid size can be adjusted. b. Number of rows and columns can be adjusted. c. Length and Width of columns can also be adjusted. Technologies Used: 1. HTML & CSS (for Frontend) 2. JavaScript (three.JS Library)
  • 3. three.js Basic Workflow Three.js is a cross-browser JavaScript library/API used to create and display animated 3D computer graphics in a web browser. Three.js uses ​WebGL​. WebGL in turn is based on OpenGL​ ES 2.0 and provides an API for 3D graphics. Everything made using three.JS library has three basic elements: 1. Camera​: Used to define view point, front-plane, back-plane and aspect-ratio and viewing angle. Camera can be Perspective or Parallel. 2. Mesh​: It is the basic form of any object which in turn is made up of geometry and material. 3. Light​: Light sources must also be defined appropriately otherwise the object cannot be seen clearly. There are various kinds of light sources like Ambient Light, Directional Light etc.
  • 4. Outline of Steps taken: 1. Create the Scene 2. Create the Renderer 3. Create a Camera 4. Add Lighting 5. Add Meshes(Geometry+Material) to Scene 6. Add Controls 7. Render the Scene Algorithms & Data Structures Data Structure We needed to model the snake using an appropriate data-structure, which fulfils the following requirements: 1. Maintains length dynamically, i.e. length should not be constant. 2. When no food is eaten, length must remain same, but snake must move forward. a. A new cube must be added at the front of current snake. b. The last cube must be removed. 3. If food is eaten by the snake, length should be increased by one. a. Here we need only to add a new cube at front of snake. b. No removal is required as the length is supposed to increase by one unit. As only the head and tail of the snake needs to be updated, we require a data structure that supports the removal and addition at its two ends. So, we must use queues. But, we need to support these addition and removal operations at both ends. The data structure that supports all these requirements is ​Dequeue (Double Ended Queue). In dequeue, elements can be added to or removed from either the front (head) or back (tail) efficiently and easily.
  • 5. Dequeue General JavaScript API Operation Common name(s) JavaScript insert element at back inject, snoc push insert element at front push, cons unshift remove last element eject pop remove first element pop shift examine last element peek last <obj>[<obj>.length - 1] examine first element peek first <obj>[0] Algorithm / Pseudocode: There are basically two main functions having some algorithmic logic: Function​ getRandomFreeLocation​(): x ​=​ random​(​0​,​ rows) y ​=​ random​(​0​,​ cols) for​ i ​in​ ​(​0​,​ rows​): for​ j ​in​ ​(​0​,​ cols​): if​ ​((​x ​+​ i ​)​ ​%​ rows​,​ ​(​y ​+​ j ​)%​ cols​)​ ​not​ ​in​ queue: return​ ​((​x ​+​ i ​)​ ​%​ rows​,​ ​(​y ​+​ j ​)%​ cols)
  • 6. Function​ ​MainRenderLoop​(): takeInput​(); IF collision​(​positionX​,​ positionY​): Display​ ​Score OUTPUT​(​"GAME OVER") Stop​ ​RenderLoop dequeue​.​push​(​newcube​) IF foodEaten​(​positionX​,​ positionY​): SCORE ​=​ SCORE ​+​ 1 food​.​location ​=​ getRandomFreeLocation​() ELSE​: dequeue​.​shift​() calculateNewPosition​(​positionX​,​ positionY​); Snapshots Start of Game Snake starts from bottom-left corner of grid with a score of zero.
  • 7. Initial Score = 0 Growth of Snake As the snake eats more food, its length and speed increases. Speed has been modeled as a linear function of length / score. Score = 25
  • 8. Emergence from other side of wall A snake can enter the wall and emerge from the opposite side. Score = 21 Game Over When snake touches any part of its own body, game is over and final score is displayed. Final Score = 27