Commit 7d66b9e5 authored by Ahmad Reza Cheraghi's avatar Ahmad Reza Cheraghi
Browse files

Update particle.py

parent e88336b3
...@@ -38,9 +38,9 @@ particle_counter=0 ...@@ -38,9 +38,9 @@ particle_counter=0
class Particle(matter.Matter): class Particle(matter.Matter):
"""In the classe marker all the methods for the characterstic of a marker is included""" """In the classe marker all the methods for the characterstic of a marker is included"""
def __init__(self, sim, x, y, color=black, alpha=1, mm_limit=0, mm_size=0): def __init__(self, sim, x, y, color=black, alpha=1):
"""Initializing the marker constructor""" """Initializing the marker constructor"""
super().__init__( sim, x, y, color, alpha, type="particle", mm_limit=mm_limit, mm_size=mm_size) super().__init__( sim, (x, y), color, alpha, type="particle", mm_size=sim.config_data.particle_mm_size)
global particle_counter global particle_counter
particle_counter+=1 particle_counter+=1
self.number=particle_counter self.number=particle_counter
...@@ -122,18 +122,11 @@ class Particle(matter.Matter): ...@@ -122,18 +122,11 @@ class Particle(matter.Matter):
:return: True: Success Moving; False: Non moving :return: True: Success Moving; False: Non moving
""" """
dir_coord = self.sim.get_coords_in_dir(self.coords, dir) dir_coord = self.sim.get_coords_in_dir(self.coords, dir)
#sim = self.sim_to_coords(dir_coord[0], dir_coord[1]) dir, dir_coord = self.check_within_border(dir, dir_coord)
#print ("sim actual coord "+ str(sim))
if self.sim.border==1:
if abs(dir_coord[0]) > self.sim.get_sim_x_size() or abs(dir_coord[1]) > self.sim.get_sim_y_size() :
dir = dir - 3 if dir > 2 else dir + 3
dir_coord = self.sim.get_coords_in_dir(self.coords, dir)
if self.sim.check_coords(dir_coord[0], dir_coord[1]): if self.sim.check_coords(dir_coord[0], dir_coord[1]):
try: # cher: added so the program does not crashed if it does not find any entries in the map if self.sim.particle_map_coords[self.coords]:
del self.sim.particle_map_coords[self.coords] del self.sim.particle_map_coords[self.coords]
except KeyError:
pass
if not dir_coord in self.sim.particle_map_coords: if not dir_coord in self.sim.particle_map_coords:
self.coords = dir_coord self.coords = dir_coord
...@@ -142,15 +135,25 @@ class Particle(matter.Matter): ...@@ -142,15 +135,25 @@ class Particle(matter.Matter):
self.sim.csv_round_writer.update_metrics( steps=1) self.sim.csv_round_writer.update_metrics( steps=1)
self.csv_particle_writer.write_particle(steps=1) self.csv_particle_writer.write_particle(steps=1)
self.touch() self.touch()
if self.carried_tile is not None: self.check_for_carried_tile_or_particle()
self.carried_tile.coords = self.coords
self.carried_tile.touch()
elif self.carried_particle is not None:
self.carried_particle.coords = self.coords
self.carried_particle.touch()
return True return True
return False return False
def check_for_carried_tile_or_particle(self):
if self.carried_tile is not None:
self.carried_tile.coords = self.coords
self.carried_tile.touch()
elif self.carried_particle is not None:
self.carried_particle.coords = self.coords
self.carried_particle.touch()
def check_within_border(self, dir, dir_coord):
if self.sim.border == 1 and \
(abs(dir_coord[0]) > self.sim.get_sim_x_size() or abs(dir_coord[1]) > self.sim.get_sim_y_size()):
dir = dir - 3 if dir > 2 else dir + 3
dir_coord = self.sim.get_coords_in_dir(self.coords, dir)
return dir, dir_coord
def move_to_in_bounds(self, dir): def move_to_in_bounds(self, dir):
""" """
Moves the particle to the given direction if it would remain in bounds. Moves the particle to the given direction if it would remain in bounds.
...@@ -195,9 +198,6 @@ class Particle(matter.Matter): ...@@ -195,9 +198,6 @@ class Particle(matter.Matter):
else: else:
return None return None
def matter_in(self, dir=E): def matter_in(self, dir=E):
""" """
:param dir: the direction to check if a matter is there :param dir: the direction to check if a matter is there
...@@ -250,7 +250,6 @@ class Particle(matter.Matter): ...@@ -250,7 +250,6 @@ class Particle(matter.Matter):
else: else:
return False return False
def get_tile_in(self, dir=E): def get_tile_in(self, dir=E):
if self.sim.get_coords_in_dir(self.coords, dir) in self.sim.get_tile_map_coords(): if self.sim.get_coords_in_dir(self.coords, dir) in self.sim.get_tile_map_coords():
return self.sim.get_tile_map_coords()[self.sim.get_coords_in_dir(self.coords, dir)] return self.sim.get_tile_map_coords()[self.sim.get_coords_in_dir(self.coords, dir)]
...@@ -281,7 +280,6 @@ class Particle(matter.Matter): ...@@ -281,7 +280,6 @@ class Particle(matter.Matter):
else: else:
return False return False
def write_to_with(self, matter, key=None, data=None): def write_to_with(self, matter, key=None, data=None):
""" """
Writes data with given a keyword directly on the matters (paricle, tile, or marker object) memory Writes data with given a keyword directly on the matters (paricle, tile, or marker object) memory
...@@ -1487,7 +1485,6 @@ class Particle(matter.Matter): ...@@ -1487,7 +1485,6 @@ class Particle(matter.Matter):
logging.info("Going to create a marker in %s on position %s", str(dir), str(coords)) logging.info("Going to create a marker in %s on position %s", str(dir), str(coords))
new_marker = self.sim.add_marker(coords[0], coords[1], color, alpha) new_marker = self.sim.add_marker(coords[0], coords[1], color, alpha)
if new_marker: if new_marker:
# self.sim.new_marker_flag = True
logging.info("Created marker on coords %s", str(coords)) logging.info("Created marker on coords %s", str(coords))
self.sim.csv_round_writer.update_markers_num(len(self.sim.get_marker_list())) self.sim.csv_round_writer.update_markers_num(len(self.sim.get_marker_list()))
self.sim.csv_round_writer.update_metrics( marker_created=1) self.sim.csv_round_writer.update_metrics( marker_created=1)
...@@ -1514,7 +1511,6 @@ class Particle(matter.Matter): ...@@ -1514,7 +1511,6 @@ class Particle(matter.Matter):
logging.info("Going to create a marker on position %s", str(coords)) logging.info("Going to create a marker on position %s", str(coords))
new_marker = self.sim.add_marker(coords[0], coords[1], color, alpha) new_marker = self.sim.add_marker(coords[0], coords[1], color, alpha)
if new_marker: if new_marker:
# self.sim.new_marker_flag = True
logging.info("Created marker on coords %s", str(coords)) logging.info("Created marker on coords %s", str(coords))
self.sim.csv_round_writer.update_markers_num(len(self.sim.get_marker_list())) self.sim.csv_round_writer.update_markers_num(len(self.sim.get_marker_list()))
self.sim.csv_round_writer.update_metrics( marker_created=1) self.sim.csv_round_writer.update_metrics( marker_created=1)
......
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