Looking for Help with Assignments?
-RUCats has 80 hours of tutoring available online and in-person. Check the tutoring tab in Canvas!
-Instructors and Lead TAs have a combined 10 hours of Office Hours, open to all sections. See times/locations here.
-Piazza (found in the Canvas sidebar) provides fast support from Course Staff and other Students. Be sure to search to see if someone has asked a similar question!
-If you need a computer to complete work on, iLab machines can be found in the CSL (Hill 252) and surrounding rooms.
Board Game Debugger - 10 Course Points
The purpose of this assignment is to learn how to use the Java Debugger to investigate code as it runs, to track down bugs.
Make sure you install all required VSCode extensions and remove any unnecessary ones before starting. View the Course FAQ page for more info
You can download and submit the project files via Autolab.
What is Debugging?
Writing code is prone to bugs (mistakes), and when bugs do occur we need an efficient way to pinpoint where they are coming from. Often, when programs have mistakes they show a Compiler Error (red squiggily underline on VSCode), or throw an Exception, which is a Runtime Error, and crash the program. These both tell you their direct cause, allowing you to fix them.- Compiler error: VSCode shows you a red squiggly underline. Basically like a grammar/spelling issue.
- Runtime error: Java shows you the call stack and which lines generated the exception. This is an error which signals an issue with the program while it’s running.
Using the Java Debugger
As with the rest of the course, we will be working within VSCode for this Lab. Make sure you’ve installed all required extensions and removed any unnecessary ones, as stated on our Course FAQ page. So far, you have most likely been running your programs using either the commands line (with compile commands), or using the VSCode run button. Now, you can use the drop down menu on the Run Button and select “Debug Java” to run the program in Debug mode instead.

Breakpoints
Breakpoints allow you to define certain lines for the program to pause running at, while running in debug mode. This is extremely useful, as it allows you to investigate specific edge cases, or specific parts of the bugged code. You can place a breakpoint by clicking to the left of the line number you want pause at. Breakpoints are represented by a red circle.







Debugger Toolbar
After the program pauses at a breakpoint, we want to be able to control it from there, and execute any number of lines, or continue running until the end. To do this, we can use the Debugger Toolbar. The debugger toolbar appears when running a program (even in non-debug mode). For any program that is actively running (for example, when you have the Driver open), the toolbar will appear as follows:





Memory Viewer
Also while the program is paused, you can use the Memory Viewer to inspect variable values. The memory viewer can be accessed through the left sidebar, under the “Run and Debug Menu”




Debug Console
The final tool you will need to debug (and complete this Lab) is the Debug Console. The Debug Console is a special terminal, which can be accessed with Ctrl + Shift + Y (for Mac, use Command instead of Ctrl). The debug console allows you to write and run singular lines of code, and print their output. For example, you can simply enter primitive values, and it will print those values back to you.

Overview
To complete this Lab, you will not need to write ANY code. Instead, you will run the Driver.java class and use it with the debugger to generate your submitted file.- The Driver class prints a small intro in the terminal, then asks for your netID. Enter your correct netID (ex: abc123, not your 9-digit RUID), then click the “Run Island” button. You can change the SKIP_INTRO variable in Driver.java to true, to disable this intro.
- After receiving your netID, the game will instantly simulate and end. Then, you will be asked a series of random questions about your game. Your netID + answers will print to an answers.out file.
- This “answers.out” file is the one you submit.
- In other words, you are going on a scavenger hunt using the debugger. You must find the requested pieces of information and enter them in the driver, then submit the printed “answers.out” file to Autolab.
Provided Classes
You are provided a number of supporting classes which comprise the game. The game/stdlib package contains the StdIn, StdOut, and StdRandom classes, used for input/output and the random chances The game/values package contains:- Effects.java – all of the random tile effects
- Questions.java – all of the possible game questions
- RandomChances.java – holds max/min game board length, roll, and pieces.
Directions
You MUST use your own NetID when running the Driver, or you will receive a zero on the Lab.- DO NOT add new import statements.
- DO NOT add any new class attributes
- DO NOT change any of the method’s signatures.
- DO NOT modify the given constructor.
- DO NOT modify any code related to game behavior.
- Modifying game behavior may cause you to find different answers than Autolab.
- You may mainly add if-statements to check logic for print statements. Do not use break, continue, return, or other similar keywords.
To Run: Run in Debug Mode through VSCode, ensuring you open the correct innermost BoardGameDebugger directory.

Driver
The Driver class will at first show a short intro, welcoming you to the board game. Then, it will prompt you for your netID (abc123 form NOT your 9-digit RUID). After you enter it, the game will automatically start. The game will instantly simulate, and end. After this, the driver will ask you 6 random questions from the 10 below about the game in general as well as your specific random game. You must use the debugger to find the answers to these questions, then enter them in the driver. NOTE: You must use the “Continue” or “Step Out” buttons to continue past ALL breakpoints after starting the game with your netID. While you are paused at any breakpoint, you will not be able to interact with the Driver. The Driver will print a questions.out file, which is provided for you to reference the questions without rerunning the program. You will NOT submit this file. After all questions are answered, the driver will print them to an “answers.out” file in your project directory. This is the file you will submit. Make sure to save your answers somewhere when you rerun, so they don’t get overwritten.Answer Formatting
- For number answers, DO NOT add use words or punctuation.
- EX: if there are 5 pieces, don’t write “Five” or “5 pieces”, write “5” (without quotes).
- Answers are case insensitive, and leading/trailing spaces are trimmed.
- Make sure to check your spelling of piece names.
Question Help
(the question numbers below may not line up with your question numbers)
Question 1: How many turns did the game last?- Look in BoardGame.java. Set a breakpoint wherever the game ends in nextTurn(), and check what turn it is using the variable viewer.
- Look in BoardGame.java. Set a breakpoint anywhere in nextTurn(), and check the numPieces class attribute.
- Look in RandomChances.java, for the corresponding static variable.
- Look in RandomChances.java, for the corresponding static variable.
- Look in RandomChances.java, for the corresponding static variable.
- Look in BoardGame.java. Set a breakpoint anywhere in nextTurn(), and check the boardLength class attribute.
- Look in BoardGame.java. Set a breakpoint at line 135 in createBoard(). Right click on it, to edit it, and add the condition tile == Tile.BONUS. Finally, run the program and count how many times it hits that breakpoint, to count the number of BONUS tiles placed on the board.
- Look in BoardGame.java. Set a breakpoint wherever the game ends in nextTurn(), and check what tile each piece is on using the variable viewer.
- Look in BoardGame.java. Set a breakpoint wherever the game ends in nextTurn(), and check how many coins each piece has on using the variable viewer.
- If this question has more than one correct answer, give only one of them.
- Look in BoardGame.java. Set a breakpoint wherever the game ends in nextTurn(), and check how many coins each piece has on using the variable viewer.
- If this question has more than one correct answer, give only one of them.
Before submission
DO NOT MODIFY THE answers.out FILE. You MUST print this file using the Driver.
You MUST use your own NetID when running the island in the Driver, or you will receive a zero on the lab.
Collaboration policy. Read our collaboration policy on our course syllabus.
Submitting the assignment. Submit your answers.out file separately via the web submission system called Autolab.
Getting help
If anything is unclear, don’t hesitate to drop by office hours or post a question on Piazza.
- Find instructors and Lead TA office hours here
- Find tutors office hours on Canvas -> Tutoring
- In addition to office hours we have the Coding and Social Lounge (CSL) , a community space staffed with ilab assistants which are undergraduate students further along the CS major to answer questions.
By Colin Sullivan