# Author: James Tam # Version: March 15, 2018 # CONSTANTS SIZE = 4 EMPTY = " " PERSON = "*" START = (1,1) ''' @ initialize() @ no parameters @ returns a fully initialized world ''' def initialize(): world = [] r = -1 c = -1 for r in range (0,SIZE,1): world.append([]) # Add in new empty row for c in range (0,SIZE,1): world[r].append(EMPTY) # Add new element to row end # Add the 'person' character to default start location sRow = START[0] sColumn = START[1] world[sRow][sColumn] = PERSON return(sRow,sColumn,world) ''' @ display() @ argument: 2D list of char(length 1 string), simulated game world @ return value: none @ @ Shows the current state of the world ''' def display(world): r = -1 c = -1 for r in range (0,SIZE,1): for c in range (0,SIZE,1): print(world[r][c], end="") print() print() ''' @ getDestination() @ argument: None @ return value: the point (row,column) to move the person @ ''' def getDestination(): dRow = int(input("Destination row: ")) dColumn = int(input("Destination column: ")) return(dRow,dColumn) ''' @ isDestinationValid() @ argument: two points P1(current row/column), @ P2(destination row/column) @ return value: boolean @ Valid moves: one of the 4 cardinal compass directions @ (N,S,W,E) of an adjacent square @ ''' def isDestinationValid(cRow,cColumn,dRow,dColumn): isValid = False # Write your solution here return(isValid) # MAIN EXECUTION POINT def start(): cRow,cColumn,world = initialize() print("Initial world") display(world) dRow,dColumn = getDestination() input("Hit enter to continue") valid = isDestinationValid(cRow,cColumn,dRow,dColumn) print("From: (%d/%d) " %(cRow,cColumn)) print("To: (%d/%d) " %(dRow,dColumn)) print("Can move?", str(valid)) start()