﻿ Lab 14

## Lab 14

### Mouse on an Island

The following diagram represents an island (green) surrounded by water (blue) with two bridges (black) leading to land (not shown).

A mouse is placed somewhere on this island and allowed to roam aimlessly about until it reaches a bridge, falls into the water (and drowns), or dies for lack of food. You are to write a program that simulates the mouse's movements.

Input: The user will enter the name of a data file which your program will read. The first row of the data file contains the number of rows and the number of columns  for the map (both less than or equal to 20). The remaining rows contain the data that describes the map as follows:

• 0 represents water
• 1 represents land
• 2 represents bridge
• 3 represents the initial location of the mouse (not shown in the map above)

The initial location of the mouse is always a land square. With the mouse located near the middle of the island, the map above would be represented as follows:

```18 12
0 0 0 0 0 0 0 0 2 0 0 0
0 1 1 1 1 1 1 1 1 1 1 0
0 1 1 1 1 1 1 1 1 1 1 0
0 1 1 1 1 1 1 1 1 1 1 0
0 1 1 1 1 1 1 1 1 1 1 0
0 1 1 1 1 1 1 1 1 1 1 0
0 1 1 1 1 1 1 1 1 1 1 0
0 1 1 1 1 1 3 1 1 1 1 0
0 1 1 1 1 1 1 1 1 1 1 0
0 0 0 1 1 1 1 1 1 1 1 0
0 0 0 1 1 1 1 1 1 1 1 0
2 2 2 1 1 1 1 1 1 1 1 0
0 0 0 1 1 1 1 1 1 1 1 0
0 0 0 1 1 1 1 1 1 1 1 0
0 0 1 1 1 1 1 1 1 1 1 0
0 0 1 1 1 1 1 1 1 1 1 0
0 0 0 0 0 0 1 1 1 1 0 0
0 0 0 0 0 0 0 0 0 0 0 0```

Process: Simulate the aimless roaming of the mouse by moving the mouse north (up), east (right), south (down), or west (left) randomly until one of the following occurs:

• The mouse moves into a water square and drowns.
• The mouse moves onto a bridge square and escapes.
• The mouse has moved 100 times (without drowning or escaping) and dies of starvation.

Invoke the simulation 1,000 times counting the number of times the mouse escapes, the number of times the mouse drowns, and the number of times the mouse starves.

Output: Display the map in the output window. Below the map, display the number of times the mouse escaped, the number of times the mouse drowned, and the number of times the mouse starved. These output values should be properly labeled.

The file Lab14.cpp contains enough code to get you started. The file island.txt contains the map illustrated above.