particle.py 72 KB
Newer Older
Ahmad Reza's avatar
Ahmad Reza committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
"""
.. module:: particle
   :platform: Unix, Windows
   :synopsis: This module provides the interfaces of the robotics particle

.. moduleauthor:: Ahmad Reza Cheraghi

TODO: Erase Memory

"""

import logging, math
from lib import csv_generator, matter

black = 1
gray = 2
red = 3
green = 4
blue = 5
20
21
22
23
yellow = 6
orange = 7
cyan = 8
violett = 9
Ahmad Reza's avatar
Ahmad Reza committed
24
25
26
27
28
29
30
31
32
33
34
35
36
37


NE=0
E = 1
SE = 2
SW = 3
W = 4
NW = 5


read = 0
write = 1
particle_counter=0

Ahmad Reza's avatar
Ahmad Reza committed
38
class Particle(matter.Matter):
Ahmad Reza's avatar
Ahmad Reza committed
39
40
    """In the classe location all the methods for the characterstic of a location is included"""

41
    def __init__(self, sim, x, y, color=black, alpha=1, mm_limit=0, mm_size=0):
Ahmad Reza's avatar
Ahmad Reza committed
42
        """Initializing the location constructor"""
Ahmad Reza's avatar
Ahmad Reza committed
43
        super().__init__( sim, x, y, color, alpha, type="particle", mm_limit=mm_limit, mm_size=mm_size)
Ahmad Reza's avatar
Ahmad Reza committed
44
45
46
47
48
49
50
51
52
53
54
55
        global particle_counter
        particle_counter+=1
        self.number=particle_counter
        self.__isCarried = False
        self.created = False
        self.carried_tile = None
        self.carried_particle = None
        self.__isCarried = False
        self.steps = 0
        self.created = False
        self.csv_particle_writer = csv_generator.CsvParticleData( self.get_id(), self.number)

56
    def coords_to_sim(self, coords):
Ahmad Reza's avatar
Ahmad Reza committed
57
58
        return coords[0], coords[1] * math.sqrt(3 / 4)

59
    def sim_to_coords(self, x, y):
Ahmad Reza's avatar
Ahmad Reza committed
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
        return x, round(y / math.sqrt(3 / 4), 0)

    def has_tile(self):
        if self.carried_tile == None:
            return False
        else:
            return True

    def has_particle(self):
        if self.carried_particle == None:
            return False
        else:
            return True


    def get_carried_status(self):
        """
        Get the status if it is taken or not

        :return: Tiles status
        """
        return self.__isCarried

    def check_on_tile(self):
        """
        Checks if the particle is on a tile

        :return: True: On a tile; False: Not on a Tile
        """
89
        if self.coords in self.sim.tile_map_coords:
Ahmad Reza's avatar
Ahmad Reza committed
90
91
92
93
94
95
96
97
98
99
100
            return True
        else:
            return False


    def check_on_particle(self):
        """
        Checks if the particle is on a particle

        :return: True: On a particle; False: Not on a particle
        """
101
        if self.coords in self.sim.particle_map_coords:
Ahmad Reza's avatar
Ahmad Reza committed
102
103
104
105
106
107
108
109
110
111
            return True
        else:
            return False

    def check_on_location(self):
        """
        Checks if the particle is on a location

        :return: True: On a location; False: Not on a location
        """
112
        if self.coords in self.sim.location_map_coords:
Ahmad Reza's avatar
Ahmad Reza committed
113
114
115
116
117
118
119
120
121
122
123
            return True
        else:
            return False

    def move_to(self, dir):
        """
        Moves the particle to the given direction

        :param dir: The direction must be either: E, SE, SW, W, NW, or NE
        :return: True: Success Moving;  False: Non moving
        """
124
        dir_coord = self.sim.get_coords_in_dir(self.coords, dir)
125
126
127
        #sim = self.sim_to_coords(dir_coord[0], dir_coord[1])
        #print ("sim actual coord "+ str(sim))
        if self.sim.border==1:
Ahmad Reza's avatar
Ahmad Reza committed
128
            if abs(dir_coord[0]) > self.sim.get_sim_x_size() or  abs(dir_coord[1]) > self.sim.get_sim_y_size() :
129
130
                dir = dir - 3 if dir > 2 else dir + 3
                dir_coord = self.sim.get_coords_in_dir(self.coords, dir)
131
        if self.sim.check_coords(dir_coord[0], dir_coord[1]):
Ahmad Reza's avatar
Ahmad Reza committed
132
133

            try:  # cher: added so the program does not crashed if it does not find any entries in the map
134
                del self.sim.particle_map_coords[self.coords]
Ahmad Reza's avatar
Ahmad Reza committed
135
136
137
            except KeyError:
                pass
            self.coords = dir_coord
138
139
            if not self.coords in self.sim.particle_map_coords:
                self.sim.particle_map_coords[self.coords] = self
Ahmad Reza's avatar
Ahmad Reza committed
140
                logging.info("particle %s successfully moved to %s", str(self.get_id()), dir)
Ahmad Reza's avatar
Ahmad Reza committed
141
                self.sim.csv_round_writer.update_metrics( steps=1)
Ahmad Reza's avatar
Ahmad Reza committed
142
143
144
145
146
147
148
149
150
                self.csv_particle_writer.write_particle(steps=1)
                self.touch()
                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()
                return True
151
        return False
Ahmad Reza's avatar
Ahmad Reza committed
152
153
154
155
156
157
158
159

    def move_to_in_bounds(self, dir):
        """
            Moves the particle to the given direction if it would remain in bounds.

            :param dir: The direction must be either: E, SE, SW, W, NW, or NE
            :return: True: Success Moving;  False: Non moving
        """
160
161
162
163
        dir_coord = self.sim.get_coords_in_dir(self.coords, dir)
        sim_coord = self.coords_to_sim(dir_coord)
        if self.sim.get_sim_x_size() >=  abs(sim_coord[0]) and \
                        self.sim.get_sim_y_size() >=  abs(sim_coord[1]):
Ahmad Reza's avatar
Ahmad Reza committed
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
            return self.move_to(dir)
        else:
            # 'bounce' off the wall
            n_dir = dir - 3 if dir > 2 else dir + 3
            self.move_to(n_dir)

    def read_from_with(self, matter, key=None):
        """
        Read the memories from the matters (paricle, tile, or location object) memories with a given keyword

        :param matter: The matter can be either a particle, tile, or location
        :param key: A string keyword to searcg for the data in the memory
        :return: The matters memory; None
        """
        if key != None:
            tmp_memory = matter.read_memory_with(key)
        else:
            tmp_memory =  matter.read_whole_memory()

        if tmp_memory != None and len(tmp_memory) > 0 :
            if matter.type == "particle":
185
                self.sim.csv_round_writer.update_metrics( particle_read=1)
Ahmad Reza's avatar
Ahmad Reza committed
186
187
                self.csv_particle_writer.write_particle(particle_read=1)
            elif matter.type == "tile":
188
                self.sim.csv_round_writer.update_metrics( tile_read=1)
Ahmad Reza's avatar
Ahmad Reza committed
189
190
                self.csv_particle_writer.write_particle(tile_read=1)
            elif matter.type == "location":
191
                self.sim.csv_round_writer.update_metrics( location_read=1)
Ahmad Reza's avatar
Ahmad Reza committed
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
                self.csv_particle_writer.write_particle(location_read=1)
            return tmp_memory
        else:
            return None

    def write_to_with(self, matter, key=None, data=None):
        """
        Writes data with given a keyword directly on the matters (paricle, tile, or location object) memory

        :param matter: The matter can be either a particle, tile, or location
        :param key: A string keyword so to order the data that is written into the memory
        :param data: The data that should be stored into the memory
        :return: True: Successful written into the memory; False: Unsuccessful
        """
        wrote=False
        if data != None:
            wrote=False
            if key==None:
                wrote=matter.write_memory(data)
            else:
                wrote= matter.write_memory_with(key, data)
            if  wrote==True:
                if matter.type == "particle":
215
                    self.sim.csv_round_writer.update_metrics( particle_write=1)
Ahmad Reza's avatar
Ahmad Reza committed
216
217
                    self.csv_particle_writer.write_particle(particle_write=1)
                elif matter.type == "tile":
218
                    self.sim.csv_round_writer.update_metrics( tile_write=1)
Ahmad Reza's avatar
Ahmad Reza committed
219
220
                    self.csv_particle_writer.write_particle(tile_write=1)
                elif matter.type == "location":
221
                    self.sim.csv_round_writer.update_metrics( location_write=1)
Ahmad Reza's avatar
Ahmad Reza committed
222
223
224
225
226
227
228
229
230
231
232
                    self.csv_particle_writer.write_particle(location_write=1)
                return True
            else:
                return False
        else:
            return False



    def matter_in(self, matter="tile", dir=E):
        if matter=="tile":
