Commit d94fddf8 authored by Karol Actun's avatar Karol Actun
Browse files

swarm-sim without visualization is running now

parent a429d990
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
.idea/*
.ides*
.idea*
# User-specific stuff
.idea/**/workspace.xml
.idea/**/tasks.xml
......
......@@ -135,14 +135,14 @@ tile_mm_size = 2
##Examples##
#marking (rasenmäher) algorithm in 3D
#marking (rasenmaeher) algorithm in 3D
;scenario = marking_3d_scenario
;solution = marking_3d_local
##Moving
#scenario = lonely_particle
scenario = n_particle_in_line
solution = random_walk
#scenario = n_particle_in_line
#solution = random_walk
#solution = triangular_round_walk
#solution = random_walk_with_take_and_drop
......@@ -158,7 +158,7 @@ solution = random_walk
#scenario = two_particles_tiles_markers
#solution = read_write
;scenario = test_interfaces
;solution = test_all_the_interfaces
scenario = test_interfaces
solution = test_all_the_interfaces
......@@ -11,4 +11,5 @@ class Location(matter.Matter):
def set_color(self, color):
super().set_color(color)
self.world.vis.location_changed(self)
if self.world.vis is not None:
self.world.vis.location_changed(self)
......@@ -95,7 +95,8 @@ class Particle(matter.Matter):
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)
if self.world.vis is not None:
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)
......@@ -107,10 +108,12 @@ class Particle(matter.Matter):
def check_for_carried_tile_or_particle(self):
if self.carried_tile is not None:
self.carried_tile.coordinates = self.coordinates
self.world.vis.tile_changed(self.carried_tile)
if self.world.vis is not None:
self.world.vis.tile_changed(self.carried_tile)
elif self.carried_particle is not None:
self.carried_particle.coordinates = self.coordinates
self.world.vis.particle_changed(self.carried_particle)
if self.world.vis is not None:
self.world.vis.particle_changed(self.carried_particle)
def check_within_border(self, direction, direction_coord):
if self.world.config_data.border == 1 and \
......@@ -384,7 +387,8 @@ class Particle(matter.Matter):
del self.world.particle_map_coordinates[self.coordinates]
self.__isCarried = True
self.coordinates = coordinates
self.world.vis.particle_changed(self)
if self.world.vis is not None:
self.world.vis.particle_changed(self)
return True
else:
return False
......@@ -399,7 +403,8 @@ class Particle(matter.Matter):
self.coordinates = coordinates
self.world.particle_map_coordinates[coordinates] = self
self.__isCarried = False
self.world.vis.particle_changed(self)
if self.world.vis is not None:
self.world.vis.particle_changed(self)
def create_tile(self):
"""
......@@ -561,7 +566,8 @@ class Particle(matter.Matter):
if self.carried_tile.take():
logging.info("Tile with tile id %s has been taken", str(tile_id))
self.carried_tile.coordinates = self.coordinates
self.world.vis.tile_changed(self.carried_tile)
if self.world.vis is not None:
self.world.vis.tile_changed(self.carried_tile)
self.world.csv_round.update_metrics(tiles_taken=1)
self.csv_particle_writer.write_particle(tiles_taken=1)
return True
......@@ -821,7 +827,8 @@ class Particle(matter.Matter):
if self.carried_particle.take_me(self.coordinates):
logging.info("particle with particle id %s has been taken" % str(particle_id))
self.carried_particle.coordinates = self.coordinates
self.world.vis.particle_changed(self.carried_particle)
if self.world.vis is not None:
self.world.vis.particle_changed(self.carried_particle)
self.world.csv_round.update_metrics(particles_taken=1)
self.csv_particle_writer.write_particle(particles_taken=1)
return True
......@@ -922,7 +929,8 @@ class Particle(matter.Matter):
if self.world.grid.are_valid_coordinates(new_coordinates):
particle.coordinates = new_coordinates
self.world.particle_map_coordinates[new_coordinates] = particle
self.world.vis.particle_changed(particle)
if self.world.vis is not None:
self.world.vis.particle_changed(particle)
return True
else:
return False
......@@ -1060,4 +1068,5 @@ class Particle(matter.Matter):
def set_color(self, color):
super().set_color(color)
self.world.vis.particle_changed(self)
if self.world.vis is not None:
self.world.vis.particle_changed(self)
......@@ -39,7 +39,8 @@ class Tile(matter.Matter):
if self.coordinates in self.world.tile_map_coordinates:
del self.world.tile_map_coordinates[self.coordinates]
self.__isCarried = True
self.world.vis.tile_changed(self)
if self.world.vis is not None:
self.world.vis.tile_changed(self)
return True
else:
return False
......@@ -54,8 +55,10 @@ class Tile(matter.Matter):
self.coordinates = coordinates
self.world.tile_map_coordinates[self.coordinates] = self
self.__isCarried = False
self.world.vis.tile_changed(self)
if self.world.vis is not None:
self.world.vis.tile_changed(self)
def set_color(self, color):
super().set_color(color)
self.world.vis.tile_changed(self)
if self.world.vis is not None:
self.world.vis.tile_changed(self)
......@@ -62,6 +62,8 @@ class World:
if config_data.visualization:
self.vis = vis3d.Visualization(self)
else:
self.vis = None
mod = importlib.import_module('scenario.' + self.config_data.scenario)
......
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