| Programming Project 2 |



getNeighborLabels function will include the me tile value if and only if that value is a neighbor as well, in its output. It will never return duplicates, however.project2.py.getNeighborLabels functionverifyNeighbor function
The getNeighborLabels function takes as arguments, or already knows the value of, the boardWidth and a current tile called me. In general the tiles of a board are always numbered, starting at zero. For example, on a board with a width of 4 and a height of 3, the tiles would be labeled as:
For this function, you will simply be performing the following calculations and storing each value in a list:
Your function should find all the neighbors of the tile me, and return them as a list in sorted order. For example, a call to the function with getNeighborLabels(5,0) (here 5 is the boardWidth and 0 is the me argument) would return the list of neighbors [1, 4, 5, 6]. If the board provided is invalid, (i.e. its width is not a natural number), your function should return a string of invalid board!. You may assume that the me tile will always be an integer, however your method should never return any negative neighbors, as these will be impossible to fit on any board. Note that we don't know if the me tile provided is ever too large, because we do not have the height of the board in this function. You can always assume that the board that would be calling this function provides a valid me tile for this project. If one of the neighbors has the same value as the me, you should include that in the result. Your result should also NOT have any duplicates. |
|||||||||||||||||||||
Although your function above will work in cases where the me tile is in the middle of the board, it will calculate incorrect values if the tile is along an edge. Therefore, we are going to write another function to verify the labels returned by the function above.The second function you will write for this project is called verifyNeighbor. This function takes as arguments a boardWidth, boardHeight, neighbor, and a me tile. For this function, imagine that the tile me is tile 3. Then all of its neighbors would be 2, 6, and 7. A neighbor is any tile on the board that touches (even in a single point) the tile me. A tile has at least three, and at most eight, neighbors. For example, a call to the function with
verifyNeighbor(4,3,4,3) would return False, because although 4 was a neighbor that could have been returned from the getNeighborLabels function, it is NOT a valid neighbor of 3 on this board.
|
getNeighborLabels and one test case of verifyNeighbor. Each test case is two lines long: the first line contains the name of the function, followed by a space, followed by all of the arguments to the function, each separated by a single space, and terminated by a newline. Then, on the next line, you should provide the expected answer for that function call, terminated by a newline. In this case, these expected answers are what our lists would look like if we printed them out; in your tests, make sure you include spaces where they need to be, otherwise they will not diff.driver.py file that will use your tests.txt file and print out whether or not the tests you wrote passed or failed. To use this driver, make sure your project2.py, tests.txt, and driver.py are all in the same directory, and from a terminal in that directory, type:python driver.pytests.txt file to something that Marmoset will understand. We have provided a file for you, called DriverBuild.class (right-mouse click and save this file into the same directory as all of your other files for this project). To use this file, from a terminal in that directory, type:java DriverBuild tests.txtDriverJava.java that you will submit as your test cases for this project. Note that you do not need to know or worry about how DriverBuild.class works (you will be learning about Java in CS211 if you take it), except each time you type the commands above, it will overwrite any older version of DriverJava.java in that directory. project2.py (and remember the link to the template for this file above).
tests.txt above: these tests are the Public Tests on Marmoset.
and, or, is, is not, in, numeric comparison operators (<,>,<=,>=), and the abs(x) function useful for this project. You will also have to use if-else statements, and possibly a for loop. You will need the return statement to get your functions to return a value - DO NOT use the print statement for this!
DriverJava.java file (see above for how to convert your tests.txt file into this DriverJava.java file) on Marmoset following the link to CS112-2T. (The T stands for TEST)project2.py. Normally, Marmoset is set up to work with Java files, which is why we have this workaround. Submit ONLY your project2.py, code.py and SystemCall.java files on Marmoset following the link to CS112-2C. (the C stands for CODE). Find the link on Marmoset to submit Project 2. Once you pass all the public tests, use your tokens wisely to start examining the release tests. Do not change the name of the files.