import sys # Author: James Tam # Version: March 20, 2018 # Note: due the missing code, this program is not executable # Learning concepts: # * Finding the solution to a 'tough' problem ROWS = 4 COLUMNS = 6 NUMBERS = " 0 1 2 3 4 5" LINES = " - - - - - -" PLAYER = "P" MONSTER = "M" EMPTY = " " P_START_ROW = 2 P_START_COLUMN = 2 # Return values hard-coded to (0,0) so program does not crash # but code to move the monster must be implemented as a student # exercise def chase(pRow,pColumn,mRow,mColumn): print("You have to write the code for chase()") return(0,0) # function: garden # garden(2DList) # returns(nothing) # Creates 4x5 garden: all locations empty except default # location for player (2,2) def initialize(garden): for r in range (0, ROWS, 1): garden.append([]) for c in range (0, COLUMNS, 1): garden[r].append(" ") # Position player garden[P_START_ROW][P_START_COLUMN] = PLAYER def display(garden): print(NUMBERS) for r in range (0, ROWS, 1): print(LINES) print(r, end="") for c in range (0, COLUMNS, 1): sys.stdout.write("|") sys.stdout.write(garden[r][c]) print('|') print(LINES) # function: getMonsterLocation # getMonsterLocation() # return(int,int) # Gets the starting location of the monster from the user. def getMonsterLocation(): print("Enter monster row: ", end="") row = int(input()) print ("Enter monster column: ", end="") column = int(input()) return(row,column) def move(garden,mRow,mColumn,dRow,dColumn): print("You have to write the code for move()") def set(garden,character,row,column): garden[row][column] = character # Part I: Move # Write the definition of the move() function here # Part II: Chase # Write the definition of the chase() function here def start(): garden = [] pRow = P_START_ROW pColumn = P_START_COLUMN dRow = -1 dColumn = -1 mRow = -1 mColumn = -1 initialize(garden) display(garden) mRow,mColumn = getMonsterLocation() set(garden,MONSTER,mRow,mColumn) print("Drawing garden with monster") display(garden) # Part II: Write the code ('chase' function) that will # make the computer 'monster' chase the human player # 'chase' function. Hint: it should return the # destination (row,column) of the computer. dRow,dColumn = chase(pRow,pColumn,mRow,mColumn) # Part I: Write the code ('move' function) that will move # the monster from the current location (mRow,mColumn) to # the destination(dRow,dColumn) in the garden. move(garden,mRow,mColumn,dRow,dColumn) # Update current monster (row,column) mRow = dRow mColumn = dColumn input("<<< Hit enter to see the effects of the chase >>>") display (garden) start()