233
            return self.sim.get_coords_in_dir(self.coords, dir) in self.sim.get_tile_map_coords()
Ahmad Reza's avatar
Ahmad Reza committed
234
        if matter=="particle":
235
            return self.sim.get_coords_in_dir(self.coords, dir) in self.sim.get_particle_map_coords()
Ahmad Reza's avatar
Ahmad Reza committed
236
        if matter=="location":
237
            return self.sim.get_coords_in_dir(self.coords, dir) in self.sim.get_location_map_coords()
Ahmad Reza's avatar
Ahmad Reza committed
238
239
240


    def tile_in(self, dir=E):
241
            return self.sim.get_coords_in_dir(self.coords, dir) in self.sim.get_tile_map_coords()
Ahmad Reza's avatar
Ahmad Reza committed
242
243

    def particle_in(self, dir=E):
244
        return self.sim.get_coords_in_dir(self.coords, dir) in self.sim.get_particle_map_coords()
Ahmad Reza's avatar
Ahmad Reza committed
245
246

    def location_in(self, dir=E):
247
         return self.sim.get_coords_in_dir(self.coords, dir) in self.sim.get_location_map_coords()
Ahmad Reza's avatar
Ahmad Reza committed
248
249
250


    def get_matter_in_dir(self, matter="tile", dir=E):
251
252
253
254
255
256
257
258
259
        if matter=="tile":
            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)]
        if matter=="particle":
            if self.sim.get_coords_in_dir(self.coords, dir) in self.sim.get_particle_map_coords():
                return self.sim.get_particle_map_coords()[self.sim.get_coords_in_dir(self.coords, dir)]
        if matter=="location":
            if self.sim.get_coords_in_dir(self.coords, dir) in self.sim.get_location_map_coords():
                return self.sim.get_location_map_coords()[self.sim.get_coords_in_dir(self.coords, dir)]
Ahmad Reza's avatar
Ahmad Reza committed
260
261
262


    def get_tile_in(self, dir=E):
263
264
        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)]
Ahmad Reza's avatar
Ahmad Reza committed
265
266

    def get_particle_in(self, dir=E):
267
268
        if self.sim.get_coords_in_dir(self.coords, dir) in self.sim.get_particle_map_coords():
            return self.sim.get_particle_map_coords()[self.sim.get_coords_in_dir(self.coords, dir)]
Ahmad Reza's avatar
Ahmad Reza committed
269
270

    def get_location_in(self, dir=E):
271
272
        if self.sim.get_coords_in_dir(self.coords, dir) in self.sim.get_location_map_coords():
            return self.sim.get_location_map_coords()[self.sim.get_coords_in_dir(self.coords, dir)]
Ahmad Reza's avatar
Ahmad Reza committed
273

Ahmad Reza's avatar
Ahmad Reza committed
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308



    def write_to_with(self, matter, key=None, data=None):
        """
        Writes data with given a keyword directly on the matters (paricle, tile, or location object) memory

        :param matter: The matter can be either a particle, tile, or location
        :param key: A string keyword so to order the data that is written into the memory
        :param data: The data that should be stored into the memory
        :return: True: Successful written into the memory; False: Unsuccessful
        """
        wrote=False
        if data != None:
            wrote=False
            if key==None:
                wrote=matter.write_memory(data)
            else:
                wrote= matter.write_memory_with(key, data)
            if  wrote==True:
                if matter.type == "particle":
                    self.sim.csv_round_writer.update_metrics( particle_write=1)
                    self.csv_particle_writer.write_particle(particle_write=1)
                elif matter.type == "tile":
                    self.sim.csv_round_writer.update_metrics( tile_write=1)
                    self.csv_particle_writer.write_particle(tile_write=1)
                elif matter.type == "location":
                    self.sim.csv_round_writer.update_metrics( location_write=1)
                    self.csv_particle_writer.write_particle(location_write=1)
                return True
            else:
                return False
        else:
            return False

Ahmad Reza's avatar
Ahmad Reza committed
309
310
    def if_matter_in_dir(self, matter="tile", dir=E):
        if matter=="tile":
311
            return self.sim.get_coords_in_dir(self.coords, dir) in self.sim.get_tile_map_coords()
Ahmad Reza's avatar
Ahmad Reza committed
312
        if matter=="particle":
313
            return self.sim.get_coords_in_dir(self.coords, dir) in self.sim.get_particle_map_coords()
Ahmad Reza's avatar
Ahmad Reza committed
314
        if matter=="location":
315
            return self.sim.get_coords_in_dir(self.coords, dir) in self.sim.get_location_map_coords()
Ahmad Reza's avatar
Ahmad Reza committed
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359


    def scan_for_matter_within(self, matter='all', hop=1):
        """
        Scans for particles, tiles, or location on a given hop distance and all the matters within the hop distance

        :todo: If nothing then everything should be scanned

        :param matter: For what matter this method should scan for. Can be either particles, tiles, locations, or (default)all
        :param hop: The hop distance from the actual position of the scanning particle
        :return: A list of the founded matters
        """

        hop_list = []
        for i in range(1, hop + 1):
            list = self.scan_for_matter_in(matter, i)
            if list != None:
                hop_list.extend(list)
        if len(hop_list) != 0:
            return hop_list
        else:
            return None

    def scan_for_matter_in(self, matter='all', hop=1):
        """
        Scanning for particles, tiles, or location on a given hop distance

        :param matter: For what matter 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
        :return: A list of the founded matters
        """
        hop_list = []
        logging.info("particle on %s is scanning for %s in %i hops", str(self.coords), matter, hop)
        cnt = 0
        x_offset = 0
        y_up_scan = self.coords[1] + hop
        y_down_scan = self.coords[1] - hop
        while cnt < hop:
            x_scan_pos = self.coords[0] + hop - x_offset
            x_scan_neg = self.coords[0] - hop + x_offset
            y_scan_coord_neg = self.coords[1] - cnt
            y_scan_coord_pos = self.coords[1] + cnt
            if cnt == 0:
                if matter == "particles":
360
361
                    # if self.coords in self.sim.particle_map_coords:
                    #     hop_list.append(self.sim.particle_map_coords[self.coords])
362
363
364
365
                    if (x_scan_pos, y_scan_coord_neg) in self.sim.particle_map_coords:
                        hop_list.append(self.sim.particle_map_coords[(x_scan_pos, y_scan_coord_neg)])
                    if (x_scan_neg, y_scan_coord_neg) in self.sim.particle_map_coords:
                        hop_list.append(self.sim.particle_map_coords[(x_scan_neg, y_scan_coord_neg)])
Ahmad Reza's avatar
Ahmad Reza committed
366
                elif matter == "locations":
367
368
                    # if self.coords in self.sim.location_map_coords:
                    #     hop_list.append(self.sim.location_map_coords[self.coords])
369
370
371
372
                    if (x_scan_pos, y_scan_coord_neg) in self.sim.location_map_coords:
                        hop_list.append(self.sim.location_map_coords[(x_scan_pos, y_scan_coord_neg)])
                    if (x_scan_neg, y_scan_coord_neg) in self.sim.location_map_coords:
                        hop_list.append(self.sim.location_map_coords[(x_scan_neg, y_scan_coord_neg)])
Ahmad Reza's avatar
Ahmad Reza committed
373
                elif matter == "tiles":
374
375
                    # if self.coords in self.sim.tile_map_coords:
                    #     hop_list.append(self.sim.tile_map_coords[self.coords])
376
377
378
379
                    if (x_scan_pos, y_scan_coord_neg) in self.sim.tile_map_coords:
                        hop_list.append(self.sim.tile_map_coords[(x_scan_pos, y_scan_coord_neg)])
                    if (x_scan_neg, y_scan_coord_neg) in self.sim.tile_map_coords:
                        hop_list.append(self.sim.tile_map_coords[(x_scan_neg, y_scan_coord_neg)])
Ahmad Reza's avatar
Ahmad Reza committed
380
                elif matter == "all":
381
382
383
384
385
386
                    # if self.coords in self.sim.tile_map_coords:
                    #     hop_list.append(self.sim.tile_map_coords[self.coords])
                    # if self.coords in self.sim.location_map_coords:
                    #     hop_list.append(self.sim.location_map_coords[self.coords])
                    # if self.coords in self.sim.particle_map_coords:
                    #    hop_list.append(self.sim.particle_map_coords[self.coords])
