BalerCoder

Untitled

Oct 14th, 2023
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.85 KB | Source Code | 0 0
  1. def moving_around(cmds):
  2.   grid = np.full((7, 7), '.')
  3.     #To Do
  4.   r,c = 3,3
  5.   grid[3][3] = "-"
  6.   for i in range(len(cmds)):
  7.       a=moveset(cmds[i],r,c,grid)
  8.       if a==None:
  9.           grid[r][c] == "/"
  10.       else:
  11.           r,c = a
  12.   grid[r][c]="/"
  13.   return grid
  14.  
  15.  
  16. def moveset(move,t,p,arr):
  17.     if move>= 1 and move<=4:
  18.         t-=2
  19.         p-=2
  20.         if move==1:
  21.             p-=1
  22.         elif move ==2:
  23.             p+=1
  24.         elif move==3:
  25.             t-=1
  26.         else:
  27.             t+=1
  28.     elif move>=5 and move<=8:
  29.         t-=2
  30.         p+=2
  31.         if move==5:
  32.             p-=1
  33.         elif move==6:
  34.             p+=1
  35.         elif move==7:
  36.             t-=1
  37.         else:
  38.             t+=1
  39.     else:
  40.             t+=2
  41.             p-=2
  42.             if move==9:
  43.                 p-=1
  44.             elif move==10:
  45.                 p+=1
  46.             elif move==11:
  47.                 t-=1
  48.             else:
  49.                 t+=1
  50.     if (t and p)>=0 and (t and p)<=6:
  51.         arr[t][p] = "*"
  52.         return t,p
  53.     else:
  54.         return None
  55.  
  56. cmds = np.array([5,11,2,9])
  57. result = moving_around(cmds)
  58. print_matrix(result)
  59. #This should print
  60. # -------------------------------------------
  61. # |  .  |  /  |  .  |  .  |  .  |  .  |  .  |
  62. # -------------------------------------------
  63. # |  .  |  .  |  .  |  .  |  *  |  .  |  .  |
  64. # -------------------------------------------
  65. # |  .  |  .  |  *  |  .  |  .  |  .  |  .  |
  66. # -------------------------------------------
  67. # |  .  |  .  |  .  |  -  |  .  |  .  |  .  |
  68. # -------------------------------------------
  69. # |  .  |  .  |  .  |  .  |  .  |  .  |  .  |
  70. # -------------------------------------------
  71. # |  .  |  .  |  .  |  .  |  .  |  .  |  .  |
  72. # -------------------------------------------
  73. # |  .  |  .  |  .  |  .  |  .  |  .  |  .  |
  74. # -------------------------------------------
Advertisement
Add Comment
Please, Sign In to add comment