Last active
January 19, 2017 17:48
-
-
Save mattdeboard/c8a27ef3a821fef66794da4a47edf9be to your computer and use it in GitHub Desktop.
Simulation of the plot of It Follows
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import os | |
import random | |
class Follower: | |
def __init__(self, starting_location, current_victim=None): | |
# `starting_location` is a string representing a file system path. | |
self.location = starting_location | |
self.current_victim = current_victim | |
self.victims = [] | |
if self.current_victim is not None: | |
self.victims.append(self.current_victim) | |
def kill(self): | |
self.current_victim.dead = True | |
try: | |
self.current_victim = self.victims.pop() | |
except IndexError: | |
raise IndexError("We're all out of victims!") | |
class Victim: | |
def __init__(self, starting_location): | |
# `starting_location` is a string representing a file system path. | |
self.location = starting_location | |
self.dead = False | |
def move(self): | |
"""Move to a random location in the file system.""" | |
pass | |
def infect(self, follower): | |
new_victim = Victim(self.location) | |
follower.victims.append(new_victim) | |
return new_victim | |
def random_directory(root): | |
return random.choice(os.listdir(root)) | |
if __name__ == '__main__': | |
first_victim = Victim(random_directory('~')) | |
follower = Follower(random_directory('~'), first_victim) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment