Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import random
- def move_trainer(pos,bounds,probability):
- input1 = random.randint(0,3)
- numcatch = random.random()
- pokecaught = 0
- if input1 == 0:
- pos[0] -= 1
- elif input1 == 1:
- pos[0] += 1
- elif input1 == 2:
- pos[1] += 1
- elif input1 == 3:
- pos[1] -= 1
- if numcatch < probability:
- pokecaught = 1
- else:
- pokecaught = 0
- return pos ,pokecaught
- M = int(input('Enter the integer number of rows => '))
- print(M)
- N = int(input('Enter the integer number of cols => '))
- print(N)
- p = float(input('Enter the probability of finding a pokemon (<= 1.0) => '))
- print(p)
- seed_value = 10*M + N
- random.seed(seed_value)
- pos = [M//2,N//2]
- totalturns = 1
- maxturns = 0
- total_pokemon = 0
- change = 0
- while(totalturns <= 250):
- pos,maxturns = move_trainer(pos,(M,N),p)
- if maxturns == 1:
- change = change + 1
- maxturns = 0
- if pos[1] < 0:
- pos[1] = 0
- elif pos[0] < 0:
- pos[0] = 0
- elif pos[1] > N-1:
- pos[1] = N-1
- elif pos[0] > M-1:
- pos[0] = M-1
- if totalturns in range(0,250,20):
- print('Time step ',totalturns,': position (',pos[0],', ',pos[1],') pokemon caught since the last report ',change,sep ='')
- total_pokemon = total_pokemon + change
- change = 0
- totalturns = totalturns + 1
- total_pokemon = total_pokemon + change
- 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