LostHiker

This assignment is derived from the original assignment.

Introduction

Organizations such as Larimer County Search and Rescue are responsible for missing person searches in wilderness areas. They deploy resources such as helicopters, search dogs, and hiking teams to look for missing persons. The next series of assignments will develop a Search and Rescue Simulator. In any search, the Task Force Team Leader must decide how to best deploy available resources, particularly the searchers themselves. The purpose of the Search and Rescue Simulator is to evaluate different strategies for deploying the searchers.

This assignment will simply model the movements of a lost hiker.

A common search pattern is the grid search. The area where the person is believed to be lost is divided into cells, and each cell searched by rescuers. We can model the locations of people in the grid using the coordinates of their current cell. This first assignment develops code simulating the movements of a lost hiker.

In this series of assignments, you will write a program that simulates the movements of a lost hiker, as well as the efforts of the searchers that are deployed to look for the person.

A common programming technique to model location and movement is to employ an array and use the indices as location coordinates. We will use a two-dimensional array (a grid) with indices representing (zero based) north-south and east-west coordinates. Each element, or cell, of the grid represents a potential location in the simulated "world".

Requirements

main() Application Setup

  1. Declare a constant integer parameter named HOURS_MISSING with a value of 10.
  2. Declare a constant integer parameter named FOOT_SPEED with a value of 1.
  3. Declare a two-dimensional 10 x 2 int array to store the history of the hiker's random movements (10 sets of x, y coordinates).
  4. Declare two integer variables x and y representing the current location of the hiker. Initialize their values to place the lost hiker in the center of the grid.

Declare your function prototype and definition in your main .cpp file.

random_move() Function

  1. Develop a void random_move function that accepts the north-south and east-west coordinates of the hiker (by reference)
  2. The possible ending points for the hiker are any valid grid cell around the hiker's initial position and not moving at all.

The movement of a lost hiker is difficult to predict and rarely consistent, so we will model the hiker's movements as a uniform random variable: the probability of the hiker moving to any particular neighboring cell, as well as remaining in the current cell, is equal.

main() Application Continued

  1. Back in the main routine, prompt the user for an integer seed for the psuedo random number generator, and use the srand() function as described in lecture.
  2. In a loop that runs HOURS_MISSING times, use your random_move() function to calculate the hiker's movements for each hour that has elapsed since they went missing.
  3. Using the two-dimensional integer array already declared, store the coordinates of the hiker per hour.

When the loop finishes, report to the console with well labeled and formatted output:

Example Output

Starting coordinate: (10,10)

Hour 1: (9,10)

Hour 2: (8,10)

Hour 3: (7,10)

Hour 4: (6,10)

Hour 5: (5,10)

Hour 6: (4,10)

Hour 7: (3,10)

Hour 8: (2,10)

Hour 9: (1,10)

Hour 10: (1,10)

Final coordinates: (1, 10)

Grading Rubric

See the original assignment.

'Candy' Bonus

Assume that the hiker is surrounded by impassable terrain on all sides at a linear distance of 5 from the original starting position. Treat these bounds as edge cases, in which the hiker cannot move outside of these bounds. (Your random movement generator must consider these edge cases when determining a valid movement. See the original assignment for some hints.)