CS311 Project 4: Arranging Data for Quick Retrieval

Due Monday, May 6, at 10:30 AM (start of the final exam)

Many games, such as The Battle for Wesnoth, require the management of a large number of character classes, preferably with some means of quick retrieval by an id. The units can then be retrieved at will, properties queried, etc. When defining a map, the creator of the map can simply derive most properties of a character by their class. Note that generally more than one instance can be made of a particular character class (i.e. there may be more than one goblin, more than one elvish archer, etc). There are many ways this data can be organized, but for this assignment you must choose either a tree or a hash table. Any of the class examples, data structures from the STL, or your own creation are all good ways to solve this assignment.
The data from the Battle for Wesnoth is zipped and posted here. Note that the entire game is open-source, and you can simply download the entire game from the official website instead if you prefer, and then you can play it too, and have a more up to date version. The above link is just for convenience. Also, on debian-based systems, "apt install wesnoth" will install the game, and place the data directory at /usr/share/games/wesnoth. It is available in that directory on isoptera, although it is difficult to actually run the game on isoptera. The .zip archive above is a zip of /usr/share/games/wesnoth/1.14/data/core/units from isoptera.
Inside the data directory, core/units contains unit description files. Create a class to represent a character class, read all the files in the units directory (they're inside subfolders by type), and load them into a data structure. Then, present a user interface that will allow the user to enter the name of a character, and result in the statistics for that character being displayed. For each character class, at a minimum include the description, level, cost, usage, and movement. Feel free to include other data if you like. Parsing the text files can be doing using any means you find useful, including Linux command-line tools, built-in C++ routines, etc. Consider it a good practice exercise with string manipulation.

Suggestion for Approaching this Project

I'd recommend doing this project as a series of steps:
  1. Write the parsing routine for single text files. Text it by extracting the strings you'll need, and printing them out.
  2. Define a class to represent character classes. Include an output routine, to print out the relevant information if queried. It might be worth considering integrating the parsing routine into the class. For example, you could have a constructor that takes a filename, which will parse out the various information to initialize the class.
  3. Set up a hash table or tree to hold classes, and test it with a few classes populated from a few selected files.
  4. Develop the user interface, so the user can make queries.
  5. Add a routine that will traverse the directory structure and populate the hash table or tree with all the character classes from the game.
There are certainly plenty of other ways to order your approach, so don't feel constrained by the list above! It's just intended to answer the question "Where do I start?".

Turning in the project

Upload your project in the usual spot
.