Advertisement
Guest User

Untitled

a guest
Oct 21st, 2016
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.55 KB | None | 0 0
  1. import random
  2.  
  3. def move_trainer(pos,bounds,probability):
  4. input1 = random.randint(0,3)
  5. numcatch = random.random()
  6. pokecaught = 0
  7. if input1 == 0:
  8. pos[0] -= 1
  9. elif input1 == 1:
  10. pos[0] += 1
  11. elif input1 == 2:
  12. pos[1] += 1
  13. elif input1 == 3:
  14. pos[1] -= 1
  15.  
  16.  
  17. if numcatch < probability:
  18. pokecaught = 1
  19. else:
  20. pokecaught = 0
  21.  
  22. return pos ,pokecaught
  23.  
  24.  
  25. M = int(input('Enter the integer number of rows => '))
  26. print(M)
  27. N = int(input('Enter the integer number of cols => '))
  28. print(N)
  29. p = float(input('Enter the probability of finding a pokemon (<= 1.0) => '))
  30. print(p)
  31.  
  32. seed_value = 10*M + N
  33. random.seed(seed_value)
  34.  
  35. pos = [M//2,N//2]
  36. totalturns = 1
  37. maxturns = 0
  38. total_pokemon = 0
  39. change = 0
  40.  
  41. while(totalturns <= 250):
  42. pos,maxturns = move_trainer(pos,(M,N),p)
  43. if maxturns == 1:
  44. change = change + 1
  45. maxturns = 0
  46. if pos[1] < 0:
  47. pos[1] = 0
  48. elif pos[0] < 0:
  49. pos[0] = 0
  50. elif pos[1] > N-1:
  51. pos[1] = N-1
  52. elif pos[0] > M-1:
  53. pos[0] = M-1
  54. if totalturns in range(0,250,20):
  55. print('Time step ',totalturns,': position (',pos[0],', ',pos[1],') pokemon caught since the last report ',change,sep ='')
  56. total_pokemon = total_pokemon + change
  57. change = 0
  58. totalturns = totalturns + 1
  59. total_pokemon = total_pokemon + change
  60. print('After 250 time steps the trainer ended at position (',pos[0],', ',pos[1],') with ',total_pokemon,' pokemon.',sep = '')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement