Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import math
- ter = open("map.txt","r")
- xpos = 0 #current x position
- ypos = 0 #current y position
- down = 1 #how many down
- right = 3 #how many right
- lines = [] #list of all the lines of the map
- trees = 0 #amount of trees detected
- for line in ter: #do loop for line in file
- lines.append(line.strip()) #make list of all the lines of the map
- for i in range(math.floor(len(lines)/down)): #do loop the amount of lines divided by how many down (rounded down)
- if (lines[ypos])[xpos] == "#": #if "tree" detected
- trees += 1 #add tree to the amount
- xpos += right #add to the x position
- ypos += down #add to the y position
- if xpos >= len(lines[i]): #if x position is greater or same as the length of one map line
- xpos = xpos-len(lines[i]) #subtract length of one map line from x position
- print(trees,"trees")
Advertisement
Add Comment
Please, Sign In to add comment