コード例 #1
0
def main():
    world = Maze(maze_data, HALF_WIDTH, HALF_HEIGHT)
    world.draw()


    for shark_count in range(151)[10::10]:
    # Initialize Items
        sharks = Shark.create_random(shark_count, world, 0)
        robert = Robot(world, 0,0)
        robots = [robert]
        no_particles = []

        # Write to File
        my_file = open("%sSharksDistFromLine.txt" %(shark_count), "w")

        # Header describing model
        my_file.write("Line Start: %s, Line End: %s" %(LINE_START, LINE_END))
        my_file.write("\n")
        my_file.write("NumSharks: %s, K_att: %s, K_rep: %s, Sigma_Rand: %s, Speed/ts: %s" %(shark_count, K_ATT, K_REP, SIGMA_RAND, Shark.speed))
        my_file.write("\n")


        att_line = LineString([LINE_START, LINE_END])

        # Let sharks move towards attraction line first
        for time_step in range(300):
            move(world, robots, sharks, att_line, no_particles, SIGMA_RAND, K_ATT, K_REP)

        # while True:
        for _ in range(3):
            for time_step in range(TIME_STEPS):
                #
                # ---------- Show current state ----------
                if SHOW_VISUALIZATION:
                    world.show_sharks(sharks)
                    world.show_robot(robert)
                    world.show_att_line(LINE_START, LINE_END)

                move(world, robots, sharks, att_line, no_particles, SIGMA_RAND, K_ATT, K_REP)
                for shark in sharks:
                    # my_file.write("%s, %s," % (shark.x, shark.y))
                    my_file.write("%s, " %(distance_from_line(shark, att_line)))
                my_file.write("\n")

                print time_step

        my_file.close()
コード例 #2
0
            self.move_by(dx, dy)
            return True
        return False

# ------------------------------------------------------------------------

world = Maze(maze_data)
world.draw()

# Initialize Sharks
sharks = Shark.create_random(SHARK_COUNT, world)
print "length of shark", len(sharks)
print sharks
robert = Robot(world)

while True:


    # ---------- Show current state ----------
    world.show_sharks(sharks)
    world.show_robot(robert)



    # # ---------- Move things ----------

    # Move sharks with shark's speed
    for s in sharks:
        s.advance(s.speed)
    time.sleep(0.1)