Snake Game
Snake Game
Snake Game
A
Minor Project
On
Bachelor of Technology In
Engineering Submitted To
Submitted By
CERTIFICATE
This is to Certify That Major Project Project Entitled “SNAKE GAME ” Submitted to Rajiv
Gandhi Proudyogiki Vishwavidyalaya, Bhopal (M.P.) by “Narendra Vishwakarma Sandeep Brar
” for Partial Fulfilment for the Award of the Degree of the Bachelor of Technology in Computer
Science & Engineering.
Sandeep Sharma
HOD (CSE)
PDSCT, CHHATARPUR(M.P.)
ACKNOWLEDGEMENT
This is one of the best moments of my B.Tech. program to publicly acknowledgment those who
have contributed in many different ways to make my success a part of their own. The completion
of the Minor Project depends upon the co-operation, coordination and combined effects of
several resources of knowledge energy.
I heartily thanks to Prof SUJAL AGARWAL ,who have supported in miner project, faculties
of Department of Computer Science & Engineering, for accepting me to work under their
Valuable Guidance, Closely Supervised this work over the past few months and offering many
innovative ideas and helpful suggestions, which led to the successful completion of this
dissertation work.
I am especially thankful DR. J. SONI , Director, PDSCT, Chhatarpur for his kind co-
operation and rendering me all possible facilities.
I am thankful to Mr. Sandeep Sharma and all staff members of the CSE department and my friends
for their timely help co-operation and suggestion during my project work. Lastly but not the least, i
must express thanks to my family, without their moral support it was impossible for me to complete this
minor project work.
Sandeep Sharma
HOD (CSE)
PDSCT, CHHATARPUR(M.P.)
Table of Contents
1 Acknowledgment.......1
2 Abstract......................2
3 Objectives.......................................................................................................................3
4 Programming Environment............................................................................................4
5 Methodology..................................................................................................................5
5.1 iSnake Client Application.........................................................................................6
5.1.1 Client Encoder/Decoder....................................................................................6
5.1.2 Client Network Interface...................................................................................6
5.1.3 Input Handler.....................................................................................................6
5.1.4 Game Field Matrix.............................................................................................7
5.1.5 Game Field Canvas.............................................................................................7
5.1.6 User Interface Components..............................................................................7
5.1.7 Game Controller................................................................................................7
5.2 iSnake Game Server................................................................................................8
5.2.1 Server Encoder/Decoder...................................................................................8
5.2.2 Server Network Interface..................................................................................8
5.2.3 Virtual Game Field.............................................................................................9
5.2.4 Player Information Manager.............................................................................9
5.2.5 Random Number Pool.......................................................................................9
5.2.6 Status Server......................................................................................................9
5.2.7 Server Core......................................................................................................10
5.3 Intelligent Autonomous Opponent Snakes...........................................................10
5.4 iSnake Game Server Manager (GSM) @ SF.net....................................................13
6 Project Management...................................................................................................14
7 Documentation............................................................................................................16
8 Limitations....................................................................................................................16
9 Future Enhancements..................................................................................................17
10 Conclusion..................................................................................................................17
11 References..................................................................................................................18
1 Acknowledgment
We offer gratitude to project supervisor Asst. Prof. Jayaram Timsina (Deputy HOD, Dept. Of
Electronics & Computer Engineering, IOE Pulchowk Campus) for guiding us throughout the
project.
1
2 Abstract
This project aims to bring the fun and simplicity of snake game with some new features. It will include
computer controlled intelligent opponents whose aim will be to challenge the human players. It will
also have the multiplayer feature that will allow more than one players to play the game over a
network.
This project explores a new dimension in the traditional snake game to make it more interesting and
challenging. The simplicity of this game makes it an ideal candidate for a minor project as we can
focus on advanced topics like multiplayer functionality and implementation of computer controlled
intelligent opponents.
3 Objectives
This game aims to change the way people think of traditional snake game. It will offer the
experience of commercial multilayer games to the player retaining the simplicity of traditional
snake game.
● Create a snake game that will have all the functionality of traditional snake games.
● Introduce multilayer functionality in the game that will allow several players to play a
game simultaneously. It should be able to give the experience of a real time
multiplayer game to the players.
3
4 Programming Environment
We used several open source tools to develop this project:
All the developers of iSnake team used Netbeans IDE for the development of this project.
These graphics development tools were extensively used for the development of User Interface
components. The illustrations presented in this report have also been prepared using these open
source tools.
● Gnuplot
The data obtained during profiling of two path finding algorithms viz. Blackmamba and Viper
was plotted using gnuplot.
All the project documents and this report were prepared using OpenOffice Writer 2.2.
During the development of iSnake Game Server Manager (GSM) @ SF.net, Wireshark tool
was used to analyze the network traffic.
5 Methodology
iSnake is a multiplayer version of traditional snake game (popular among cell phone gamers) with
computer controlled intelligent opponents that challenges the human players.
The player who hosts the game server is called “local player”. The iSnake Client Application and
Game Server run in separate execution domains. The iSnake Client App. for local player communicates
with the game server through network layer, just like other remote players, as shown in illustration 1.
5
5.1 iSnake Client Application
iSnake client application refers to the application used to play snake game. A player joins an
already existing iSnake game server using this application.
The update of game field canvas occurs in the way similar to the refreshing technique of
a cathode ray monitor. The game field matrix and game field canvas are updated in separate
thread. The update of game field canvas starts by scanning each column of the 1st row in the
game field matrix, then 2nd row and so on upto the 58th row. The game field is refreshed twice
during each game cycle (two refresh cycle for game field canvas for each game cycle). This is
done make the movements in the game field smoother.
7
received from the game server. Game Controller maintains the game cycle when the game is
running. This game cycle is synchronized with the game cycle of the game server. All the updates
to game field matrix are done during this cycle time. After expiry of each game cycle the
game field is repainted to reflect the changes in the game field.
It is maintained by the game server to check whether the food has been eaten and whether
any player has collide with the wall. It maintains the head coordinate (not the coordinates for tails)
of each player. The head coordinate of players is moved in each game cycle and checked for the
presence of wall/food in that coordinate position. Server Core generates corresponding event
(collide or food eaten) and all the active players are informed about the event in the same cycle.
If the random number service is unreachable pseudo random numbers are generated
using java.util.Random class provided by Java.
9
A typical response of Status Server is given below:
When the game is in "Waiting" mode, Server Core provides the facility of chat messaging
to the game players. During this state new players can join the game.
When all the players have sent signal to start the game, the Server Core changes
state to “Running” mode. If a new player tries to join the game, it receives a “NAK” response.
In this mode, Server Core maintains a game cycle time during which it receives the movement
coordinates (in terms of deltaX and deltaY) from the players. If a player does not send any
packet during this cycle time, server considers the movement coordinate sent in last cycle for the
current game cycle. After expiry of cycle time, game server broadcasts a packet containing
movement coordinates of each player to all the players active in the game. The game server also
checks if any player has eaten the food or if any players have collided to the wall in each cycle.
A detailed paper describing the algorithm used by these two implementation is present in
ANNEX A and ANNEX B. The module implementing these two path finding algorithm easily fits
into the existing design of iSnake Client Application as shown in Illustration 4
Illustration 4: Module implementing two path finding algorithms replaces the Input Handler
module of standard iSnake Client application.
To know which of the two implementations perform better, we profiled them using a simple
JUnit test and the results were plotted using gnuplot:
11
Illustration 5: Turn around time for Illustration 6: Length of path returned
two path finding algorithms by the two path finding algorithms
The time elapsed between the instant of supplying the (source,target) coordinate pair
(S,T) to the algorithm and the instant when it returns a path for supplied (S,T) pair is called turn
around time. From the plot of illustration 5, it is clear that the turn around time for Viper is
always smaller as compared to Blackmamba.
The length of path (computed by counting the number of game field coordinates in the
path) returned by the two path finding algorithms is depicted by the plot of illustration 6. It is
clear from the plot that Viper implementation results in smaller paths (and hence efficient) as
compared to Blackmamba implementation.
NOTE: The value of turn around time and path length for the coordinate pairs 5,7,8 have
negative values for Blackmamba. This suggests that the algorithm was not able to compute a path
for given (S,T) pair in given timeout period (250 ms for this test).
5.4 iSnake Game Server Manager (GSM) @ SF.net
iSnake Game Server Manager (iSnake – GSM) hosted at http://isnake.sf.net is used to manage all
the information about iSnake game servers being hosted over the Internet.
The iSnake application deployed at our website has been digitally signed by the iSnake
team to address the security issues related to launch of Internet applications.
13
6 Project Management
The first thing we did before starting the work on iSnake was to register a project at Sourceforge4.
Apart from hosting services, it provided us several code and project management services.
Illustration 8 shows the svn commit statistics for the isnake code repository at sourceforge. We
collaborated on project documents (including prototype designs, project plan, TODO list, etc) using
WIKI (http://isnake.wiki.sourceforge.net).
JUnit tests were developed to independently test some of the modules before integration. The
integration of modules developed by the three developers was performed in three phases:
● Phase 1 Integration (Sep. 28, 2007) chat functionality of the game was tested
successfully
4 http://www.sourceforge.net
● Phase 2 Integration (Oct. 06, 2007) successful testing of basic version of
multiplayer snake game
● Phase 3 Integration (Feb 17 26, 2008) – integration of all the modules for iSnake
0.1 Beta release.
7 Documentation
Documentation of every task being done in the project was a priority for all the team members. Almost
every portion of the source code contains full code documentation conforming to Javadoc standards.
Illustration 9: Screen shot of a snippet of source code showing method comments conforming to
javadoc standards.
There exists two path finding algorithms that implements intelligent opponent in the game viz
Blackmamba and Viper. These two algorithms have been fully documented with illustrations5.
The protocol devised for communication between game server and clients has been documented in
ANNEXD.
8 Limitations
The limitations of present implementation of iSnake are:
● The present implementation of iSnake can only be played in LAN. Due to large
latency time and bandwidth limitation, it cannot be played over the Internet.
● Path finding algorithms (Blackmamba and Viper) implemented in this game have
their own computation limitations which has been describe in ANNEX A,B.
5 Refer to ANNEX – A,B
● Full stress test of the application has not been done yet. Hence, the response of game
server in unpredictable situations cannot be handled properly.
9 Future Enhancements
● Port iSnake to cell phone platform and One Laptop Per Child – OLPC (which uses
Sugar Desktop environment). The presence of several connectivity options(Bluetooth,
WIFI, GPRS, CDMA) in cell phones makes it a very attractive platform for a
multiplayer game like iSnake. Local WIFI network formed by kids using OLPC laptops
can be used as a platform for iSnake's deployment.
● As iSnake game server communicates with remote playing using a well defined and
very simple protocol (Refer to ANNEX D), iSnake clients programmed in other
programming platform like Flash, Python, etc can be developed.
Gaming instraction :-
Play game :-
11.Conclusion
We were successful in creating a multiplayer version of traditional snake game. The computer
controlled intelligent opponents have been successfully tested in the game is a unique feature of
iSnake.
We learned several project management techniques used by professionals to develop large scale
project. The experience of working in team and integration of modules developed independently, with
just requirement specifications, is a very important achievement for the iSnake team.
12. References
Books
Websites
http://wiki.netbeans.org/wiki/view/CommunityDocs
http://inkscapetutorials.wordpress.com/
http://www.smashingmagazine.com/
http://java.sun.com/docs/books/tutorial/
5. Timing Framework
https://timingframework.dev.java.net/
6. JavaGaming.org's Forum
http://www.javagaming.org/forums/index.php
7. MIT Open Course Ware - 6.831 User Interface Design and Implementation
http://ocw.mit.edu/OcwWeb/ElectricalEngineeringandComputerScience/6831Fall
2004/CourseHome/index.htm
http://theory.stanford.edu/~amitp/GameProgramming/
http://arianne.sourceforge.net/
http://community.java.net/javadesktop/
http://forum.java.sun.com
http://www.curiouscreature.org/
http://www.filthyrichclients.com/
http://warriors.eecs.umich.edu/games/papers/quakefinal.pdf
http://www.exampledepot.com/
http://mina.apache.org/
library http://www.php.net/
18. Quantum Random Bit Generator Service (QRBG)
http://random.irb.hr/
ANNEX – D2
D 1