Info Lectures Assignments Staff Office Hours Hall of Fame Notes
Info Lectures Assignments Staff Office Hours Hall of Fame Notes

Snake

Assigned: 2020-04-06
Due Date: 2020-04-14 by 11:59PM U.S. Central Time


Assignment Spec

The rubric can be found here.

Gradescope

You will need to submit your GitHub repository to Gradescope.

Part 0: Getting Started

Get your copy of the repository here: https://classroom.github.com/a/pygIQb9Z

This assignment will use the Cinder framework. You can download the latest version Cinder for your platform here. The latest version is v0.9.2.

Here is a basic tutorial on how to develop Cinder projects: https://libcinder.org/docs/guides/tour/hello_cinder_chapter1.html.

Here is some documentation: https://libcinder.org/docs/reference/index.html.

Setting up Cinder + Snake

Windows Users: READ THIS!!!

Cinder v0.9.2 was built with Visual Studio 2015 in mind. Thus, in order to build Cinder on Windows, you'll need to downgrade your Microsoft Build Tools to v140 or v141. Note that for the C++ TicTacToe assignment, you probably only installed v142. So, below is a short guide on how to do this:

  1. Uninstall Visual Studio Build Tools 2019 if present on your machine by navigating to Control Panel > Programs > Programs and Features > Uninstall a Program, and then uninstall Visual Studio Build Tools 2019.

  2. Go to: https://my.visualstudio.com/Downloads?q=visual%20studio%202015&wt.mc_id=o~msft~vscom~older-downloads. You'll also be able to access this page by going to https://my.visualstudio.com/downloads and searching for 2015.

  1. Next, download Visual Studio Community 2015 with Update 3 for your architecture (probably x64).

  2. Run the installer and if prompted, select Modify.

  3. Now, you only need to select the Common Tools for Visual C++ 2015 option, then click Next. Note that this will take up around 8GB on your machine.

  1. Continue along with the installation. The installation process can take a while (~20 minutes).

  2. After the installation is complete, do not need to click the "Launch" button.

  3. Go back to CLion and make the default toolchain be a Visual Studio environment, pointing to C:\Program Files (x86)\Microsoft Visual Studio 14.0. Confirm that there are no warnings.

That's it!

As an added bonus, you now have Visual Studio 2015 installed if you ever want to use it in the future after this class is over.

  1. Download Cinder (v0.9.2) for your platform. Extract the downloaded item into a folder. We’ll call this folder ~/Cinder throughout the instructions
  2. Open the ~/Cinder folder in CLion and click the green build button. This will build libcinder. You only need to do this once per machine. This build might take a while.
  3. Create a directory, say my-projects in ~/Cinder. Clone the snake project into this folder. You can checkout your repository here:
  4. Open the snake project in CLion, set the target to cinder-snake and click the run button.

MacOS users: It’s possible that you may come across:

Error running 'cinder-snake': Cannot run program … cinder-snake.app/Contents/Resources"): error=13, Permission denied

In this case, try doing: Edit configurations -> Executable -> Select Other -> Find my-projects/snake/cmake-build-debug/Debug/cinder-snake/Contents/MacOS/cinder-snake And click run once again.

Setting up the Database (SQLite)

  1. In CLion, navigate to View > Tool Windows > Database.
  2. Next, in the Database window, select the Database properties button, which is between the Refresh and the Stop button.
  3. There are two possibilities now: i. If properties for snake.db are automatically selected, you can proceed to Step 4. ii. If there are no database properties selected, navigate to Add > SQLite.
  4. Next, there should be a highlighted link to download the necessary drivers for SQLite. Click this link.
  5. For the file of the datasource, select snake-<your-netid>/assets/snake.db.
  6. Press Test Connection to verify that the driver is set up correctly. Click the OK button in the
  7. Now, you should run the cinder-snake target and play the game to test out your database.
  8. After the cinder-snake application has run, go back to the Database tab, click the Refresh button. You should now be able to see the schema of the database under snake.db > schemas > main > leaderboard. Also, you’ll be able to manually execute queries by clicking the Jump to Console button at the top.

Interfacing through the program arguments

There are 4 different flags for the program (which you can modify via Edit Configurations -> Program Arguments):

Part 1: Database Interaction

Every time the snake game is run, the following should be executed in order:

  1. Create a leaderboard table in the database if it does not already exist
  2. Add the name and score of the player into the leaderboard table after the game has ended
  3. Display the top players and their respective scores after the game has ended
  4. Display the top scores of the current player.

The logic and SQLite query for item 1 has already been provided to you.

The logic for item 2 and 3 have already been provided, but you will need to write the query for this.

For item 4, you’ll need to write the logic and the query. Don’t worry too much about the format of the text in the application: all that matters is that the current player’s high scores are visible somewhere.

The queries for the leaderboard can be found in src/leaderboard.cc. The code will likely crash after the game ends due to the SQLite queries being initially empty/incorrect. You may find it helpful to use try/catch statements in apps/snake_app.cc or in src/leaderboard.cc in order to catch these exceptions, thus avoiding fatal unhandled exception messages.

We are using the SqliteModernCpp library to make SQLite queries from C++. Take a look at the examples here: https://github.com/SqliteModernCpp/sqlite_modern_cpp/tree/dev.

There is great documentation on SQLite, which can be found here: https://www.sqlitetutorial.net/. Please try to play around with the local database that you have before asking questions on Piazza. The SQLite syntax is very intuitive.

Part 2: Customize Snake (Extensions)

In apps/snake_app.cc and apps/snake_app.h, you’ll find the main GUI code for snake. Implement each of these features, and make sure to test after you implement them:

If you want to use a CinderBlock for any of this, you can clone the CinderBlock into your ~/Cinder/blocks directory, and then place the name of the directory of the cloned directory into the BLOCKS argument in apps/CMakeLists.txt. See more info here: https://www.libcinder.org/docs/guides/cmake/cmake.html#building-your-application-with-cmake. Note that the first part of this link isn’t relevant since CLion will invoke the necessary CMake commands for you when building.

Part 2b: Extra Credit

You can receive extra credit for extending the Snake application in any interesting way. The more significant and interesting the extension the more points you can receive; in general, each hour of additional work is a point of extra credit.

Grading and Deliverables

This is not a coding-heavy assignment; we expect most of your time to be spent on getting your IDE set up with Cinder. Spend the time now troubleshooting your build environment, rather than later!

If you run into any build or linking errors, please post them to Piazza. It can be difficult to fix these problems on your own.

Known Bugs

Here is a list of bugs that we would like to document: