Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import numpy
- width = 101
- height = 101
- class ReplicatingProbe():
- #class to keep track of a probe's properties and what it can do
- global width , height
- def __init__(self,Location =[0,0]):
- #our probe starts in the center of our galaxy
- self.location = Location
- self.StepsTaken = 0
- self.distance = 0
- self.locationlist = []
- def move(self):
- #moves our probe by picking a random number 1-4, representing each possible direction
- #1 represents up, 2 represents right, 3 represents down, 4 represents left
- direction = numpy.random.choice([1,2,3,4])
- if direction == 1:
- if self.location[1]==height:
- self.move()
- else:
- self.location[1] +=1
- if direction == 3:
- if self.location[1]==-height:
- self.move()
- else:
- self.location[1] -= 1
- if direction == 2:
- if self.location[0] == width:
- self.move()
- else:
- self.location[0] += 1
- if direction == 4:
- if self.location[0]==-width:
- self.move()
- else:
- self.location[0] -= 1
- self.StepsTaken += 1
- #keeps track of how many steps our probe has taken
- self.distance = (self.location[0]**2 + self.location[1]**2)**.5
- self.locationlist.append([self.location[0],self.location[1]])
- def replicate(self,probelist):
- probelist.append(ReplicatingProbe(self.location))
- probelist.append(ReplicatingProbe(self.location))
- #create two new probes
- probelist.remove(self)
- #probe is removed from list, which represents the probe being consumed
- class Star():
- #keeps track of the information about each star, how many times it has been visited, by what, etc.
- def __init__(self,UsefulFlag):
- self.visits = 0
- if UsefulFlag==0:
- self.useful = False
- else:
- self.useful = True
- #useful represents whether the star has the resources necessary for the probe to replicate. we give it a random
- #value, 0 or 1, that determines whether or not the star is useful.
- def visited(self):
- self.visits +=1
- self.useful = False
- def initializestars(probability):
- #creates a list of lists, each containing a star object
- #the first index of the list indicates x position, and the second index represents y position
- #index - 101 = coordinate
- global width , height
- starlist = []
- for j in range(0,2 * width + 1 ):
- stars = []
- for i in range(0,2 * height + 1 ):
- stars.append(Star(numpy.random.choice([0,1],p = [1-probability,probability])))
- starlist.append(stars)
- return starlist
- def initializeprobe():
- #makes the first probe object
- probelist = [ReplicatingProbe()]
- return probelist
- def replicatingexploration(probability,N_steps):
- probelist = initializeprobe()
- starlist = initializestars(probability)
- count = 0
- #this count will keep track of how many total steps have been taken
- while count< N_steps:
- for k in probelist:
- k.move()
- xcoordinate = k.location[0]
- ycoordinate = k.location[1]
- if starlist[xcoordinate + width][ycoordinate + height].useful:
- k.replicate(probelist)
- starlist[xcoordinate + width][ycoordinate + height].visited()
- #update the number of times the star the probe traveled to has been visited
- count+=1
- return probelist , starlist
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement