Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Project task Create a new class, SnakeGame, which will be used to calculate someones final score. You will be given the game board and the

image text in transcribedimage text in transcribed

Project task Create a new class, SnakeGame, which will be used to calculate someones final score. You will be given the game board and the position of the snakes head, the goal will be to find the position of the snakes tail, and the final length. You will do this by doing both an exhaustive search and recursive search as described below. You will need to also create unit tests using Unit that will test the two methods correctness and the running time (at least 5 for each method independently, or 10 that test both methods at once). Each test should have a comment describing what is being tested. Note the access labeling each element and method below. Elements private bool[][] game -- Stores the final game state, cells that are true contain a part of the snake, and false are the background. Note that in this version of the game the snake will always have a barrier of one cell (i.e. every neighborhood of 9 cells around a portion of the snake will only ever have at most 3 true cells). private int[] headPosition -- Stores the location of the snake's head. private static int exhaustiveChecks -- counts the number of positions checked when performing the tail search using exhaustive enumeration, across all instances of the SnakeGame. private static int recursiveChecks -- counts the number of positions checked when performing the tail search using recursive search, across all instances of the SnakeGame. Constructors the default constructor, which initializes an empty 1 x 1 gameboard, and a constructor that takes a 2-dimensional boolean array, and the x and y position of the snakes "head". Methods public int[] findTailExhaustive() -- will find the tail of the snake by searching across the whole grid to find the grid position where a true element is surrounded by only one other true cell (see figure below), but is not the head, and return 3 items: the x and y position of the tail in the grid, and the length of the snake on the board. Incremenets the exhaustiveChecks counter with each (x',y') cell that is examined. Project task Create a new class, SnakeGame, which will be used to calculate someones final score. You will be given the game board and the position of the snakes head, the goal will be to find the position of the snakes tail, and the final length. You will do this by doing both an exhaustive search and recursive search as described below. You will need to also create unit tests using Unit that will test the two methods correctness and the running time (at least 5 for each method independently, or 10 that test both methods at once). Each test should have a comment describing what is being tested. Note the access labeling each element and method below. Elements private bool[][] game -- Stores the final game state, cells that are true contain a part of the snake, and false are the background. Note that in this version of the game the snake will always have a barrier of one cell (i.e. every neighborhood of 9 cells around a portion of the snake will only ever have at most 3 true cells). private int[] headPosition -- Stores the location of the snake's head. private static int exhaustiveChecks -- counts the number of positions checked when performing the tail search using exhaustive enumeration, across all instances of the SnakeGame. private static int recursiveChecks -- counts the number of positions checked when performing the tail search using recursive search, across all instances of the SnakeGame. Constructors the default constructor, which initializes an empty 1 x 1 gameboard, and a constructor that takes a 2-dimensional boolean array, and the x and y position of the snakes "head". Methods public int[] findTailExhaustive() -- will find the tail of the snake by searching across the whole grid to find the grid position where a true element is surrounded by only one other true cell (see figure below), but is not the head, and return 3 items: the x and y position of the tail in the grid, and the length of the snake on the board. Incremenets the exhaustiveChecks counter with each (x',y') cell that is examined

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Data Science Project Ideas In Health Care Volume 1

Authors: Zemelak Goraga

1st Edition

B0CPX2RWPF, 979-8223791072

More Books

Students also viewed these Databases questions

Question

Brief the importance of span of control and its concepts.

Answered: 1 week ago

Question

What is meant by decentralisation?

Answered: 1 week ago

Question

Write down the Limitation of Beer - Lamberts law?

Answered: 1 week ago