Commit 05a8706a authored by Ahmad Reza's avatar Ahmad Reza
Browse files

removed some codes-smells issues.

parent f5db65db
......@@ -4,7 +4,7 @@
seedvalue = 12
## Maximum round number in swarm-world, 0 = infinite
max_round = 0
max_round = 10
## 1/True = Call of particles in randmom order
## 0/False = Call of particles in added order in scenario
......
......@@ -158,7 +158,7 @@ class Grid(ABC):
current_ns = ns
result.update(ns)
for i in range(radius):
for _ in range(radius):
tmp = set()
for n in current_ns:
ns = self._get_adjacent_coordinates_not_in_set(n, result)
......@@ -186,7 +186,7 @@ class Grid(ABC):
seen.update(ns)
seen.add(coordinates)
for i in range(radius-1):
for _ in range(radius-1):
tmp = set()
for n in current_ns:
ns = self._get_adjacent_coordinates_not_in_set(n, seen)
......
......@@ -89,18 +89,18 @@ class Particle(matter.Matter):
"""
direction_coord = get_coordinates_in_direction(self.coordinates, direction)
direction, direction_coord = self.check_within_border(direction, direction_coord)
if self.world.grid.are_valid_coordinates(direction_coord):
if direction_coord not in self.world.particle_map_coordinates:
if self.coordinates in self.world.particle_map_coordinates:
del self.world.particle_map_coordinates[self.coordinates]
self.coordinates = direction_coord
self.world.particle_map_coordinates[self.coordinates] = self
self.world.vis.particle_changed(self)
logging.info("particle %s successfully moved to %s", str(self.get_id()), direction)
self.world.csv_round.update_metrics(steps=1)
self.csv_particle_writer.write_particle(steps=1)
self.check_for_carried_tile_or_particle()
return True
if self.world.grid.are_valid_coordinates(direction_coord) \
and direction_coord not in self.world.particle_map_coordinates:
if self.coordinates in self.world.particle_map_coordinates:
del self.world.particle_map_coordinates[self.coordinates]
self.coordinates = direction_coord
self.world.particle_map_coordinates[self.coordinates] = self
self.world.vis.particle_changed(self)
logging.info("particle %s successfully moved to %s", str(self.get_id()), direction)
self.world.csv_round.update_metrics(steps=1)
self.csv_particle_writer.write_particle(steps=1)
self.check_for_carried_tile_or_particle()
return True
return False
......@@ -133,18 +133,18 @@ class Particle(matter.Matter):
else:
tmp_memory = target.read_whole_memory()
if tmp_memory is not None:
if not (hasattr(tmp_memory, '__len__')) or len(tmp_memory) > 0:
if target.type == "particle":
self.world.csv_round.update_metrics(particle_read=1)
self.csv_particle_writer.write_particle(particle_read=1)
elif target.type == "tile":
self.world.csv_round.update_metrics(tile_read=1)
self.csv_particle_writer.write_particle(tile_read=1)
elif target.type == "location":
self.world.csv_round.update_metrics(location_read=1)
self.csv_particle_writer.write_particle(location_read=1)
return tmp_memory
if tmp_memory is not None \
and not (hasattr(tmp_memory, '__len__')) or len(tmp_memory) > 0:
if target.type == "particle":
self.world.csv_round.update_metrics(particle_read=1)
self.csv_particle_writer.write_particle(particle_read=1)
elif target.type == "tile":
self.world.csv_round.update_metrics(tile_read=1)
self.csv_particle_writer.write_particle(tile_read=1)
elif target.type == "location":
self.world.csv_round.update_metrics(location_read=1)
self.csv_particle_writer.write_particle(location_read=1)
return tmp_memory
return None
def matter_in(self, direction):
......
......@@ -202,8 +202,6 @@ class Visualization:
self._wait_while_not_running()
time_elapsed = time.perf_counter() - round_start_timestamp
#GL.glFinish()
#end = time.perf_counter_ns()
def remove_particle(self, particle):
"""
......
......@@ -159,7 +159,6 @@ class GridProgram(Program):
eprint("WARNING: invalid offset data! "
"Amount of coordinate components not dividable by 3 (not in xyz format?)!")
self.amount = int(self.amount)
pass
def set_line_scaling(self, scaling):
"""
......
......@@ -80,7 +80,6 @@ class OffsetColorProgram(Program):
eprint("WARNING: invalid offset data! "
"Amount of coordinate components not dividable by 3 (not in xyz format?)!")
self.amount = int(self.amount)
pass
def update_colors(self, data):
"""
......
......@@ -7,4 +7,5 @@ def solution(world):
if world.get_actual_round() % 1 == 0:
for particle in world.get_particle_list():
print(world.get_actual_round()," Particle No.", particle.number)
particle.move_to(random.choice(dirs))
Markdown is supported
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