#
#  Executes target seeking random walk inside a
#  confining boundary(rectangle). Conducts and 
#   plots up to 5 random walks
#
#  Following parameters can be changed:
#    1- Size and location of boundary
#    2- Size and location of target
#    3 -Starting location for random walk 
#
import sys,random
import numpy as np
##############################################
# Your CODE changes:
# Note: This program requires you to complete a new function 
#       in randwalk2d_mod.py module before it will work
#       Find "rand_walk_target" in this module and complete
#       Then run this program (which imports randwalk2d_mod below) 
#
##############################################
import randwalk2d_mod as rw2d
import matplotlib.pyplot as plt
from matplotlib.patches import Rectangle  # Used to draw rectangle
random.seed(None)        # Seed generator, None => system clock
#
#   Enter number of walks to plot and check entered value
#
num_walks = int(input('Enter number of walks to do (1-5) :  '))
max_steps = 10000
#  
#  Set up confining box, target , starting point for walks, 
#      and random step function
#  
boundary    = rw2d.setup_box((0.0, 0.0), 40, 40)
target      = rw2d.setup_box((10.0, 10.0), 4, 4)    
start_loc   = ( 0.0, 0.0)
#  Allows each walk to use a different color/line type on plot 
line_type = ['r-','c-','k-','g-','m-'] 
#
#  Perform loop for each walk and plot with different color(line_type):
# 
for i in range(num_walks):      
    xwalk1,ywalk1,steps_taken,target_reached = rw2d.random_walk_target(max_steps, \
           start_loc, boundary, target )
    plt.plot(xwalk1, ywalk1, line_type[i],label='wk'+str(i+1)+' '+      \
            str(steps_taken))
    plt.plot(xwalk1[-1],ywalk1[-1], 'b*', ms=8)  # Large * to mark end of walk
#  
#  Draw boundary and target on graph and set size of graph (xlim,ylim)
#  Create bold lines through walk starting point
#
rw2d.draw_boundary(start_loc, boundary)
rw2d.draw_target(target)
#  Set plot title , legend, and grid 
plt.title('2D walks inside box w/ target (' +str(num_walks)+ ')' )
plt.legend(loc="upper left")
plt.grid(True)
plt.show() 


