Random Walks

Simulation and Modeling (CSCI 3010U)

Faisal Z. Qureshi

Faculty of Science, Ontario Tech University

http://vclab.science.ontariotechu.ca

Discuss in class


Random Walks

Consider the code provided below. It implements the classes necessary to implement random walks. You are asked to complete the following two tasks:

Task 1

Complete the following Walker class such that this walker takes one of the following 4 2d steps with equal probability (1,0), (-1,0), (0,1.1), (0,-0.9)

class WalkerUp(Walker):
    def __init__(self, name):
        Walker.__init__(self, name)
    
    def step(self): 
        return Walker.step(self)    

Task 2

Complete the following class that implements traps. When a walker reaches a trap it is magically transported to a random location.

class FieldWithTraps(Field):
    def __init__(self, w, h, num_traps):
        Field.__init__(self)
        
    def reset(self):
        Field.reset(self)

    def move(self, walker):
        Field.move(self, walker)

Here \(w\) and \(h\) defines the width and the height of the region where traps are located.

Code

random-walk-exercise.py

Submission

The exercise will be completed in class. Upload your thoughts, code, notes to the activity dropbox on course canvas.

Be prepared to show your work to the instructor.