Snake Tester Project Report

Verified

Added on  2020/06/05

|12
|1657
|1917
AI Summary
This assignment report details the development process of the Snake Tester, a software project that incorporates unit testing and a competitive element. The project involved implementing a client-server architecture with a custom JUnit framework for testing. A unique feature is the integration of hints and solutions for failed tests, along with a score system to encourage friendly competition among students. The report also covers the challenges faced during development, particularly regarding concurrency issues, which were successfully addressed using a volatile flag variable.
tabler-icon-diamond-filled.svg

Contribute Materials

Your contribution can guide someone’s learning journey. Share your documents today.
Document Page
Snake game in Java
tabler-icon-diamond-filled.svg

Secure Best Marks with AI Grader

Need help grading? Try our AI Grader for instant feedback on your assignments.
Document Page
Introduction
Snake is an older classic computer game. It was first created at the end of
70s. Later on it was brought to PCs. With this game the player controls the
snake. The aim is to eat as many pears as possible. Every time the snake
eats a f its body grows. The particular snake must avoid the wall space and
its own body.
The dimensions of each of the joints of a snake are 10 px. The particular
snake is controlled using the cursor keys. Initially, the particular snake has
three important joints. If the game is finished, the particular "Game Over"
message will be displayed in the middle of the table.
Java Code
package Snake_engin;
import javax.swing.JOptionPane;
import m_snake.MainPanel.snakeBody.Food;
import m_snake.MainPanel.snakeBody.snake;
/**
*
* @author SQLStudent
*/
public class engin {
/** Creates a new instance of engin */
public engin()
{
}
public void Move_mySnake(int newDirection,boolean
food_eaten)
{
Document Page
if(!Game_Over)
{
switch(newDirection)
{
case 1: if(direction!=3)
{
my_snake.put_Head_postion(0,-
step_to_move);
direction=1;
}
else move_as_last(direction);
break;//UP
case 2: if(direction!=4)
{
my_snake.put_Head_postion(step_to_move,0);
direction=2;
}
else move_as_last(direction);
break;//RIGHT
case 3:
if(direction!=1)
{
my_snake.put_Head_postion(0,step_to_move);
direction=3;
}
else move_as_last(direction);
break;//DOWN
case 4:
Document Page
if(direction!=2)
{
my_snake.put_Head_postion(-step_to_move,0);
direction=4;
}
else move_as_last(direction);
break;//LEFT
}
if(food_eaten)
{
my_snake.Increase_lenght();// IF the Snake ate new
Food
}
my_snake.Move_snake();
if((my_snake.getHeadX()==snakeFood.get_int_X())&&(my_snake.getHea
dY()== snakeFood.get_int_Y()))
{
snakeFood.getFood();
Score+=20;
my_snake.Increase_lenght();
while(check_food_place())
{
snakeFood.getFood();
}
}
tabler-icon-diamond-filled.svg

Secure Best Marks with AI Grader

Need help grading? Try our AI Grader for instant feedback on your assignments.
Document Page
Game_Over=my_snake.check_game_over();
}
if(Game_Over)
{
JOptionPane.showConfirmDialog(null,"Score =
"+Integer.toString(Score),"Your
Score",JOptionPane.DEFAULT_OPTION);
// Thread.yield();
}
}
public void move_as_last(int diirec)
{
switch(direction)
{
case 1:
my_snake.put_Head_postion(0,-
step_to_move);
break;//UP
case 2:
my_snake.put_Head_postion(step_to_move,0);
break;//RIGHT
case 3:
Document Page
my_snake.put_Head_postion(0,step_to_move);
break;//DOWN
case 4:
my_snake.put_Head_postion(-step_to_move,0);
break;//LEFT
}
}
public int[] return_Snake_postionsX()
{
return my_snake.get_All_postionsX();
}
public int[] return_Snake_postionsY()
{
return my_snake.get_All_postionsY();
}
public int get_Oval_size()
{
return my_snake.getOval_Size();
}
public int get_my_snake_lenght()
{
return my_snake.get_lenght();
}
public void set_step_length()
Document Page
{
step_to_move=5;
}
public int get_Food_X()
{
return (int)snakeFood.getX();
}
public int get_Food_Y()
{
return (int)snakeFood.getY();
}
public boolean check_food_place()
{
int xfood=(int)snakeFood.getX();
int yfood=(int)snakeFood.getY();
if(xfood>260||yfood>260)return true;
else
return my_snake.compare_with_foodPostion(xfood,yfood);
}
public boolean get_Game_over()
{
return Game_Over;
}
private int direction=2;
private boolean Game_Over;
private boolean Moving_vertical=false;
private snake my_snake=new snake();
private final Food snakeFood=new Food();
private int step_to_move=20;
private int Score;
}
tabler-icon-diamond-filled.svg

Paraphrase This Document

Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser
Document Page
Unit Test
The particular Snake Tester aims to help the students in their
understanding by enabling them to check their own code as they create it,
to check it works the required outcomes. In addition to this, the particular
students can also learn more independently by using the hints and options
that are attached to each job, and only shown to the pupil when one or more
of the assessments fail. Initially the Snake Tester was the selection of JUnit
tests created concurrently with the worksheets. The particular tests had
been packaged like a Coffee ‘ or Store. jar’ file, and put into the skeleton
code task as a dependency, making use of comparative coping with so that
the learners could copy and paste within new versions of the Specialist
program in future classes. The students could operate the tests by simply
managing a file called ‘SnakeGameTestRunner after that. java’ that was
included in the bones code also. Nonetheless, it had been observed in the
teaching periods that the students initially discovered the test results
confusing, because executing the selection gives 20 test results, without
sign of which task the given test was related to. This led to the development
of the custom JUnit test runner architecture that will tracks the progress of
every consumer, and adaptively unveils tests consistently with the
improvement of the user. It was at first considered whether to create a
check runner architecture from scratch, in order that it could be built from
the ground as much as support the project, such as the progress tracking
Document Page
and ideas and solutions aspect. Even so, after exploring the extensibility of
the existing JUnit structures, it was decided that this might be used instead,
meaning that a lot of the existing test runner construction could be reused,
and period spent instead on the improvement tracking and hints plus
solutions aspects that are particular to this project.
Progressively more independent when developing their particular software,
the particular further element of the Snake Tester has been implemented to
allow students in order to easily see which duties are associated with the
failed testing. A windowpane is then proven to the user that includes control
keys to access the particular hint for just about any unsuccessful tasks. If
that one test has failed through minimum three times, the particular button
to exhibit the full solution for this task is enabled. It was to ensure the
learning students produced the real effort to accomplish each task before
having the ability to view the solution.
The particular report collector is the particular server component for the
Snake Tester, allowing the machine to run on one machine upon the local
network, plus acknowledge connections from customers (other computers
on the network) which send the created report. In order to introduce an
component associated with competition, each report (identified uniquely by
Document Page
the username from the pupil who is logged in) also has a score, depending
upon how a lot of tests have handed, and whether or not the solution or
even hint was accessed, enabling the university students to get into friendly
competition to see who also can get the best score. Simply by collecting and
displaying the final results, this also allows the trainer to be able to track
the improvement of all the students in the course, and can compare scores
among college students, and see which workouts are causing the most
problems so that they know to focus training more on that area.
In early stages during the growth of this element, issues with concurrency
arose, since the Hint UI was shown on a separate thread that was getting
disposed when the check run ended. However, it was fixed by using a ‘flag’
adjustable with the volatile modifier to do something as a guard, blocking
performance until the guard is transformed. The volatile modifier helps to
ensure that changes to variables are usually visible across threads. The
particular flag was set to fake and the program enters a good infinite loop
initially, till the Hint UI window will be closed. When the UI can be closed, a
listener mounted on the window updates the significance of the flag
variable, permitting set up to proceed.
tabler-icon-diamond-filled.svg

Secure Best Marks with AI Grader

Need help grading? Try our AI Grader for instant feedback on your assignments.
Document Page
To obtain a level of confidence the fact that computer software components
of the task were working as designed, the suite of unit testing were also
developed together with the project. In total, you can find tests that cover a
variety of functionality within the project forty-one, checking out areas such
as the results selection (from the custom JUnit framework), the particular
protocol responsible for handling communications between the client and
machine, plus testing that files are usually written correctly. Additionally, it
includes some nonfunctional testing, for example to test that all check
methods (i. e individuals with an ‘@Test’ annotation), also provide an
‘@Task’ annotation, to make sure that all test methods come with an
associated task
Document Page
References
Koenig, Sven and Xiaoxun Sun. “Comparing Real-Time and Incremental Heuristic Search for Real-Time
Situated Agents”. Autonomous Agents and Multi-Agent Systems. Volume 18 Issue 3, 2009.
Korf, Richard E. “Real-Time Heuristic Search”. Artificial Intelligence. 1990:190-211 Likhachev, Maxim, et
al. “Anytime Search in Dynamic Graphs”. Artificial Intelligence. Volume 172 Issue 14, 2008.
Russell, Stuart and Peter Norvig. Artificial Intelligence: A Modern Approach. New Jersey: Pearson
Education, 2010.
chevron_up_icon
1 out of 12
circle_padding
hide_on_mobile
zoom_out_icon
[object Object]

Your All-in-One AI-Powered Toolkit for Academic Success.

Available 24*7 on WhatsApp / Email

[object Object]