示例#1
0
        if environment[a][b] == 1:
            environment[a][
                b] = 99  #this value changes the color hue for the pubs
            #print(a,b)
    #house numbers

print("print(len(drunks))", len(drunks))
"""
Print the fifth step: 
Creating drunks and make them know how to locate their house numbers
"""
for i in range(num_of_drunks):
    house_number = (i + 1) * 10
    print("house_number", house_number)
    drunks.append(
        agentframework.drunks(drunks, homes, environment, house_number))
print("print(len(drunks))", len(drunks))

#setting up iterations to determine the number of times the code runs
iteration = 0
numhome = 0
"""
 Print the sixth step:
Moving the drunks from the pub to their respective homes
 """
while (True):
    if (iteration % 1000 == 0):
        print("iteration",
              iteration)  #testing the code to know how the drunks were able
        #to move to thier homes through a number of iterations
    for i in range(num_of_drunks):
示例#2
0
)
environment = []
for row in f:
    parsed_row = str.split(row, ",")
    rowlist = []
    for value in parsed_row:
        rowlist.append(float(value))
    environment.append(rowlist)
f.close()
for a in range(300):
    for b in range(300):
        if environment[a][b] == 1:
            environment[a][b] = 100

for i in range(total_drunks):
    drunks.append(agentframework.drunks(drunks, house, environment))

for i in range(total_drunks):
    house = (i + 1) * 10
    drunks.append(agentframework.drunks(drunks, house, environment))

    plt.imshow(environment)
plt.show

for i in range(total_drunks):

    #creating scatterplots of the agents defined above
    plt.scatter(drunks[i].x, drunks[i].y)
    plt.draw()

    carry_on = True
示例#3
0
    parsed_row = str.split(row, ",")
    rowlist = []
    for value in parsed_row:
        rowlist.append(float(value))
    environment.append(rowlist)

#3rd STEP: Closes the file "drunk.plan.txt" so it is no longer read or written
f.close()
for a in range(300):
    for b in range(300):
        if environment[a][b] == 1:
            environment[a][b] = 100

#4th STEP: Initiates the class 'drunks'
for i in range(num_of_drunks):
    drunks.append(agentframework.drunks(environment))

#5th STEP: adds a label to the 25 houses that belong to the drunks
for i in range(num_of_drunks):
    houselabel = (i + 1) * 10
    house.append(houselabel)

#6th STEP: locates the drunks houses and moves the drunks to find their homes
for i in range(num_of_drunks):
    while environment[drunks[i].x][drunks[i].y] != house[i]:
        drunks[i].move()
    print(drunks[i].x, drunks[i].y)

#7th STEP: plots the environment
matplotlib.pyplot.xlim(0, 300)  #plots x values
matplotlib.pyplot.ylim(0, 300)  #plots y values