# CSE 143, Winter 2010, Marty Stepp # Homework 4: Assassin, in Python # # Instructor-provided testing program. # AssassinMain is the main client program for assassin game management. # It reads names from a file names.txt, shuffles them, and uses them to # start the game. The user is asked for the name of the next victim until # the game is over. import random from assassinmanager import * # input file name from which to read data INPUT_FILENAME = "names.txt" # True for different results every run False for predictable results RANDOM = True # If not random, use this value to guide the sequence of numbers # that will be generated by the random number generator. SEED = 42 # Handles the details of recording one victim. Shows the current kill # ring and graveyard to the user, prompts for a name and records the # kill if the name is legal. def oneKill(manager): # print both linked lists print("Current kill ring:") manager.print_kill_ring() print("Current graveyard:") manager.print_graveyard() # prompt for next victim to kill print("") name = input("next victim? ").strip() # kill the victim, if possible if manager.graveyard_contains(name): print(name + " is already dead.") elif not manager.kill_ring_contains(name): print("Unknown person.") else: manager.kill(name) print("") # main # read names into a list names = [] for line in open(INPUT_FILENAME): names.append(line.strip()) # shuffle and build an AssassinManager if not RANDOM: random.seed(SEED) random.shuffle(names) manager = AssassinManager(names) while not manager.game_over(): oneKill(manager) # report who won print("Game was won by " + manager.winner()) print("Final graveyard is as follows:") manager.print_graveyard()