Commit 8c8e3c88 authored by Ahmad Reza Cheraghi's avatar Ahmad Reza Cheraghi
Browse files

Replace particle.py

parent f63019d5
......@@ -196,7 +196,9 @@ class Particle:
hop_list = []
for i in range(0, hop + 1):
hop_list.extend(self.scan_for_aim_in(aim, i))
list = self.scan_for_aim_in(aim, i)
if list != None:
hop_list.extend(list)
if len(hop_list) != 0:
return hop_list
else:
......@@ -204,7 +206,7 @@ class Particle:
def scan_for_aim_in(self, aim='all', hop=1):
"""
Scanns for particles, tiles, or location on a given hop distance
Scanning for particles, tiles, or location on a given hop distance
:param aim: For what aim this method should scan for. Can be either particles, tiles, locations, or (default)all
:param hop: The hop distance from thee actual position of the scanning particle
......@@ -369,9 +371,9 @@ class Particle:
logging.info("Nothing in %s hops", str(hop))
return None
def take(self, coords=0):
def take_me(self, coords=0):
"""
Takes the tile on the given coordinate if it is not taken
The particle is getting taken from the the other particle on the given coordinate
:param coords: Coordination of tile that should be taken
:return: True: Successful taken; False: Cannot be taken or wrong Coordinates
......@@ -446,7 +448,7 @@ class Particle:
else:
logging.info("Not created tile on coords %s", str(coords))
def delete_tile(self, tile_id):
def delete_tile(self, id):
"""
Deletes a tile with a given tile-id
......@@ -454,12 +456,12 @@ class Particle:
:return: True: Deleting successful; False: Deleting unsuccessful
"""
logging.info("Particle %s is", self.id)
logging.info("is going to delete a tile with tile id %s", str(tile_id))
if self.world.remove_tile(tile_id):
logging.info("is going to delete a tile with tile id %s", str(id))
if self.world.remove_tile(id):
self.csv_particle_writer.write_particle(tile_deleted=1)
return True
else:
logging.info("Could not delet tile with tile id %s", str(tile_id))
logging.info("Could not delet tile with tile id %s", str(id))
return False
def delete_tile_in(self, dir=E):
......@@ -508,30 +510,57 @@ class Particle:
logging.info("Could not delet tile on coords %s", str(coords))
return False
def take_tile(self, tile_id):
def take_tile(self):
"""
Takes a tile on the actual position
:param id: The id of the tile that should be taken
:return: True: successful taken; False: unsuccessful taken
"""
if self.carried_particle is None and self.carried_tile is None:
if self.coords in self.world.tile_map:
self.carried_tile = self.world.tile_map[self.coords]
if self.carried_tile.take(coords=self.coords):
logging.info("Tile has been taken")
self.world.csv_round_writer.update_metrics(self.world.sim.get_actual_round(), tiles_taken=1)
self.csv_particle_writer.write_particle(tiles_taken=1)
return True
else:
logging.info("Tile could not be taken")
return False
else:
logging.info("No tile on the actual position not in the world")
return False
else:
logging.info("Tile cannot taken because particle is carrieng either a tile or a particle")
return False
def take_tile_with(self, id):
"""
Takes a tile with a given tile id
:param tile_id: The id of the tile that should be taken
:param id: The id of the tile that should be taken
:return: True: successful taken; False: unsuccessful taken
"""
if self.carried_particle is None and self.carried_tile is None:
if tile_id in self.world.tile_id_map:
logging.info("Tile with tile id %s is in the world", str(tile_id))
self.carried_tile = self.world.tile_id_map[tile_id]
if id in self.world.tile_id_map:
logging.info("Tile with tile id %s is in the world", str(id))
self.carried_tile = self.world.tile_id_map[id]
if self.carried_tile.take(coords=self.coords):
logging.info("Tile with tile id %s has been taken", str(tile_id))
logging.info("Tile with tile id %s has been taken", str(id))
self.world.csv_round_writer.update_metrics(self.world.sim.get_actual_round(), tiles_taken=1)
self.csv_particle_writer.write_particle(tiles_taken=1)
return True
else:
logging.info("Tile with tile id %s could not be taken", str(tile_id))
logging.info("Tile with tile id %s could not be taken", str(id))
return False
else:
logging.info("Tile with tile id %s is not in the world", str(tile_id))
logging.info("Tile with tile id %s is not in the world", str(id))
return False
else:
logging.info("Tile cannot taken because particle is carrieng either a tile or a particle", str(tile_id))
logging.info("Tile cannot taken because particle is carrieng either a tile or a particle", str(id))
return False
def take_tile_in(self, dir):
......@@ -593,7 +622,7 @@ class Particle:
logging.info("Tile cannot taken because particle is carrieng either a tile or a particle")
return False
def drop_taken_tile(self):
def drop_tile(self):
"""
Drops the taken tile on the particles actual position
......@@ -788,7 +817,8 @@ class Particle:
else:
return False
def take_particle(self, id):
def take_particle_with(self, id):
"""
Takes a particle with a given tile id
......@@ -799,7 +829,7 @@ class Particle:
if id in self.world.id_map:
logging.info("particle with particle id %s is in the world", str(id))
self.carried_particle = self.world.particle_id_map[id]
if self.take(self.coords):
if self.carried_particle.take_me(self.coords):
logging.info("particle with particle id %s has been taken", str(id))
self.world.csv_round_writer.update_metrics(self.world.sim.get_actual_round(),
......@@ -826,7 +856,7 @@ class Particle:
if coords in self.world.particle_map:
logging.info("Take particle")
self.carried_particle = self.world.particle_map[coords]
if self.carried_particle.take(coords=self.coords):
if self.carried_particle.take_me(coords=self.coords):
logging.info("particle with particle id %s has been taken", str(self.carried_particle.id))
self.world.csv_round_writer.update_metrics(self.world.sim.get_actual_round(),
particles_taken=1)
......@@ -850,24 +880,27 @@ class Particle:
:return: True: Successful taken; False: Cannot be taken or wrong Coordinates
"""
if self.carried_particle is None and self.carried_tile is None:
if x is not None and y is not None:
if self.world.check_coords(x=x, y=y):
coords = (x, y)
if not self.__isCarried:
del self.world.particle_map[coords]
self.__isCarried = True
self.touch()
self.world.csv_round_writer.update_metrics(self.world.sim.get_actual_round(),
particles_taken=1)
if self.world.check_coords(x=x, y=y):
coords = (x, y)
if coords in self.world.particle_map:
self.carried_particle = self.world.particle_map[coords]
logging.info("Particle with id %s is in the world", str(self.carried_particle.id))
if self.carried_particle.take_me(coords=self.coords):
self.world.csv_round_writer.update_metrics(self.world.sim.get_actual_round(), particles_taken=1)
self.csv_particle_writer.write_particle(particles_taken=1)
logging.info("particle with tile id %s has been taken", str(self.carried_particle.id))
return True
else:
logging.info("Particle with id %s could not be taken", str(self.carried_particle.id))
return False
else:
logging.info("Particle is not in the world")
return False
else:
logging.info("Coordinates are wrong")
return False
else:
logging.info("Particle cannot taken because particle is carrieng either a tile or a particle")
return False
def drop_particle(self):
......
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