387
388
389
390
391
392
393
394
395
396
397
398
                    if (x_scan_pos, y_scan_coord_neg) in self.sim.tile_map_coords:
                        hop_list.append(self.sim.tile_map_coords[(x_scan_pos, y_scan_coord_neg)])
                    if (x_scan_neg, y_scan_coord_neg) in self.sim.tile_map_coords:
                        hop_list.append(self.sim.tile_map_coords[(x_scan_neg, y_scan_coord_neg)])
                    if (x_scan_pos, y_scan_coord_neg) in self.sim.location_map_coords:
                        hop_list.append(self.sim.location_map_coords[(x_scan_pos, y_scan_coord_neg)])
                    if (x_scan_neg, y_scan_coord_neg) in self.sim.location_map_coords:
                        hop_list.append(self.sim.location_map_coords[(x_scan_neg, y_scan_coord_neg)])
                    if (x_scan_pos, y_scan_coord_neg) in self.sim.particle_map_coords:
                        hop_list.append(self.sim.particle_map_coords[(x_scan_pos, y_scan_coord_neg)])
                    if (x_scan_neg, y_scan_coord_neg) in self.sim.particle_map_coords:
                        hop_list.append(self.sim.particle_map_coords[(x_scan_neg, y_scan_coord_neg)])
Ahmad Reza's avatar
Ahmad Reza committed
399
400
401
402
                else:
                    logging.info("No matter specified")
            else:
                if matter == "particles":
403
404
405
406
407
408
409
410
                    if (x_scan_pos, y_scan_coord_pos) in self.sim.particle_map_coords:
                        hop_list.append(self.sim.particle_map_coords[(x_scan_pos, y_scan_coord_pos)])
                    if (x_scan_pos, y_scan_coord_neg) in self.sim.particle_map_coords:
                        hop_list.append(self.sim.particle_map_coords[(x_scan_pos, y_scan_coord_neg)])
                    if (x_scan_neg, y_scan_coord_pos) in self.sim.particle_map_coords:
                        hop_list.append(self.sim.particle_map_coords[(x_scan_neg, y_scan_coord_pos)])
                    if (x_scan_neg, y_scan_coord_neg) in self.sim.particle_map_coords:
                        hop_list.append(self.sim.particle_map_coords[(x_scan_neg, y_scan_coord_neg)])
Ahmad Reza's avatar
Ahmad Reza committed
411
                elif matter == "locations":
412
413
414
415
416
417
418
419
                    if (x_scan_pos, y_scan_coord_pos) in self.sim.location_map_coords:
                        hop_list.append(self.sim.location_map_coords[(x_scan_pos, y_scan_coord_pos)])
                    if (x_scan_pos, y_scan_coord_neg) in self.sim.location_map_coords:
                        hop_list.append(self.sim.location_map_coords[(x_scan_pos, y_scan_coord_neg)])
                    if (x_scan_neg, y_scan_coord_pos) in self.sim.location_map_coords:
                        hop_list.append(self.sim.location_map_coords[(x_scan_neg, y_scan_coord_pos)])
                    if (x_scan_neg, y_scan_coord_neg) in self.sim.location_map_coords:
                        hop_list.append(self.sim.location_map_coords[(x_scan_neg, y_scan_coord_neg)])
Ahmad Reza's avatar
Ahmad Reza committed
420
                elif matter == "tiles":
421
422
423
424
425
426
427
428
                    if (x_scan_pos, y_scan_coord_pos) in self.sim.tile_map_coords:
                        hop_list.append(self.sim.tile_map_coords[(x_scan_pos, y_scan_coord_pos)])
                    if (x_scan_pos, y_scan_coord_neg) in self.sim.tile_map_coords:
                        hop_list.append(self.sim.tile_map_coords[(x_scan_pos, y_scan_coord_neg)])
                    if (x_scan_pos, y_scan_coord_neg) in self.sim.tile_map_coords:
                        hop_list.append(self.sim.tile_map_coords[(x_scan_pos, y_scan_coord_neg)])
                    if (x_scan_neg, y_scan_coord_neg) in self.sim.tile_map_coords:
                        hop_list.append(self.sim.tile_map_coords[(x_scan_neg, y_scan_coord_neg)])
Ahmad Reza's avatar
Ahmad Reza committed
429
                elif matter == "all":
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
                    if (x_scan_pos, y_scan_coord_pos) in self.sim.particle_map_coords:
                        hop_list.append(self.sim.particle_map_coords[(x_scan_pos, y_scan_coord_pos)])
                    if (x_scan_pos, y_scan_coord_neg) in self.sim.particle_map_coords:
                        hop_list.append(self.sim.particle_map_coords[(x_scan_pos, y_scan_coord_neg)])
                    if (x_scan_neg, y_scan_coord_pos) in self.sim.particle_map_coords:
                        hop_list.append(self.sim.particle_map_coords[(x_scan_neg, y_scan_coord_pos)])
                    if (x_scan_neg, y_scan_coord_neg) in self.sim.particle_map_coords:
                        hop_list.append(self.sim.particle_map_coords[(x_scan_neg, y_scan_coord_neg)])

                    if (x_scan_pos, y_scan_coord_pos) in self.sim.location_map_coords:
                        hop_list.append(self.sim.location_map_coords[(x_scan_pos, y_scan_coord_pos)])
                    if (x_scan_pos, y_scan_coord_neg) in self.sim.location_map_coords:
                        hop_list.append(self.sim.location_map_coords[(x_scan_pos, y_scan_coord_neg)])
                    if (x_scan_neg, y_scan_coord_pos) in self.sim.location_map_coords:
                        hop_list.append(self.sim.location_map_coords[(x_scan_neg, y_scan_coord_pos)])
                    if (x_scan_neg, y_scan_coord_neg) in self.sim.location_map_coords:
                        hop_list.append(self.sim.location_map_coords[(x_scan_neg, y_scan_coord_neg)])

                    if (x_scan_pos, y_scan_coord_pos) in self.sim.tile_map_coords:
                        hop_list.append(self.sim.tile_map_coords[(x_scan_pos, y_scan_coord_pos)])
                    if (x_scan_pos, y_scan_coord_neg) in self.sim.tile_map_coords:
                        hop_list.append(self.sim.tile_map_coords[(x_scan_pos, y_scan_coord_neg)])
                    if (x_scan_pos, y_scan_coord_neg) in self.sim.tile_map_coords:
                        hop_list.append(self.sim.tile_map_coords[(x_scan_pos, y_scan_coord_neg)])
                    if (x_scan_neg, y_scan_coord_neg) in self.sim.tile_map_coords:
                        hop_list.append(self.sim.tile_map_coords[(x_scan_neg, y_scan_coord_neg)])
Ahmad Reza's avatar
Ahmad Reza committed
456
457
458
459
460
461
462
463
464
465
466
467

                else:
                    logging.info("No matter specified")
            cnt += 1
            x_offset += 0.5

        cnt = 0
        x_upper_scan = self.coords[0] + hop / 2
        offset_x = 0
        while cnt < hop + 1:
            x_upper_scan = x_upper_scan - offset_x
            if matter == "particles":
468
469
470
471
                if (x_upper_scan, y_up_scan) in self.sim.particle_map_coords:
                    hop_list.append(self.sim.particle_map_coords[(x_upper_scan, y_up_scan)])
                if (x_upper_scan, y_down_scan) in self.sim.particle_map_coords:
                    hop_list.append(self.sim.particle_map_coords[(x_upper_scan, y_down_scan)])
Ahmad Reza's avatar
Ahmad Reza committed
472
            elif matter == "locations":
473
474
475
476
                if (x_upper_scan, y_up_scan) in self.sim.location_map_coords:
                    hop_list.append(self.sim.location_map_coords[(x_upper_scan, y_up_scan)])
                if (x_upper_scan, y_down_scan) in self.sim.location_map_coords:
                    hop_list.append(self.sim.location_map_coords[(x_upper_scan, y_down_scan)])
Ahmad Reza's avatar
Ahmad Reza committed
477
            elif matter == "tiles":
478
479
480
481
                if (x_upper_scan, y_up_scan) in self.sim.tile_map_coords:
                    hop_list.append(self.sim.tile_map_coords[(x_upper_scan, y_up_scan)])
                if (x_upper_scan, y_down_scan) in self.sim.tile_map_coords:
                    hop_list.append(self.sim.tile_map_coords[(x_upper_scan, y_down_scan)])
Ahmad Reza's avatar
Ahmad Reza committed
482
483
            if matter == "all":
                if hop == 0:
484
485
486
487
488
489
                    if (0, 0) in self.sim.particle_map_coords:
                        hop_list.append(self.sim.particle_map_coords[(0, 0)])
                    if (0, 0) in self.sim.location_map_coords:
                        hop_list.append(self.sim.location_map_coords[(0, 0)])
                    if (0, 0) in self.sim.tile_map_coords:
                        hop_list.append(self.sim.tile_map_coords[(0, 0)])
Ahmad Reza's avatar
Ahmad Reza committed
490
491

                else:
492
493
494
495
                    if (x_upper_scan, y_up_scan) in self.sim.particle_map_coords:
                        hop_list.append(self.sim.particle_map_coords[(x_upper_scan, y_up_scan)])
                    if (x_upper_scan, y_down_scan) in self.sim.particle_map_coords:
                        hop_list.append(self.sim.particle_map_coords[(x_upper_scan, y_down_scan)])
