Gridhunt2

Gridhunt2 is a small game written in C++ used to teach students basic OO concepts like encapsulation, composition, inheritance and polymorphism.

The objective of gridhunt is to implement a hunter who can catch the monster faster than all other hunters. Gridhunt uses a 30x30 grid of squares and a monster moves on this grid. Gridhunt is turn-based. In each turn each hunter gets 1-5 points which she/he can use for actions (e.g., move to an adjacent square, find out where the monster is; teleport to a random location on the grid). A hunter catches the monster if she/he moves on the same square the monster currently occupies first. If the monster survives 100 rounds the monster wins.

Get started with Gridhunt2:

Some example questions for students:

  1. Explain why it is a good idea to have Monster and Hunter inherit from the same superclass called Mobile.
  2. In Gridhunt.cc in function void Gridhunt::run(bool visual) the line hunters[j]->makeMove(); calls makeMove() for an element of an array of type Hunter. In Hunter this function does nothing. Why do our Hunters (subclass of Hunter) still try to hunt the Monster?
  3. It seems that class Grid does not know where all the mobiles are. Who knows where they are?
  4. Form teams of two and implement at least two hunters (subclasses of class Hunter) per team. Make the hunters as smart as possible (e.g., remember where you saw the monster last). Make also sure that your hunters know when they are out of points and do not try to still do things which might create an infinite loop. Let your best hunter compete with hunters implemented by others. No cheating please!.
  5. Analyze the code of Gridhunt2 and try to cheat in order to get an advantage. You can only place code in the files for your subclass of Hunter.

License: The code for this educational game is distributed under the GNU General Public License v3.0 or later.

Good hunting!


Copyright 2010 Michael Hahsler
Last modified: