In class, we considered the simulation of Dot races, where a single dot could move a random distance along a track at each step. Dot races represent just one example of a broad class of simulations known as random walks. In a random walk, the walker starts at an initial position and is able to move in random (but possibly constrained) steps. Random walks have been used in a variety of real-world applications, including modeling the interactions of atomic particles, recreating natural patterns such as river beds and mollusk shells markings, and drawing realistic textures for 3-D graphics.
For this assignment, you will consider a form of random walk known as an alley walk. In an alley walk, the walker is constrained to one-dimensional movement, being able to move one unit to the right or left in a single step. As an analogy, consider a person standing at the middle of a long, narrow alley. She can take a step in either direction towards an exit. If the direction is randomly chosen, it is possible that she may wander back and forth along the alley before eventually stumbling out one end. The following diagram depicts a situation where the person is 10 steps away from either exit.
As we have seen in past examples, random events such as dice rolls and coin flips are predictable, but only in the long run. It is possible (although unlikely) for a person to roll snake eyes on their first roll or flip heads four times in a row. Similarly, a single random walk might produce unexpected results. An alley walk with goal distance 10 could be completed in as few as 10 steps, or conversely might take hundreds of steps. Given a large number of walks, however, you would expect such anomalous walks to be rare and to balance out. It has been shown that, on average, the number of steps required for an alley walk with goal distance X is approximately X2. Thus, if a walker starts in the center of an alley where each end is 10 steps away, it will take (on average) approximately 100 steps to exit.
This class will be similar in form to the VolleyBallSimulator class from the previous homework. In particular, the alleyWalk method should display the walker's position after every step when called directly, but not if called from displayAverage.
SIMULATION 1 | SIMULATION 2 | SIMULATION 3 | |
---|---|---|---|
1,000 alley walks, goal=10 | |||
10,000 alley walks, goal=10 | |||
100,000 alley walks, goal=10 | |||
1,000 alley walks, goal=20 | |||
10,000 alley walks, goal=20 | |||
100,000 alley walks, goal=20 |
Assuming the same goal distance, which do you think would require more steps (on average) to complete: a random alley walk in which the user can exit in either direction, or a random dead-end walk in which the user can only exit in one direction but may repeatedly bump into the wall. Note that bumps into the wall still counts as steps, even though the walker's position does not change. You must provide a plausible justification for your prediction.
SIMULATION 1 | SIMULATION 2 | SIMULATION 3 | |
---|---|---|---|
1,000 dead-end walks, goal=10 | |||
10,000 dead-end walks, goal=10 | |||
100,000 dead-end walks, goal=10 | |||
1,000 dead-end walks, goal=20 | |||
10,000 dead-end walks, goal=20 | |||
100,000 dead-end walks, goal=20 |