Added std_lib to scenario and solution.

parent 9962e505
 ... ... @@ -23,8 +23,8 @@ border = 0.0 ## Swarm-Sim sim size in points ## Works only with border flag set on 1 size_x = 20.0 size_y = 20.0 size_x = 2000.0 size_y = 2000.0 ## Maximum number of particles that can be created while simulating max_particles = 10000 ... ... @@ -43,7 +43,8 @@ tile_mm_size = 2 ##Examples## ##Moving scenario = lonely_particle #scenario = lonely_particle scenario = n_particle_in_line solution = random_walk #solution = round_walk ... ...
 from scenario.std_lib import * def scenario(sim): max_size_particle = 10 create_particle_in_line(sim, max_size_particle, (0,0)) \ No newline at end of file
 import random #colors black = 1 gray = 2 red = 3 green = 4 blue = 5 yellow = 6 orange = 7 cyan = 8 violett = 9 #directions NE = 0 E = 1 SE = 2 SW = 3 W = 4 NW = 5 direction = [NE, E, SE, SW, W, NW] def generating_random_spraded_particles (sim, max_size_particle): for _ in range(0, max_size_particle): x = random.randrange(-sim.get_sim_x_size(), sim.get_sim_x_size()) y = random.randrange(-sim.get_sim_y_size(), sim.get_sim_y_size()) if y % 2 == 1: x = x + 0.5 if (x, y) not in sim.tile_map_coords: sim.add_particle(x, y) else: print(" x and y ", (x, y)) print("Max Size of created Particle", len(sim.particles)) def create_particle_in_line(sim, max_size_particle, start_coords): if start_coords[0] % 1 != 0: start_i = int(start_coords[0] - 0.5) for i in range(start_i, start_i+max_size_particle): sim.add_particle(i + 1.5, start_coords[1]) else: for i in range(int(start_coords[0] + 1), int(start_coords[0] + 1) + max_size_particle): sim.add_particle(i, start_coords[1]) def create_particle_in_square(sim, max_size_particle, start_coords): for y in range(start_coords[1], round(max_size_particle/2)): for x in range(start_coords[0], round(max_size_particle/2)): sim.add_particle(x + 0.5, 2 * y + 1.0) sim.add_particle(-(x + 0.5), 2 * y + 1.0) sim.add_particle(x + 0.5, -(2 * y + 1.0)) sim.add_particle(-(x + 0.5), -(2 * y + 1.0)) sim.add_particle(x, 2 * y) sim.add_particle(-x, 2 * y) sim.add_particle(x, -2 * y) sim.add_particle(-x, - 2 * y)
 ... ... @@ -2,7 +2,7 @@ This solution is an example for creating and deleting, particles, tiles or markers """ #Standard Lib that has to be in each solution from lib.std_lib import * from solution.std_lib import * def solution(sim): if sim.get_actual_round() == 1: ... ...
 import random #Standard Lib that has to be in each solution from lib.std_lib import * from solution.std_lib import * def solution(sim): if sim.get_actual_round() % 2 == 0: if sim.get_actual_round() % 1 == 0: for particle in sim.get_particle_list(): particle.move_to(random.choice(direction)) \ No newline at end of file
 ... ... @@ -3,7 +3,6 @@ The particles are moving infront each other but in the different direction but w the start either to write to each other and then they give out the what it they received from each other. """ #Standard Lib that has to be in each solution from lib.std_lib import * def solution(sim): """ ... ...
 #Standard Lib that has to be in each solution from lib.std_lib import * from solution.std_lib import * def solution(sim): ... ...
 ... ... @@ -3,7 +3,6 @@ This solution just scans for particles that are within 5 hops range and prints t """ #Standard Lib that has to be in each solution from lib.std_lib import * def solution(sim): ... ...
 ... ... @@ -38,19 +38,26 @@ def move_to_dest_in_one_rnd(particle, destiny): move_to_dest_in_one_rnd(particle, destiny) def move_to_dest_step_by_step(particle, destiny): """ :param particle: :param destiny: :return: True if movement occured, False if not movment and a Matter if the next dir point has a matter on it """ next_dir = get_next_dir_to(particle.coords[0], particle.coords[1], destiny.coords[0], destiny.coords[1]) if particle.matter_in(next_dir) or next_dir == -1: return True if particle.matter_in(next_dir): particle.get_matter_in(next_dir) return particle.get_matter_in(next_dir) particle.move_to(next_dir) print("\n P", particle.number, " moves to", dir_to_str(next_dir)) return False def get_next_dir_to(src_x, src_y, dest_x, dest_y): """ :param src_x: x coordinate of the source :param src_x: x coordinate of the source :param src_y: y coordinate of the source :param dest_x: x coordinate of the destiny :param dest_x: x coordinate of the destiny :param dest_y: y coordinate of the destiny :return: the next direction that brings the matter closer to the destiny :return: the next direction that brings the matter closer to the destiny """ next_dir = -1 if (src_x < dest_x or src_x == dest_x) and src_y < dest_y: ... ... @@ -67,17 +74,18 @@ def get_next_dir_to(src_x, src_y, dest_x, dest_y): next_dir = E return next_dir def dir_to_str(dir): """ :param dir: the direction that should get converted to a string :return: the string of the direction """ if dir == 0: return "NO" return "NE" elif dir == 1: return "O" return "E" elif dir == 2: return "SO" return "SE" elif dir == 3: return "SW" elif dir == 4: ... ... @@ -89,10 +97,7 @@ def dir_to_str(dir): def get_the_invert(dir): if dir >= 3: return dir - 3 else: return dir + 3 return (dir + 3) % 6 def dir_in_range(dir): ... ...
 ... ... @@ -2,7 +2,7 @@ This solution just scans for particles that are within 5 hops range and prints them out. """ #Standard Lib that has to be in each solution from lib.std_lib import * from solution.std_lib import * def solution(sim): if sim.get_actual_round() == 1 : ... ...
 ... ... @@ -6,7 +6,7 @@ import logging import random #Standard Lib that has to be in each solution from lib.std_lib import * from solution.std_lib import * def solution(sim): ... ...
This diff is collapsed.
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!