# RW2.py # NAME # DATE from random import randint as randi from simpleGraphicsE import * def MakePath(n): """ Returns a string s that consists of the characters 'E', 'N', 'W', and 'S'. s[k] indicates how the robot moved during step k. Thus, if s[7] is 'N', then in step 7 the robot moved North, i..e, the y-value of its location was increased by 1. PreC: n is a positive integer """ # The current location of the robot is (x,y) x = 0 y = 0 # The travel string s will be built through repeated concatenation s = '' while abs(x)<=n and abs(y)<=n: i = randi(1,4) if i==1: # Move east x=x+1 s =s+'E' elif i==2: # Move north y=y+1 s=s+'N' elif i==3: # Movewest x=x-1 s=s+'W' else: # Move south y=y-1 s=s+'S' return s def HopsAve(n,nTrials): pass def isHappy(s,n): pass def ProbHappy(n,nTrials): pass def isHomesick(x,y,n): pass def Homesick(s,n): pass def HomesickAve(n,nTrials): pass def DrawPlaypen(n): """ Draws a size n playpen. n should be <=10 for the labels to be clear PreC: n is a positive int. """ # Draw the pen and its purple boundary DrawRect(0,0,2*n+3,2*n+3,color=PURPLE,stroke=0) DrawRect(0,0,2*n+1,2*n+1,color=YELLOW,stroke=0) x = -n-.5 y = -n-.5 # Add in the vertical and horizontal grid lines. for k in range(2*n+2): DrawLineSeg(x,-n-1.5,2*n+3,90) DrawLineSeg(-n-1.5,y,2*n+3,0) x+=1 y+=1 # Application Script if __name__ == '__main__': n = 5 MakeWindow(n+2,labels=True,bgcolor='BLACK') DrawPlaypen(n) DrawDisk(0,0,.25,color=BLACK) DrawDisk(4,-5,.25,color=GREEN) DrawDisk(2,3,.25,color=ORANGE) ShowWindow()