In this lab, you'll practice using arrays and vectors to solve programming tasks.
By the end of this lab, you should be more comfortable...
- interacting with 2D arrays
- tracing function calls
- creating complex Boolean expressions
- implementing pseudo code
Download gridworld.cpp. This is a mostly implemented game in which a 2D world is represented as a grid of chars. The player, represented as the char 'A', can move up, down, left, or right on the grid, attempting to avoid enemies ('&'), pick up treasure ('$'), and reach the goal ('X'). Movement is shown by printing out the grid after every move. There are four TODOs spread out across three functions, which you should locate and complete in this order:
- printWorld (1 TODO)
- getMove (2 TODOs)
- updateWorld (1 TODO)
Before you start, read through the code to see what global variables and constants there are, what functions there are, and how the functions connect (you don't need a deep understanding of functions at this point). Note that this does not use the zyBook convention of placing function definitions above main, but rather puts function declarations above main and function definitions below main.
Implement each TODO incrementally: don't wait until you're totally done a TODO to compile and test; go for small wins to build confidence, ensure you're on the right track, and to focus your debugging.
We'll go over each of TODO after 20 minutes.
Upload your .cpp file with what you've accomplished at the end of lab to this assignment.. Your grade for the lab is based on effort, not whether you complete all of the assigned problems; you will get full credit as long as you work diligently during the 2-hour lab period.
Please see the syllabus and course schedule (both on the homepage) for more information about how many programming assignments you are required to pass, due dates, etc. Of note: you do not need to attempt every or even most PAs.