Ahmad Reza's avatar
Ahmad Reza committed
496

497
498
499
500
                    if (x_upper_scan, y_up_scan) in self.sim.location_map_coords:
                        hop_list.append(self.sim.location_map_coords[(x_upper_scan, y_up_scan)])
                    if (x_upper_scan, y_down_scan) in self.sim.location_map_coords:
                        hop_list.append(self.sim.location_map_coords[(x_upper_scan, y_down_scan)])
Ahmad Reza's avatar
Ahmad Reza committed
501

502
503
504
505
                    if (x_upper_scan, y_up_scan) in self.sim.tile_map_coords:
                        hop_list.append(self.sim.tile_map_coords[(x_upper_scan, y_up_scan)])
                    if (x_upper_scan, y_down_scan) in self.sim.tile_map_coords:
                        hop_list.append(self.sim.tile_map_coords[(x_upper_scan, y_down_scan)])
Ahmad Reza's avatar
Ahmad Reza committed
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560

            else:
                logging.info("No matter specified")
            cnt += 1
            offset_x = 1
        if len(hop_list) > 0:
            logging.info("Got %s in %s hops", str(len(hop_list)), str(hop))
            return hop_list
        else:
            logging.info("Nothing in %s hops", str(hop))
            return None



    def scan_for_particle_within(self, hop=1):
        """
        Scans for particles, tiles, or location on a given hop distance and all the matters within the hop distance

        :todo: If nothing then everything should be scanned

        :param matter: For what matter this method should scan for. Can be either particles, tiles, locations, or (default)all
        :param hop: The hop distance from the actual position of the scanning particle
        :return: A list of the founded matters
        """

        hop_list = []
        for i in range(1, hop + 1):
            list = self.scan_for_particle_in( i)
            if list != None:
                hop_list.extend(list)
        if len(hop_list) != 0:
            return hop_list
        else:
            return None

    def scan_for_particle_in(self, hop=1):
        """
        Scanning for particles, tiles, or location on a given hop distance

        :param matter: For what matter 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
        :return: A list of the founded matters
        """
        hop_list = []
        logging.info("particle on %s is scanning for particle in %i hops", str(self.coords), hop)
        cnt = 0
        x_offset = 0
        y_up_scan = self.coords[1] + hop
        y_down_scan = self.coords[1] - hop
        while cnt < hop:
            x_scan_pos = self.coords[0] + hop - x_offset
            x_scan_neg = self.coords[0] - hop + x_offset
            y_scan_coord_neg = self.coords[1] - cnt
            y_scan_coord_pos = self.coords[1] + cnt
            if cnt == 0:
561
562
563
564
565
566
                # if self.coords in self.sim.particle_map_coords:
                #     hop_list.append(self.sim.particle_map_coords[self.coords])
                if (x_scan_pos, y_scan_coord_neg) in self.sim.particle_map_coords:
                    hop_list.append(self.sim.particle_map_coords[(x_scan_pos, y_scan_coord_neg)])
                if (x_scan_neg, y_scan_coord_neg) in self.sim.particle_map_coords:
                    hop_list.append(self.sim.particle_map_coords[(x_scan_neg, y_scan_coord_neg)])
Ahmad Reza's avatar
Ahmad Reza committed
567
            else:
568
569
570
571
572
573
574
575
                if (x_scan_pos, y_scan_coord_pos) in self.sim.particle_map_coords:
                    hop_list.append(self.sim.particle_map_coords[(x_scan_pos, y_scan_coord_pos)])
                if (x_scan_pos, y_scan_coord_neg) in self.sim.particle_map_coords:
                    hop_list.append(self.sim.particle_map_coords[(x_scan_pos, y_scan_coord_neg)])
                if (x_scan_neg, y_scan_coord_pos) in self.sim.particle_map_coords:
                    hop_list.append(self.sim.particle_map_coords[(x_scan_neg, y_scan_coord_pos)])
                if (x_scan_neg, y_scan_coord_neg) in self.sim.particle_map_coords:
                    hop_list.append(self.sim.particle_map_coords[(x_scan_neg, y_scan_coord_neg)])
Ahmad Reza's avatar
Ahmad Reza committed
576
577
578
579
580
581
582
583
            cnt += 1
            x_offset += 0.5

        cnt = 0
        x_upper_scan = self.coords[0] + hop / 2
        offset_x = 0
        while cnt < hop + 1:
            x_upper_scan = x_upper_scan - offset_x
584
585
586
587
            if (x_upper_scan, y_up_scan) in self.sim.particle_map_coords:
                hop_list.append(self.sim.particle_map_coords[(x_upper_scan, y_up_scan)])
            if (x_upper_scan, y_down_scan) in self.sim.particle_map_coords:
                hop_list.append(self.sim.particle_map_coords[(x_upper_scan, y_down_scan)])
Ahmad Reza's avatar
Ahmad Reza committed
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
            cnt += 1
            offset_x = 1
        if len(hop_list) > 0:
            logging.info("Got %s in %s hops", str(len(hop_list)), str(hop))
            return hop_list
        else:
            logging.info("Nothing in %s hops", str(hop))
            return None



    def scan_for_tile_within(self,  hop=1):
        """
        Scans for particles, tiles, or location on a given hop distance and all the matters within the hop distance

        :todo: If nothing then everything should be scanned

        :param matter: For what matter this method should scan for. Can be either particles, tiles, locations, or (default)all
        :param hop: The hop distance from the actual position of the scanning particle
        :return: A list of the founded matters
        """

        hop_list = []
        for i in range(1, hop + 1):
            list = self.scan_for_tile_in(i)
            if list != None:
                hop_list.extend(list)
        if len(hop_list) != 0:
            return hop_list
        else:
            return None

    def scan_for_tile_in(self, hop=1):
        """
        Scanning for particles, tiles, or location on a given hop distance

        :param matter: For what matter 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
        :return: A list of the founded matters
        """
        hop_list = []
        logging.info("particle on %s is scanning for tile in %i hops", str(self.coords), hop)
        cnt = 0
        x_offset = 0
        y_up_scan = self.coords[1] + hop
        y_down_scan = self.coords[1] - hop
        while cnt < hop:
            x_scan_pos = self.coords[0] + hop - x_offset
            x_scan_neg = self.coords[0] - hop + x_offset
            y_scan_coord_neg = self.coords[1] - cnt
            y_scan_coord_pos = self.coords[1] + cnt
            if cnt == 0:
640
641
642
643
644
645
                # if self.coords in self.sim.tile_map_coords:
                #     hop_list.append(self.sim.tile_map_coords[self.coords])
                if (x_scan_pos, y_scan_coord_neg) in self.sim.tile_map_coords:
                    hop_list.append(self.sim.tile_map_coords[(x_scan_pos, y_scan_coord_neg)])
                if (x_scan_neg, y_scan_coord_neg) in self.sim.tile_map_coords:
                    hop_list.append(self.sim.tile_map_coords[(x_scan_neg, y_scan_coord_neg)])
Ahmad Reza's avatar
Ahmad Reza committed
646
            else:
647
648
649
650
651
652
653
654
                if (x_scan_pos, y_scan_coord_pos) in self.sim.tile_map_coords:
                    hop_list.append(self.sim.tile_map_coords[(x_scan_pos, y_scan_coord_pos)])
                if (x_scan_pos, y_scan_coord_neg) in self.sim.tile_map_coords:
                    hop_list.append(self.sim.tile_map_coords[(x_scan_pos, y_scan_coord_neg)])
                if (x_scan_pos, y_scan_coord_neg) in self.sim.tile_map_coords:
                    hop_list.append(self.sim.tile_map_coords[(x_scan_pos, y_scan_coord_neg)])
                if (x_scan_neg, y_scan_coord_neg) in self.sim.tile_map_coords:
                    hop_list.append(self.sim.tile_map_coords[(x_scan_neg, y_scan_coord_neg)])
Ahmad Reza's avatar
Ahmad Reza committed
655
656
657
658
659
660
661
662
            cnt += 1
            x_offset += 0.5

        cnt = 0
        x_upper_scan = self.coords[0] + hop / 2
        offset_x = 0
        while cnt < hop + 1:
            x_upper_scan = x_upper_scan - offset_x
663
664
665
666
            if (x_upper_scan, y_up_scan) in self.sim.tile_map_coords:
                hop_list.append(self.sim.tile_map_coords[(x_upper_scan, y_up_scan)])
            if (x_upper_scan, y_down_scan) in self.sim.tile_map_coords:
                hop_list.append(self.sim.tile_map_coords[(x_upper_scan, y_down_scan)])
