def preparation(): log.create() ax = FieldPreparation.prepare() playgr = FieldPreparation.create_field() ants = ant.create() log.write(ants,"trace") return (ax,playgr,ants)
def paint(possearch, posreturn, plt, ax): xsearch = [] ysearch = [] xreturn = [] yreturn = [] for i in possearch: xsearch.append(common.xy_pos(i)[0]) ysearch.append(common.xy_pos(i)[1]) for i in posreturn: xreturn.append(common.xy_pos(i)[0]) yreturn.append(common.xy_pos(i)[1]) ax.plot(xsearch, ysearch, 'ro') ax.scatter(xreturn, yreturn, facecolor='green') POIx = [common.xy_pos(common.startpoint)[0], common.xy_pos(common.targetpoint)[0]] POIy = [common.xy_pos(common.startpoint)[1], common.xy_pos(common.targetpoint)[1]] ax.scatter([POIx], [POIy], facecolor="blue") log.write("Collection before:" + str(ax.collections)) plt.draw() plt.pause(0.01) ax.lines[0].remove() for i in range(0, 2): try: ax.collections[0].remove() except: break log.write("Collection after:" + str(ax.collections)) ax.plot()
def poskey(x, y): if not isinstance(y, int) or not isinstance(x, int): return False if (x > 999) or (y > 999): return False posNr = str(x * 1000 + y) positionkey = (6 - len(posNr)) * "0" + posNr log.write("x:" + str(x) + "y:" + str(y) + "=" + positionkey) return positionkey
def position(i, ants, field): direct = ant.move(i, ants, field) pos_old = ants[i]["pos"] pos_x = int(pos_old[:3]) pos_y = int(pos_old[4:6]) pos_new = common.poskey(pos_x + direct[0], pos_y + direct[1]) ants[i].update({"pos": pos_new}) ants.update({i: ants[i]}) text = "pos_old:" + pos_old + "--direct:" + str( direct) + "pos_new:" + pos_new log.write(text, "trace")
def ants_changing(j, ants, playground): pltlistsearch = [] pltlistreturn = [] for i in range(0, config.max_ants): try: an = ants[i] except: return False ant.modechange(ants, i) ant.position(i, ants, playground) pos_new = an["pos"] if an["status"] == "search": pltlistsearch.append(pos_new) else: pltlistreturn.append(pos_new) log.write(ant.printtext(j, i, an["status"], pos_new)) return pltlistsearch, pltlistreturn
def smell(pos, field): smell_list = [] x = int(pos[:3]) y = int(pos[4:6]) log.write("Smelling field:" + str(field)) for i in common.direction: pos_x = x + i[0] pos_y = y + i[1] pos_key = common.poskey(pos_x, pos_y) fieldPos = field[pos_key] log.write("Smell:" + str(pos_key) + "field:" + str(fieldPos)) border = fieldPos["border"] smell_list.append({ "border": border, "search": fieldPos["search"] * border, "return": fieldPos["return"] * border }) log.write(smell_list, 'trace') return smell_list
def test_write(): logFileDictionay = log.write("","fatal") assert logFileDictionay.__getattribute__('name') is config.logfile_name