Control flow
The reason why the agents might be missing from the graph is if they've wandered off the edge.
Edge effects are a major issue in geographical modelling. Here our agent coordinates have a very large (practically infinite) area to move in (controlled by the size of the int variables used to store the coordinates). Separately, our graph is only displaying an area of 100x100 spaces. Ok, this isn't a massive issue (we could write something to zoom in and out) but once we deal with adding environmental data, it will be: we don't have infinite environmental datasets, and the memory size of the computer will start to limit us.
For some algorithms, there are additional boundary effects. Look at this code, which blurs an image by making a new dataset where each data point is the average of an cross-shaped moving window passed across the original data set:
This is just an example (and one that doesn't yet work); we're not expecting you to use this in your code. If you want to experiment with it copy it into a new blank file.
# blur ---------------------------------------
import matplotlib.pyplot
data = []
processed_data = []
# Fill with random data.
for i in (range(0,99)):
datarow = []
for j in (range(0,99)):
datarow.append(random.randint(0,255))
data.append(datarow)
# Blur.
for i in (range(0,99)):
datarow = []
for j in (range(0,99)):
sum = data[i][j]
sum += data[i-1][j]
sum += data[i+1][j]
sum += data[i][j+1]
sum += data[i][j-1]
sum /= 5
datarow.append(sum)
processed_data.append(datarow)
matplotlib.pyplot.imshow(data)
matplotlib.pyplot.show()
matplotlib.pyplot.imshow(processed_data)
matplotlib.pyplot.show()
# End ---------------------------------------
Why do you think it doesn't run, complaining IndexError: list index out of range
?