Ahmad Reza's avatar
Ahmad Reza committed
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
            cnt += 1
            offset_x = 1
        if len(hop_list) > 0:
            logging.info("Got %s in %s hops", str(len(hop_list)), str(hop))
            return hop_list
        else:
            logging.info("Nothing in %s hops", str(hop))
            return None


    def scan_for_location_within(self, hop=1):
        """
        Scans for particles, tiles, or location on a given hop distance and all the matters within the hop distance

        :todo: If nothing then everything should be scanned

        :param matter: For what matter this method should scan for. Can be either particles, tiles, locations, or (default)all
        :param hop: The hop distance from the actual position of the scanning particle
        :return: A list of the founded matters
        """

        hop_list = []
        for i in range(1, hop + 1):
            list = self.scan_for_location_in(i)
            if list != None:
                hop_list.extend(list)
        if len(hop_list) != 0:
            return hop_list
        else:
            return None

    def scan_for_location_in(self, hop=1):
        """
        Scanning for particles, tiles, or location on a given hop distance

        :param matter: For what matter 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
        :return: A list of the founded matters
        """
        hop_list = []
        logging.info("particle is scanning for location in %i hops", hop)
        cnt = 0
        x_offset = 0
        y_up_scan = self.coords[1] + hop
        y_down_scan = self.coords[1] - hop
        while cnt < hop:
            x_scan_pos = self.coords[0] + hop - x_offset
            x_scan_neg = self.coords[0] - hop + x_offset
            y_scan_coord_neg = self.coords[1] - cnt
            y_scan_coord_pos = self.coords[1] + cnt
            if cnt == 0:
718
719
720
721
722
723
                # if self.coords in self.sim.location_map_coords:
                #     hop_list.append(self.sim.location_map_coords[self.coords])
                if (x_scan_pos, y_scan_coord_neg) in self.sim.location_map_coords:
                    hop_list.append(self.sim.location_map_coords[(x_scan_pos, y_scan_coord_neg)])
                if (x_scan_neg, y_scan_coord_neg) in self.sim.location_map_coords:
                    hop_list.append(self.sim.location_map_coords[(x_scan_neg, y_scan_coord_neg)])
Ahmad Reza's avatar
Ahmad Reza committed
724
725
            else:

726
727
728
729
730
731
732
733
                if (x_scan_pos, y_scan_coord_pos) in self.sim.location_map_coords:
                    hop_list.append(self.sim.location_map_coords[(x_scan_pos, y_scan_coord_pos)])
                if (x_scan_pos, y_scan_coord_neg) in self.sim.location_map_coords:
                    hop_list.append(self.sim.location_map_coords[(x_scan_pos, y_scan_coord_neg)])
                if (x_scan_neg, y_scan_coord_pos) in self.sim.location_map_coords:
                    hop_list.append(self.sim.location_map_coords[(x_scan_neg, y_scan_coord_pos)])
                if (x_scan_neg, y_scan_coord_neg) in self.sim.location_map_coords:
                    hop_list.append(self.sim.location_map_coords[(x_scan_neg, y_scan_coord_neg)])
Ahmad Reza's avatar
Ahmad Reza committed
734
735
736
737
738
739
740
741
            cnt += 1
            x_offset += 0.5

        cnt = 0
        x_upper_scan = self.coords[0] + hop / 2
        offset_x = 0
        while cnt < hop + 1:
            x_upper_scan = x_upper_scan - offset_x
742
743
744
745
            if (x_upper_scan, y_up_scan) in self.sim.location_map_coords:
                hop_list.append(self.sim.location_map_coords[(x_upper_scan, y_up_scan)])
            if (x_upper_scan, y_down_scan) in self.sim.location_map_coords:
                hop_list.append(self.sim.location_map_coords[(x_upper_scan, y_down_scan)])
Ahmad Reza's avatar
Ahmad Reza committed
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
            cnt += 1
            offset_x = 1
        if len(hop_list) > 0:
            logging.info("Got %s in %s hops", str(len(hop_list)), str(hop))
            return hop_list
        else:
            logging.info("Nothing in %s hops", str(hop))
            return None



    def take_me(self, coords=0):
        """
        The particle is getting taken from the the other particle on the given coordinate

        :param coords: Coordination of particle that should be taken
        :return: True: Successful taken; False: Cannot be taken or wrong Coordinates
        """

        if not self.__isCarried:
766
767
            if self.coords in self.sim.particle_map_coords:
                del self.sim.particle_map_coords[self.coords]
Ahmad Reza's avatar
Ahmad Reza committed
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
            self.__isCarried = True
            self.coords = coords
            self.touch()
            return True
        else:
            return False


    def drop_me(self, coords):
        """
        The actual particle is getting dropped

        :param coords: the given position
        :return: None
        """
783
        self.sim.particle_map_coords[coords] = self
Ahmad Reza's avatar
Ahmad Reza committed
784
785
786
787
788
789
790
791
792
793
        self.coords = coords
        self.__isCarried = False
        self.touch()



    def create_tile(self, color=gray, alpha=1):
        """
        Creates a tile on the particles actual position

Ahmad Reza's avatar
Ahmad Reza committed
794
        :return: New Tile or False
Ahmad Reza's avatar
Ahmad Reza committed
795
796
        """
        logging.info("Going to create a tile on position %s", str(self.coords))
Ahmad Reza's avatar
Ahmad Reza committed
797
798
799
800
801
802
803
804
805
        new_tile = self.sim.add_tile(self.coords[0], self.coords[1], color, alpha)
        if new_tile:
            self.sim.tile_map_coords[self.coords[0], self.coords[1]].created = True
            self.csv_particle_writer.write_particle(tile_created=1)
            self.sim.csv_round_writer.update_tiles_num(len(self.sim.get_tiles_list()))
            self.sim.csv_round_writer.update_metrics( tile_created=1)
            return new_tile
        else:
            return False
Ahmad Reza's avatar
Ahmad Reza committed
806
807
808
809
810
811

    def create_tile_in(self, dir=None, color=gray, alpha=1):
        """
        Creates a tile either in a given direction

        :param dir: The direction on which the tile should be created. Options: E, SE, SW, W, NW, NE,
Ahmad Reza's avatar
Ahmad Reza committed
812
        :return: New tile or False
Ahmad Reza's avatar
Ahmad Reza committed
813
814
815
816
        """
        logging.info("particle with id %s is", self.get_id())
        logging.info("Going to create a tile in %s ", str(dir) )
        if dir != None:
817
            coords = self.sim.get_coords_in_dir(self.coords, dir)
Ahmad Reza's avatar
Ahmad Reza committed
818
819
            new_tile = self.sim.add_tile(coords[0], coords[1], color, alpha)
            if new_tile:
820
                self.sim.tile_map_coords[coords[0], coords[1]].created = True
Ahmad Reza's avatar
Ahmad Reza committed
821
                logging.info("Tile is created")
822
                self.sim.new_tile_flag = True
Ahmad Reza's avatar
Ahmad Reza committed
823
                self.csv_particle_writer.write_particle(tile_created=1)
824
825
                self.sim.csv_round_writer.update_tiles_num(len(self.sim.get_tiles_list()))
                self.sim.csv_round_writer.update_metrics( tile_created=1)
Ahmad Reza's avatar
Ahmad Reza committed
826
827
828
                return new_tile
            else:
                return False
Ahmad Reza's avatar
Ahmad Reza committed
829
830
        else:
            logging.info("Not created tile ")
Ahmad Reza's avatar
Ahmad Reza committed
831
            return False
Ahmad Reza's avatar
Ahmad Reza committed
832
833
834
835
836
837
838

    def create_tile_on(self, x=None, y=None, color=gray, alpha=1):
        """
        Creates a tile either on a given x,y coordinates

        :param x: x coordinate
        :param y: y coordinate
Ahmad Reza's avatar
Ahmad Reza committed
839
        :return: New Tile or False
Ahmad Reza's avatar
Ahmad Reza committed
840
841
842
843
844
        """

        logging.info("particle with id %s is", self.get_id())
        if x is not None and y is not None:
            coords = (x, y)
845
            if self.sim.check_coords(x,y):
Ahmad Reza's avatar
Ahmad Reza committed
846
                logging.info("Going to create a tile on position \(%i , %i\)", x,y )
847
848
849
                if self.sim.add_tile(coords[0], coords[1], color, alpha) == True:
                    self.sim.tile_map_coords[coords[0], coords[1]].created = True
                    self.sim.new_tile_flag = True
Ahmad Reza's avatar
Ahmad Reza committed
850
                    self.csv_particle_writer.write_particle(tile_created=1)
851
852
                    self.sim.csv_round_writer.update_tiles_num(len(self.sim.get_tiles_list()) )
                    self.sim.csv_round_writer.update_metrics( tile_created=1)
Ahmad Reza's avatar
Ahmad Reza committed
853
854
855
856
857
858
                    return True
                else:
                    logging.info("Not created tile on coords  \(%i , %i\)", y,x )
                    return False
            else:
                logging.info("Not created tile on coords   \(%i , %i\)", y,x )
Ahmad Reza's avatar
Ahmad Reza committed
859
                return False
Ahmad Reza's avatar
Ahmad Reza committed
860
861
862
863
864
865
866
867
868

    def delete_tile(self):
        """
        Deletes a tile on current position

        :return: True: Deleting successful; False: Deleting unsuccessful
        """
        logging.info("Particle %s is", self.get_id())
        logging.info("is going to delete a tile on current position")
869
870
        if self.coords in self.sim.get_tile_map_coords():
            if self.sim.remove_tile_on(self.coords):
Ahmad Reza's avatar
Ahmad Reza committed
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
                self.csv_particle_writer.write_particle(tile_deleted=1)
                return True
        else:
            logging.info("Could not delet tile")
            return False

    def delete_tile_with(self, id):
        """
        Deletes a tile with a given tile-id

        :param tile_id: The id of the tile that should be deleted
        :return: True: Deleting successful; False: Deleting unsuccessful
        """
        logging.info("Particle %s is", self.get_id())
        logging.info("is going to delete a tile with tile id %s", str(id))
886
        if self.sim.remove_tile(id):
Ahmad Reza's avatar
Ahmad Reza committed
887
888
889
890
891
892
            self.csv_particle_writer.write_particle(tile_deleted=1)
            return True
        else:
            logging.info("Could not delet tile with tile id %s", str(id))
            return False

Ahmad Reza's avatar
Ahmad Reza committed
893
    def delete_tile_in(self, dir=None):
Ahmad Reza's avatar
Ahmad Reza committed
894
895
896
897
898
899
900
901
        """
        Deletes a tile either in a given direction

        :param dir: The direction on which the tile should be deleted. Options: E, SE, SW, W, NW, NE,

        :return: True: Deleting successful; False: Deleting unsuccessful
        """
        coords = ()
Ahmad Reza's avatar
Ahmad Reza committed
902
        if dir is not None:
903
            coords = self.sim.get_coords_in_dir(self.coords, dir)
Ahmad Reza's avatar
Ahmad Reza committed
904
905
            logging.info("Deleting tile in %s direction", str(dir))
            if coords is not None:
906
                if self.sim.remove_tile_on(coords):
Ahmad Reza's avatar
Ahmad Reza committed
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
                    logging.info("Deleted tile with tile on coords %s", str(coords))
                    self.csv_particle_writer.write_particle(tile_deleted=1)
                    return True
                else:
                    logging.info("Could not delet tile on coords %s", str(coords))
                    return False
        else:
            logging.info("Could not delet tile on coords %s", str(coords))
            return False

    def delete_tile_on(self, x=None, y=None):
        """
        Deletes a tile either on a given x,y coordinates
,
        :param x: x coordinate
        :param y: y coordinate
        :return: True: Deleting successful; False: Deleting unsuccessful
        """
        coords = ()
        if x is not None and y is not None:
            coords = (x, y)
928
            if self.sim.remove_tile_on(coords):
Ahmad Reza's avatar
Ahmad Reza committed
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
                logging.info("Deleted tile with tile on coords %s", str(coords))
                self.csv_particle_writer.write_particle(tile_deleted=1)
                return True
            else:
                logging.info("Could not delet tile on coords %s", str(coords))
                return False
        else:
            logging.info("Could not delet tile on coords %s", str(coords))
            return False


    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:
948
949
            if self.coords in self.sim.tile_map_coords:
                self.carried_tile = self.sim.tile_map_coords[self.coords]
Ahmad Reza's avatar
Ahmad Reza committed
950
951
                if self.carried_tile.take(coords=self.coords):
                    logging.info("Tile has been taken")
952
                    self.sim.csv_round_writer.update_metrics( tiles_taken=1)
Ahmad Reza's avatar
Ahmad Reza committed
953
954
955
956
957
958
                    self.csv_particle_writer.write_particle(tiles_taken=1)
                    return True
                else:
                    logging.info("Tile could not be taken")
                    return False
            else:
959
                logging.info("No tile on the actual position not in the sim")
Ahmad Reza's avatar
Ahmad Reza committed
960
961
962
963
964
965
966
967
968
969
970
971
972
973
                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 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:
974
975
976
            if id in self.sim.tile_map_id:
                logging.info("Tile with tile id %s is in the sim", str(id))
                self.carried_tile = self.sim.tile_map_id[id]
Ahmad Reza's avatar
Ahmad Reza committed
977
978
                if self.carried_tile.take(coords=self.coords):
                    logging.info("Tile with tile id %s  has been taken", str(id))
979
                    self.sim.csv_round_writer.update_metrics( tiles_taken=1)
Ahmad Reza's avatar
Ahmad Reza committed
980
981
982
983
984
985
                    self.csv_particle_writer.write_particle(tiles_taken=1)
                    return True
                else:
                    logging.info("Tile with tile id %s could not be taken", str(id))
                    return False
            else:
986
                logging.info("Tile with tile id %s is not in the sim", str(id))
Ahmad Reza's avatar
Ahmad Reza committed
987
988
989
990
991
992
993
994
995
996
997
998
999
                return False
        else:
            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):
        """
        Takes a tile that is in a given direction

        :param dir: The direction on which the tile should be taken. Options: E, SE, SW, W, NW, NE,
        :return: True: successful taken; False: unsuccessful taken
        """
        if self.carried_particle is None and self.carried_tile is None:
1000
1001
1002
1003
            coords = self.sim.get_coords_in_dir(self.coords, dir)
            if coords in self.sim.tile_map_coords:
                self.carried_tile = self.sim.tile_map_coords[coords]
                logging.info("Tile with tile id %s is in the sim", str(self.carried_tile.get_id()))
Ahmad Reza's avatar
Ahmad Reza committed
1004
1005
                if self.carried_tile.take(coords=self.coords):
                    logging.info("Tile with tile id %s  has been taken", str(self.carried_tile.get_id()))
1006
                    self.sim.csv_round_writer.update_metrics( tiles_taken=1)
Ahmad Reza's avatar
Ahmad Reza committed
1007
1008
1009
1010
1011
1012
                    self.csv_particle_writer.write_particle(tiles_taken=1)
                    return True
                else:
                    logging.info("Tile with tile id %s could not be taken", str(self.carried_tile.get_id()))
                    return False
            else:
1013
                logging.info("Tile is not in the sim")
Ahmad Reza's avatar
Ahmad Reza committed
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
                return False
        else:
            logging.info("Tile cannot taken because particle is carrieng either a tile or a particle")
            return False

    def take_tile_on(self, x=None, y=None):
        """
        Takes a tile that is in a given direction

        :param x: x coordinate
        :param y: y coordinate
        :return: True: successful taken; False: unsuccessful taken
        """
        if self.carried_particle is None and self.carried_tile is None:
1028
            if self.sim.check_coords(x, y):
Ahmad Reza's avatar
Ahmad Reza committed
1029
                coords = (x, y)
1030
1031
1032
                if coords in self.sim.tile_map_coords:
                    self.carried_tile = self.sim.tile_map_coords[coords]
                    logging.info("Tile with tile id %s is in the sim", str(self.carried_tile.get_id()))
Ahmad Reza's avatar
Ahmad Reza committed
1033
                    if self.carried_tile.take(coords=self.coords):
1034
                        self.sim.csv_round_writer.update_metrics( tiles_taken=1)
Ahmad Reza's avatar
Ahmad Reza committed
1035
1036
1037
1038
1039
1040
1041
                        self.csv_particle_writer.write_particle(tiles_taken=1)
                        logging.info("Tile with tile id %s  has been taken", str(self.carried_tile.get_id()))
                        return True
                    else:
                        logging.info("Tile with tile id %s could not be taken", str(self.carried_tile.get_id()))
                        return False
                else:
1042
                    logging.info("Tile is not in the sim")
Ahmad Reza's avatar
Ahmad Reza committed
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
                    return False
            else:
                logging.info("Coordinates are wrong")
                return False
        else:
            logging.info("Tile cannot taken because particle is carrieng either a tile or a particle")
            return False

    def drop_tile(self):
        """
        Drops the taken tile on the particles actual position

        :return: None
        """
        if self.carried_tile is not None:
1058
            if self.coords not in self.sim.tile_map_coords:
Ahmad Reza's avatar
Ahmad Reza committed
1059
1060
1061
1062
1063
1064
                try:  # cher: insert so to overcome the AttributeError
                    self.carried_tile.drop_me(self.coords)
                except AttributeError:
                    pass
                self.carried_tile = None
                logging.info("Tile has been dropped on the actual position")
1065
                self.sim.csv_round_writer.update_metrics( tiles_dropped=1)
Ahmad Reza's avatar
Ahmad Reza committed
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
                self.csv_particle_writer.write_particle(tiles_dropped=1)
                return True
            else:
                logging.info("Is not possible to drop the tile on that position because it is occupied")
                return False
        else:
            return False

    def drop_tile_in(self, dir):
        """
        Drops the taken tile on a given direction

         :param dir: The direction on which the tile should be dropped. Options: E, SE, SW, W, NW, NE,
        """
        if self.carried_tile is not None:
1081
1082
            coords = self.sim.get_coords_in_dir(self.coords, dir)
            if coords not in self.sim.tile_map_coords:
Ahmad Reza's avatar
Ahmad Reza committed
1083
1084
1085
1086
1087
                try:  # cher: insert so to overcome the AttributeError
                    self.carried_tile.drop_me(coords)
                except AttributeError:
                    pass
                self.carried_tile = None
1088
                self.sim.csv_round_writer.update_metrics( tiles_dropped=1)
Ahmad Reza's avatar
Ahmad Reza committed
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
                self.csv_particle_writer.write_particle(tiles_dropped=1)
                logging.info("Dropped tile on %s coordinate", str(coords))
                return True
            else:
                logging.info("Is not possible to drop the tile on that position")
                return False

        else:
            logging.info("No tile taken for dropping")
            return False

    def drop_tile_on(self, x=None, y=None):
        """
        Drops the taken tile on a given direction

        :param x: x coordinate
        :param y: y coordinate
        """
        if self.carried_tile is not None:
1108
            if self.sim.check_coords(x, y):
Ahmad Reza's avatar
Ahmad Reza committed
1109
                coords = (x, y)
1110
                if coords not in self.sim.get_tile_map_coords():
Ahmad Reza's avatar
Ahmad Reza committed
1111
1112
1113
1114
1115
                    try:  # cher: insert so to overcome the AttributeError
                        self.carried_tile.drop_me(coords)
                    except AttributeError:
                        pass
                    self.carried_tile = None
1116
                    self.sim.csv_round_writer.update_metrics( tiles_dropped=1)
Ahmad Reza's avatar
Ahmad Reza committed
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
                    self.csv_particle_writer.write_particle(tiles_dropped=1)
                    logging.info("Dropped tile on %s coordinate", str(coords))
                    return True
                else:
                    logging.info("Is not possible to drop the tile on that position because it is occupied")
                    return False
            else:
                logging.info("Wrong coordinates for dropping the tile")
                return False
        else:
            logging.info("No tile is taken for dropping")
            return False

    def create_particle(self, color=black, alpha=1):
        """
        Creates a particle on the particles actual position

Ahmad Reza's avatar
Ahmad Reza committed
1134
        :return: New Particle or False
Ahmad Reza's avatar
Ahmad Reza committed
1135
1136
        """
        logging.info("Going to create on position %s", str(self.coords))
Ahmad Reza's avatar
Ahmad Reza committed
1137
1138
1139
1140
1141
1142
1143
1144
1145
        new_particle = self.sim.add_particle(self.coords[0], self.coords[1], color, alpha)
        if new_particle:
            self.sim.particle_map_coords[self.coords[0], self.coords[1]].created=True
            self.csv_particle_writer.write_particle(particle_created=1)
            self.sim.csv_round_writer.update_particle_num(len(self.sim.get_particle_list()))
            self.sim.csv_round_writer.update_metrics( particle_created=1)
            return new_particle
        else:
            return False
Ahmad Reza's avatar
Ahmad Reza committed
1146
1147
1148
1149
1150
1151
1152
1153

    def create_particle_in(self, dir=None, color=black, alpha=1):
        """
        Creates a particle either in a given direction

        :toDo: seperate the direction and coordinates and delete state

        :param dir: The direction on which the particle should be created. Options: E, SE, SW, W, NW, NE,
Ahmad Reza's avatar
Ahmad Reza committed
1154
        :return: New Particle or False
Ahmad Reza's avatar
Ahmad Reza committed
1155
1156
1157
        """
        coords = (0, 0)
        if dir is not None:
1158
            coords = self.sim.get_coords_in_dir(self.coords, dir)
Ahmad Reza's avatar
Ahmad Reza committed
1159
            logging.info("Going to create a particle in %s on position %s", str(dir), str(coords))
Ahmad Reza's avatar
Ahmad Reza committed
1160
1161
            new_particle= self.sim.add_particle(coords[0], coords[1], color, alpha)
            if new_particle:
1162
                self.sim.particle_map_coords[coords[0], coords[1]].created = True
Ahmad Reza's avatar
Ahmad Reza committed
1163
                logging.info("Created particle on coords %s", coords)
1164
1165
                self.sim.csv_round_writer.update_particle_num(len(self.sim.get_particle_list()))
                self.sim.csv_round_writer.update_metrics( particle_created=1)
Ahmad Reza's avatar
Ahmad Reza committed
1166
                self.csv_particle_writer.write_particle(particle_created=1)
Ahmad Reza's avatar
Ahmad Reza committed
1167
1168
1169
                return new_particle
            else:
                return False
Ahmad Reza's avatar
Ahmad Reza committed
1170
1171
        else:
            logging.info("Not created particle on coords %s", str(coords))
Ahmad Reza's avatar
Ahmad Reza committed
1172
            return False
Ahmad Reza's avatar
Ahmad Reza committed
1173
1174
1175
1176
1177
1178
1179
1180
1181

    def create_particle_on(self, x=None, y=None, color=black, alpha=1):
        """
        Creates a particle either on a given x,y coordinates

        :toDo: seperate the direction and coordinates and delete state

        :param x: x coordinate
        :param y: y coordinate
Ahmad Reza's avatar
Ahmad Reza committed
1182
        :return: New Particle or False
Ahmad Reza's avatar
Ahmad Reza committed
1183
1184
1185
        """
        coords = (0, 0)
        if x is not None and y is not None:
1186
            if self.sim.check_coords(x, y):
Ahmad Reza's avatar
Ahmad Reza committed
1187
1188
                coords = (x, y)
                logging.info("Going to create a particle on position %s", str(coords))
Ahmad Reza's avatar
Ahmad Reza committed
1189
1190
                new_particle = self.sim.add_particle(coords[0], coords[1], color, alpha)
                if new_particle:
1191
                    self.sim.particle_map_coords[coords[0], coords[1]].created = True
Ahmad Reza's avatar
Ahmad Reza committed
1192
                    logging.info("Created particle on coords %s", str(coords))
1193
1194
                    self.sim.csv_round_writer.update_particle_num(len(self.sim.get_particle_list()))
                    self.sim.csv_round_writer.update_metrics( particle_created=1)
Ahmad Reza's avatar
Ahmad Reza committed
1195
                    self.csv_particle_writer.write_particle(particle_created=1)
Ahmad Reza's avatar
Ahmad Reza committed
1196
                    return new_particle
Ahmad Reza's avatar
Ahmad Reza committed
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
                else:
                    return False
            else:
                return False
        else:
            logging.info("Not created particle on coords %s", str(coords))
            return False

    def delete_particle(self):
        """
        Deletes a tile on current position

        :return: True: Deleting successful; False: Deleting unsuccessful
        """
        logging.info("Particle %s is", self.get_id())
        logging.info("is going to delete a particle on current position")
1213
1214
        if self.coords in self.sim.get_particle_map_coords():
            if self.sim.remove_particle_on(self.coords):
Ahmad Reza's avatar
Ahmad Reza committed
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
                self.csv_particle_writer.write_particle(particle_deleted=1)
                return True
        else:
            logging.info("Could not delet particle")
            return False

    def delete_particle_with(self, id):
        """
        Deletes a particle with a given id

        :param id: The id of the particle that should be deleted
        :return: True: Deleting successful; False: Deleting unsuccessful
        """
        logging.info("Particle %s is", self.get_id())
        logging.info("is going to delete a particle with id %s", str(id))
1230
        if self.sim.remove_particle(id):
Ahmad Reza's avatar
Ahmad Reza committed
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
            self.csv_particle_writer.write_particle(particle_deleted=1)
            return
        else:
            logging.info("Could not delet particle with particle id %s", str(id))

    def delete_particle_in(self, dir=None):
        """
        Deletes a particle either in a given direction

        :param dir: The direction on which the particle should be deleted. Options: E, SE, SW, W, NW, NE,
        :return: True: Deleting successful; False: Deleting unsuccessful
        """
Ahmad Reza's avatar
Ahmad Reza committed
1243
        if dir is not None:
1244
            coords = self.sim.get_coords_in_dir(self.coords, dir)
Ahmad Reza's avatar
Ahmad Reza committed
1245
            logging.info("Deleting tile in %s direction", str(dir))
Ahmad Reza's avatar
Ahmad Reza committed
1246
1247
1248
1249
1250
            if self.sim.remove_particle_on(coords):
                logging.info("Deleted particle with particle on coords %s", str(coords))
                self.csv_particle_writer.write_particle(particle_deleted=1)
            else:
                logging.info("Could not delet particle on coords %s", str(coords))
Ahmad Reza's avatar
Ahmad Reza committed
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260

    def delete_particle_on(self, x=None, y=None):
        """
        Deletes a particle either on a given x,y coordinates

        :param x: x coordinate
        :param y: y coordinate
        :return: True: Deleting successful; False: Deleting unsuccessful
        """
        if x is not None and y is not None:
1261
            if self.sim.check_coords(x, y):
Ahmad Reza's avatar
Ahmad Reza committed
1262
                coords = (x, y)
1263
                if self.sim.remove_particle_on(coords):
Ahmad Reza's avatar
Ahmad Reza committed
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
                    logging.info("Deleted particle with particle on coords %s", str(coords))
                    self.csv_particle_writer.write_particle(particle_deleted=1)
                    return True
                else:
                    logging.info("Could not delet particle on coords %s", str(coords))
                    return False
            else:
                return False
        else:
            return False

    def take_particle(self):
        """
        Takes a particle on the actual position

        :return: True: successful taken; False: unsuccessful taken
        """
        if self.carried_particle is None and self.carried_tile is None:
1282
1283
            if self.coords in self.sim.particle_map_coords:
                self.carried_particle = self.sim.particle_map_coords[self.coords]
Ahmad Reza's avatar
Ahmad Reza committed
1284
1285
                if self.carried_particle.take_me(coords=self.coords):
                    logging.info("particle has been taken")
1286
                    self.sim.csv_round_writer.update_metrics( particles_taken=1)
Ahmad Reza's avatar
Ahmad Reza committed
1287
1288
1289
1290
1291
1292
                    self.csv_particle_writer.write_particle(particles_taken=1)
                    return True
                else:
                    logging.info("particle could not be taken")
                    return False
            else:
1293
                logging.info("No particle on the actual position not in the sim")
Ahmad Reza's avatar
Ahmad Reza committed
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
                return False
        else:
            logging.info("particle cannot taken because particle is carrieng either a particle or a particle")
            return False

    def take_particle_with(self, id):
        """
        Takes a particle with a given tile id

        :param id:  The id of the particle that should be taken
        :return: True: successful taken; False: unsuccessful taken
        """
        if self.carried_tile is None and self.carried_particle is None:
1307
            if id in self.sim.get_particle_map_id():
1308
1309
                logging.info("particle with particle id %s is in the sim", str(id))
                self.carried_particle = self.sim.particle_map_id[id]
Ahmad Reza's avatar
Ahmad Reza committed
1310
1311
1312
                if self.carried_particle.take_me(self.coords):
                    logging.info("particle with particle id %s  has been taken", str(id))

1313
                    self.sim.csv_round_writer.update_metrics(
Ahmad Reza's avatar
Ahmad Reza committed
1314
1315
1316
1317
1318
1319
1320
                                                               particles_taken=1)
                    self.csv_particle_writer.write_particle(particles_taken=1)
                    return True
                else:
                    logging.info("particle with particle id %s could not be taken", str(id))
                    return False
            else:
1321
                logging.info("particle with particle id %s is not in the sim", str(id))
Ahmad Reza's avatar
Ahmad Reza committed
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
        else:
            logging.info("particle cannot taken because particle is carrieng either a particle or a particle", str(id))

    def take_particle_in(self, dir):
        """
        Takes a particle that is in a given direction

        :param dir: The direction on which the particle should be taken. Options: E, SE, SW, W, NW, NE,
        :return: True: successful taken; False: unsuccessful taken
        """
        if self.carried_tile is None and self.carried_particle is None:
1333
1334
            coords = self.sim.get_coords_in_dir(self.coords, dir)
            if coords in self.sim.particle_map_coords:
Ahmad Reza's avatar
Ahmad Reza committed
1335
                logging.info("Take particle")
1336
                self.carried_particle = self.sim.particle_map_coords[coords]
Ahmad Reza's avatar
Ahmad Reza committed
1337
1338
                if self.carried_particle.take_me(coords=self.coords):
                    logging.info("particle with particle id %s  has been taken", str(self.carried_particle.get_id()))
1339
                    self.sim.csv_round_writer.update_metrics(
Ahmad Reza's avatar
Ahmad Reza committed
1340
1341
1342
1343
1344
1345
1346
                                                               particles_taken=1)
                    self.csv_particle_writer.write_particle(particles_taken=1)
                    return True
                else:
                    logging.info("particle could not be taken")
                    return False
            else:
1347
                pass
1348
                logging.info("particl is not in the sim")
Ahmad Reza's avatar
Ahmad Reza committed
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
        else:
            logging.info("particle cannot be  taken")

    def take_particle_on(self, x=None, y=None):
        """
        Takes the particle on the given coordinate if it is not taken

        :param y:
        :param x:
        :return: True: Successful taken; False: Cannot be taken or wrong Coordinates
        """
        if self.carried_particle is None and self.carried_tile is None:
1361
            if self.sim.check_coords(x, y):
Ahmad Reza's avatar
Ahmad Reza committed
1362
                coords = (x, y)
1363
1364
1365
                if coords in self.sim.particle_map_coords:
                    self.carried_particle = self.sim.particle_map_coords[coords]
                    logging.info("Particle with id %s is in the sim", str(self.carried_particle.get_id()))
Ahmad Reza's avatar
Ahmad Reza committed
1366
                    if self.carried_particle.take_me(coords=self.coords):
1367
                        self.sim.csv_round_writer.update_metrics( particles_taken=1)
Ahmad Reza's avatar
Ahmad Reza committed
1368
1369
1370
1371
1372
1373
1374
                        self.csv_particle_writer.write_particle(particles_taken=1)
                        logging.info("particle with tile id %s has been taken", str(self.carried_particle.get_id()))
                        return True
                    else:
                        logging.info("Particle with id %s could not be taken", str(self.carried_particle.get_id()))
                        return False
                else:
1375
                    logging.info("Particle is not in the sim")
Ahmad Reza's avatar
Ahmad Reza committed
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
                    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):
        """
        Drops the taken particle on the particles actual position

        :return: None
        """
        if self.carried_particle is not None:
1391
            if self.coords not in self.sim.particle_map_coords:
Ahmad Reza's avatar
Ahmad Reza committed
1392
1393
1394
1395
1396
                try:  # cher: insert so to overcome the AttributeError
                    self.carried_particle.drop_me(self.coords)
                except AttributeError:
                    pass
            self.carried_particle = None
1397
            self.sim.csv_round_writer.update_metrics( particles_dropped=1)
Ahmad Reza's avatar
Ahmad Reza committed
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
            self.csv_particle_writer.write_particle(particles_dropped=1)
            logging.info("Particle succesfull dropped")
            return True
        else:
            logging.info("No particle taken to drop")
            return False

    def drop_particle_in(self, dir):
        """
        Drops the particle tile in a given direction

         :param dir: The direction on which the particle should be dropped. Options: E, SE, SW, W, NW, NE,
        """
        if self.carried_particle is not None:
1412
1413
            coords = self.sim.get_coords_in_dir(self.coords, dir)
            if coords not in self.sim.particle_map_coords:
Ahmad Reza's avatar
Ahmad Reza committed
1414
1415
1416
1417
1418
1419
                try:  # cher: insert so to overcome the AttributeError
                    self.carried_particle.drop_me(coords)
                except AttributeError:
                    pass
                    self.carried_particle = None
                    logging.info("Dropped particle on %s coordinate", str(coords))
1420
                    self.sim.csv_round_writer.update_metrics( particles_dropped=1)
Ahmad Reza's avatar
Ahmad Reza committed
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
                    self.csv_particle_writer.write_particle(particles_dropped=1)
                    return True
                else:
                    logging.info("Is not possible to drop the particle on that position")
                    return False
            else:
                logging.info("Is not possible to drop the particle on that position because it is occupied")
                return False
        else:
            logging.info("No particle taken to drop")
            return False

    def drop_particle_on(self, x=None, y=None):
        """
        Drops the particle tile on a given x and y coordination

        :param x: x coordinate
        :param y: y coordinate
        """
        if self.carried_particle is not None:
            if x is not None and y is not None:
1442
                if self.sim.check_coords(x, y):
Ahmad Reza's avatar
Ahmad Reza committed
1443
                    coords = (x, y)
1444
                    if coords not in self.sim.particle_map_coords:
Ahmad Reza's avatar
Ahmad Reza committed
1445
1446
1447
1448
1449
1450
                        try:  # cher: insert so to overcome the AttributeError
                            self.carried_particle.drop_me(coords)
                        except AttributeError:
                            pass
                        self.carried_particle = None
                        logging.info("Dropped particle on %s coordinate", str(coords))
1451
                        self.sim.csv_round_writer.update_metrics(
Ahmad Reza's avatar
Ahmad Reza committed
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
                                                                   particles_dropped=1)
                        self.csv_particle_writer.write_particle(particles_dropped=1)
                        return True
                    else:
                        logging.info("Is not possible to drop the particle on that position  because it is occupied")
                        return False
                else:
                    logging.info("Wrong coordinates for dropping particle")
                    return False
            else:
                logging.info("No coordinates for dropping particle")
                return False
        else:
            log