#!/usr/bin/python # D. Vrajitoru, C463/B551 Spring 2008 # Code for testing the reflex agent in homework 3. # Add the function for the reflex agent called nlife_agent for the # function bellow to work. # A function that transforms a list by replacing every element with # the result of the processing done by the reflex agent to be # written. It doesn't change the original list but returns the result # list instead. def nlife (L): result = [] for i in range(len(L)): if i == 0: prev = 0 else: prev = L[i-1] if i == len(L)-1: next = 0 else: next = L[i+1] result.append(nlife_agent(prev, L[i], next)) return result # Test to make sure the function above works #def nlife_agent(x, y, z): # return max(x, y, z) # Creating a global list to test the function testl = [1, 2, 3, 4] # Calling this function should result in the list bellow. nlife(testl) #[0, 0, 1, 7] # Executing the following instruction repeteadly should run the game # of numerical life. The sequence of lists bellow is an example of the # evolution of the original list through this process, shown backwards # (it starts at the bottom going up). testl = nlife(testl) #[18, 8, 24, 60] #[1, 17, 49, 11] #[3, 0, 14, 35] #[6, 0, 28, 70] #[5, 1, 57, 13] #[0, 5, 26, 26] #[0, 0, 5, 21] #[1, 0, 17, 4] #[0, 1, 8, 8] #[0, 0, 1, 7]