Commit 1ea3ec5e authored by Ahmad Reza's avatar Ahmad Reza
Browse files

Big Update:

!!!Almost all the the Swarm-Sim core libaries written at the HHU
has no code smells!!!!! :)))) Only vis.py has code smells and this
is not written by HHU. And multiple.py as well and some solutions.
But in total all the core libaries/interfaces of the Swarm-Sim
has no code smells. Yeapy!!!!
Changes:
The scanning for matters method has been modified and refactored.
The header became a new function called scanning.
The stl_lib for the scenarios became to methods.
One for creating particles in hexagon.
The other one for creating a hexagon border with tiles.
parent a17fa86a
......@@ -67,5 +67,6 @@ tile_mm_size = 2
## All interfaces
scenario = test_interfaces
#scenario = hexagon_border
solution = test_all_the_interfaces
......@@ -109,3 +109,37 @@ def coords_to_sim(coords):
def sim_to_coords(x, y):
return x, round(y / math.sqrt(3 / 4), 0)
def scan(matter_map_coords, hop, starting_x, starting_y):
hop_list = []
if (hop / 2 + starting_x, hop + starting_y) in matter_map_coords:
hop_list.append(matter_map_coords[(hop / 2 + starting_x, hop + starting_y)])
if (hop + starting_x, starting_y) in matter_map_coords:
hop_list.append(matter_map_coords[(hop + starting_x, starting_y)])
if (hop / 2 + starting_x, -hop + starting_y) in matter_map_coords:
hop_list.append(matter_map_coords[(hop / 2 + starting_x, -hop + starting_y)])
if (-hop / 2 + starting_x, -hop + starting_y) in matter_map_coords:
hop_list.append(matter_map_coords[(-hop / 2 + starting_x, -hop + starting_y)])
if (-hop + starting_x, starting_y) in matter_map_coords:
hop_list.append(matter_map_coords[(-hop + starting_x, starting_y)])
if (-hop / 2 + starting_x, hop + starting_y) in matter_map_coords:
hop_list.append(matter_map_coords[(-hop / 2 + starting_x, hop + starting_y)])
for i in range(1, hop):
if (-hop / 2 + i + starting_x, hop + starting_y) in matter_map_coords:
hop_list.append(matter_map_coords[(-hop / 2 + i + starting_x, hop + starting_y)])
if (hop / 2 + (0.5 * i) + starting_x, hop - i + starting_y) in matter_map_coords:
hop_list.append(
matter_map_coords[(hop / 2 + (0.5 * i) + starting_x, hop - i + starting_y)])
if (hop / 2 + (0.5 * i) + starting_x, -hop + i + starting_y) in matter_map_coords:
hop_list.append(
matter_map_coords[(hop / 2 + (0.5 * i) + starting_x, -hop + i + starting_y)])
if (-hop / 2 + i + starting_x, -hop + starting_y) in matter_map_coords:
hop_list.append(matter_map_coords[(-hop / 2 + i + starting_x, -hop + starting_y)])
if (-hop / 2 - (0.5 * i) + starting_x, -hop + i + starting_y) in matter_map_coords:
hop_list.append(
matter_map_coords[(-hop / 2 - (0.5 * i) + starting_x, -hop + i + starting_y)])
if (-hop / 2 - (0.5 * i) + starting_x, hop - i + starting_y) in matter_map_coords:
hop_list.append(
matter_map_coords[(-hop / 2 - (0.5 * i) + starting_x, hop - i + starting_y)])
return hop_list
This diff is collapsed.
......@@ -3,8 +3,8 @@ import random
def generating_random_spraded_particles (world, max_size_particle):
for _ in range(0, max_size_particle):
x = random.randrange(-world.get_sim_x_size(), world.get_sim_x_size())
y = random.randrange(-world.get_sim_y_size(), world.get_sim_y_size())
x = random.randrange(-world.get_world_x_size(), world.get_world_x_size())
y = random.randrange(-world.get_world_y_size(), world.get_world_y_size())
if y % 2 == 1:
x = x + 0.5
if (x, y) not in world.tile_map_coords:
......@@ -37,3 +37,39 @@ def create_particle_in_square(world, max_size_particle, start_coords):
world.add_particle(-x, 2 * y)
world.add_particle(x, -2 * y)
world.add_particle(-x, - 2 * y)
def create_particle_in_hexagons(world, radius):
radius = 3
world.add_particle(0, 0)
displacement = - radius + 0.5
iteration = 0
for i in range(1, radius + 1):
world.add_particle(i, 0)
world.add_particle(-i, 0)
for i in range(1, radius + 1):
for j in range(0, (2 * radius) - iteration):
world.add_particle(displacement + j, i)
world.add_particle(displacement + j, -i)
iteration = iteration + 1
displacement = displacement + 0.5
def create_tiles_formed_as_hexagons_border(world, radius, starting_x = 0, starting_y = 0):
offset_x = 0
if starting_y % 2 != 0:
offset_x = 0.5
world.add_tile(radius/2 + starting_x + offset_x, radius + starting_y)
world.add_tile(radius + starting_x + offset_x, starting_y)
world.add_tile(radius/2 + starting_x + offset_x, -radius + starting_y)
world.add_tile(-radius/2 + starting_x + offset_x, -radius + starting_y)
world.add_tile(-radius + starting_x + offset_x, starting_y)
world.add_tile(-radius/2 + starting_x + offset_x, radius + starting_y)
for i in range(1, radius):
world.add_tile(-radius/2 + i + starting_x + offset_x, radius + starting_y)
world.add_tile(radius/2 + (0.5 * i ) + starting_x + offset_x, radius - i + starting_y)
world.add_tile(radius/2 + (0.5 * i) + starting_x + offset_x, -radius + i + starting_y)
world.add_tile(-radius/2 + i + starting_x + offset_x, -radius + starting_y)
world.add_tile(-radius/2 - (0.5 * i) + starting_x + offset_x, -radius + i + starting_y)
world.add_tile(-radius/2 - (0.5 * i) + starting_x + offset_x, radius - i + starting_y)
......@@ -3,6 +3,7 @@ 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 solution.std_lib import *
def solution(world):
"""
......
......@@ -3,12 +3,13 @@ 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 solution.std_lib import *
def solution(world):
all_matters_list=[]
if world.get_actual_round() == 1:
all_matters_list=world.get_particle_map_coords()[(0,0)].scan_for_matter_within(hop=5)
all_matters_list=world.get_particle_map_coords()[(0,0)].scan_for_matters_within(hop=5)
for list in all_matters_list:
if list.type=='particle':
print ("particle at", list.coords)
......@@ -16,4 +17,13 @@ def solution(world):
print("tile", list.coords)
elif list.type=='marker':
print("marker", list.coords)
if world.get_actual_round() == 2:
all_matters_list = world.get_particle_map_coords()[(0, 0)].scan_for_particles_within(hop=5)
for list in all_matters_list:
print ("particle at", list.coords)
all_matters_list = world.get_particle_map_coords()[(0, 0)].scan_for_tiles_within(hop=5)
for list in all_matters_list:
print("tile", list.coords)
all_matters_list = world.get_particle_map_coords()[(0, 0)].scan_for_markers_within(hop=5)
for list in all_matters_list:
print("marker", list.coords)
"""
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 solution.std_lib import *
......
......@@ -13,7 +13,7 @@ def solution(world):
if world.get_actual_round() == 1:
print ("Scanning for markers, tiles and particles")
logging.info("Scanning for markers, tiles and particles")
all_matters_list = world.get_particle_map_coords()[(0, 0)].scan_for_matter_within()
all_matters_list = world.get_particle_map_coords()[(0, 0)].scan_for_matters_within()
for list in all_matters_list:
if list.type == 'particle':
print("particle at", list.coords)
......
......@@ -29,13 +29,13 @@ def swarm_sim(argv):
while swarm_sim_world.get_actual_round() <= config_data.max_round and swarm_sim_world.get_end() is False:
round_start_timestamp = time.perf_counter()
run_solution(swarm_sim_world)
if config_data.visualization:
swarm_sim_world.window.draw_world(round_start_timestamp)
if swarm_sim_world.window.window_active is False:
break
run_solution(swarm_sim_world)
generate_data(config_data, swarm_sim_world)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment