particle.py 69.8 KB
Newer Older
Ahmad Reza's avatar
Ahmad Reza committed
1
2
3
4
5
6
7
8
9
10
11
12
13
"""
.. 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
Ahmad Reza's avatar
Ahmad Reza committed
14
from lib.header import *
Ahmad Reza's avatar
Ahmad Reza committed
15
16
17

particle_counter=0

Ahmad Reza's avatar
Ahmad Reza committed
18

Ahmad Reza's avatar
Ahmad Reza committed
19
class Particle(matter.Matter):
20
    """In the classe marker all the methods for the characterstic of a marker is included"""
21
    def __init__(self, world, x, y, color=black, alpha=1, particle_counter = particle_counter):
22
        """Initializing the marker constructor"""
23
24
25
        super().__init__( world, (x, y), color, alpha,
                          type="particle", mm_size=world.config_data.particle_mm_size)
        self.number = particle_counter
Ahmad Reza's avatar
Ahmad Reza committed
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
        self.__isCarried = False
        self.carried_tile = None
        self.carried_particle = None
        self.steps = 0
        self.csv_particle_writer = csv_generator.CsvParticleData( self.get_id(), self.number)

    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
        """
Ahmad Reza's avatar
Ahmad Reza committed
58
        if self.coords in self.world.tile_map_coords:
Ahmad Reza's avatar
Ahmad Reza committed
59
60
61
62
63
64
65
66
67
68
            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
        """
Ahmad Reza's avatar
Ahmad Reza committed
69
        if self.coords in self.world.particle_map_coords:
Ahmad Reza's avatar
Ahmad Reza committed
70
71
72
73
            return True
        else:
            return False

74
    def check_on_marker(self):
Ahmad Reza's avatar
Ahmad Reza committed
75
        """
76
        Checks if the particle is on a marker
Ahmad Reza's avatar
Ahmad Reza committed
77

78
        :return: True: On a marker; False: Not on a marker
Ahmad Reza's avatar
Ahmad Reza committed
79
        """
Ahmad Reza's avatar
Ahmad Reza committed
80
        if self.coords in self.world.marker_map_coords:
Ahmad Reza's avatar
Ahmad Reza committed
81
82
83
84
85
86
87
88
89
90
91
            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
        """
Ahmad Reza's avatar
Ahmad Reza committed
92
        dir_coord = self.world.get_coords_in_dir(self.coords, dir)
Ahmad Reza Cheraghi's avatar
Ahmad Reza Cheraghi committed
93
        dir, dir_coord = self.check_within_border(dir, dir_coord)
94
        if check_coords(dir_coord[0], dir_coord[1]):
Ahmad Reza's avatar
Ahmad Reza committed
95

Ahmad Reza's avatar
Ahmad Reza committed
96
97
            if self.coords in self.world.particle_map_coords:
                del self.world.particle_map_coords[self.coords]
Ahmad Reza Cheraghi's avatar
Ahmad Reza Cheraghi committed
98

Ahmad Reza's avatar
Ahmad Reza committed
99
            if not dir_coord in self.world.particle_map_coords:
Ahmad Reza Cheraghi's avatar
Ahmad Reza Cheraghi committed
100
                self.coords = dir_coord
Ahmad Reza's avatar
Ahmad Reza committed
101
                self.world.particle_map_coords[self.coords] = self
Ahmad Reza's avatar
Ahmad Reza committed
102
                logging.info("particle %s successfully moved to %s", str(self.get_id()), dir)
Ahmad Reza's avatar
Ahmad Reza committed
103
                self.world.csv_round.update_metrics( steps=1)
Ahmad Reza's avatar
Ahmad Reza committed
104
105
                self.csv_particle_writer.write_particle(steps=1)
                self.touch()
Ahmad Reza Cheraghi's avatar
Ahmad Reza Cheraghi committed
106
                self.check_for_carried_tile_or_particle()
Ahmad Reza's avatar
Ahmad Reza committed
107
                return True
108
        return False
Ahmad Reza's avatar
Ahmad Reza committed
109

Ahmad Reza Cheraghi's avatar
Ahmad Reza Cheraghi committed
110
111
112
113
114
115
116
117
118
    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):
Ahmad Reza's avatar
Ahmad Reza committed
119
120
        if self.world.config_data.border == 1 and \
                (abs(dir_coord[0]) > self.world.get_sim_x_size() or abs(dir_coord[1]) > self.world.get_sim_y_size()):
Ahmad Reza Cheraghi's avatar
Ahmad Reza Cheraghi committed
121
            dir = dir - 3 if dir > 2 else dir + 3
Ahmad Reza's avatar
Ahmad Reza committed
122
            dir_coord = self.world.get_coords_in_dir(self.coords, dir)
Ahmad Reza Cheraghi's avatar
Ahmad Reza Cheraghi committed
123
124
        return dir, dir_coord

Ahmad Reza's avatar
Ahmad Reza committed
125
126
127
128
129
130
131
    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
        """
Ahmad Reza's avatar
Ahmad Reza committed
132
        dir_coord = self.world.get_coords_in_dir(self.coords, dir)
133
        sim_coord = coords_to_sim(dir_coord)
Ahmad Reza's avatar
Ahmad Reza committed
134
135
        if self.world.get_sim_x_size() >=  abs(sim_coord[0]) and \
                        self.world.get_sim_y_size() >=  abs(sim_coord[1]):
Ahmad Reza's avatar
Ahmad Reza committed
136
137
138
139
140
141
142
143
            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):
        """
144
        Read the memories from the matters (paricle, tile, or marker object) memories with a given keyword
Ahmad Reza's avatar
Ahmad Reza committed
145

146
        :param matter: The matter can be either a particle, tile, or marker
Ahmad Reza's avatar
Ahmad Reza committed
147
148
149
150
151
152
153
154
155
156
        :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":
Ahmad Reza's avatar
Ahmad Reza committed
157
                self.world.csv_round.update_metrics( particle_read=1)
Ahmad Reza's avatar
Ahmad Reza committed
158
159
                self.csv_particle_writer.write_particle(particle_read=1)
            elif matter.type == "tile":
Ahmad Reza's avatar
Ahmad Reza committed
160
                self.world.csv_round.update_metrics( tile_read=1)
Ahmad Reza's avatar
Ahmad Reza committed
161
                self.csv_particle_writer.write_particle(tile_read=1)
162
            elif matter.type == "marker":
Ahmad Reza's avatar
Ahmad Reza committed
163
                self.world.csv_round.update_metrics( marker_read=1)
164
                self.csv_particle_writer.write_particle(marker_read=1)
Ahmad Reza's avatar
Ahmad Reza committed
165
166
167
168
            return tmp_memory
        else:
            return None

Ahmad Reza Cheraghi's avatar
Ahmad Reza Cheraghi committed
169
170
171
172
173
    def matter_in(self, dir=E):
        """
        :param dir: the direction to check if a matter is there
        :return: True: if a matter is there, False: if not
        """
Ahmad Reza's avatar
Ahmad Reza committed
174
175
176
        if  self.world.get_coords_in_dir(self.coords, dir) in self.world.get_tile_map_coords() \
            or self.world.get_coords_in_dir(self.coords, dir) in self.world.get_particle_map_coords() \
            or self.world.get_coords_in_dir(self.coords, dir) in self.world.get_marker_map_coords():
Ahmad Reza Cheraghi's avatar
Ahmad Reza Cheraghi committed
177
178
179
            return True
        else:
            return False
Ahmad Reza's avatar
Ahmad Reza committed
180
181

    def tile_in(self, dir=E):
Ahmad Reza Cheraghi's avatar
Ahmad Reza Cheraghi committed
182
183
184
185
        """
        :param dir: the direction to check if a tile is there
        :return: True: if a tile is there, False: if not
        """
Ahmad Reza's avatar
Ahmad Reza committed
186
        if self.world.get_coords_in_dir(self.coords, dir) in self.world.get_tile_map_coords():
Ahmad Reza Cheraghi's avatar
Ahmad Reza Cheraghi committed
187
188
189
            return True
        else:
            return False
Ahmad Reza's avatar
Ahmad Reza committed
190
191

    def particle_in(self, dir=E):
Ahmad Reza Cheraghi's avatar
Ahmad Reza Cheraghi committed
192
193
194
195
        """
        :param dir: the direction to check if a particle is there
        :return: True: if a particle is there, False: if not
        """
Ahmad Reza's avatar
Ahmad Reza committed
196
        if self.world.get_coords_in_dir(self.coords, dir) in self.world.get_particle_map_coords():
Ahmad Reza Cheraghi's avatar
Ahmad Reza Cheraghi committed
197
198
199
            return True
        else:
            return False
Ahmad Reza's avatar
Ahmad Reza committed
200

201
    def marker_in(self, dir=E):
Ahmad Reza Cheraghi's avatar
Ahmad Reza Cheraghi committed
202
203
204
205
        """
        :param dir: the direction to check if a marker is there
        :return: True: if a marker is there, False: if not
        """
Ahmad Reza's avatar
Ahmad Reza committed
206
        if self.world.get_coords_in_dir(self.coords, dir) in self.world.get_marker_map_coords():
Ahmad Reza Cheraghi's avatar
Ahmad Reza Cheraghi committed
207
208
209
            return True
        else:
            return False
Ahmad Reza's avatar
Ahmad Reza committed
210

Ahmad Reza Cheraghi's avatar
Ahmad Reza Cheraghi committed
211
    def get_matter_in(self, dir=E):
Ahmad Reza's avatar
Ahmad Reza committed
212
213
214
215
216
217
        if self.world.get_coords_in_dir(self.coords, dir) in self.world.get_tile_map_coords():
            return self.world.get_tile_map_coords()[self.world.get_coords_in_dir(self.coords, dir)]
        elif self.world.get_coords_in_dir(self.coords, dir) in self.world.get_particle_map_coords():
            return self.world.get_particle_map_coords()[self.world.get_coords_in_dir(self.coords, dir)]
        elif self.world.get_coords_in_dir(self.coords, dir) in self.world.get_marker_map_coords():
            return self.world.get_marker_map_coords()[self.world.get_coords_in_dir(self.coords, dir)]
Ahmad Reza Cheraghi's avatar
Ahmad Reza Cheraghi committed
218
219
        else:
            return False
Ahmad Reza's avatar
Ahmad Reza committed
220
221

    def get_tile_in(self, dir=E):
Ahmad Reza's avatar
Ahmad Reza committed
222
223
        if self.world.get_coords_in_dir(self.coords, dir) in self.world.get_tile_map_coords():
            return self.world.get_tile_map_coords()[self.world.get_coords_in_dir(self.coords, dir)]
Ahmad Reza Cheraghi's avatar
Ahmad Reza Cheraghi committed
224
225
        else:
            return False
Ahmad Reza's avatar
Ahmad Reza committed
226
227

    def get_particle_in(self, dir=E):
Ahmad Reza's avatar
Ahmad Reza committed
228
229
        if self.world.get_coords_in_dir(self.coords, dir) in self.world.get_particle_map_coords():
            return self.world.get_particle_map_coords()[self.world.get_coords_in_dir(self.coords, dir)]
Ahmad Reza Cheraghi's avatar
Ahmad Reza Cheraghi committed
230
231
        else:
            return False
Ahmad Reza's avatar
Ahmad Reza committed
232

233
    def get_marker_in(self, dir=E):
Ahmad Reza's avatar
Ahmad Reza committed
234
235
        if self.world.get_coords_in_dir(self.coords, dir) in self.world.get_marker_map_coords():
            return self.world.get_marker_map_coords()[self.world.get_coords_in_dir(self.coords, dir)]
Ahmad Reza Cheraghi's avatar
Ahmad Reza Cheraghi committed
236
237
        else:
            return False
Ahmad Reza's avatar
Ahmad Reza committed
238

239
    def get_marker(self):
Ahmad Reza's avatar
Ahmad Reza committed
240
241
        if self.coords in self.world.marker_map_coords:
            return self.world.get_marker_map_coords()[self.coords]
Ahmad Reza Cheraghi's avatar
Ahmad Reza Cheraghi committed
242
243
        else:
            return False
Ahmad Reza's avatar
Ahmad Reza committed
244

Ahmad Reza Cheraghi's avatar
Ahmad Reza Cheraghi committed
245
    def get_tile(self):
Ahmad Reza's avatar
Ahmad Reza committed
246
247
        if self.self.coords in self.world.get_tile_map_coords():
            return self.world.get_tile_map_coords()[self.coords]
Ahmad Reza Cheraghi's avatar
Ahmad Reza Cheraghi committed
248
249
        else:
            return False
Ahmad Reza's avatar
Ahmad Reza committed
250
251
252

    def write_to_with(self, matter, key=None, data=None):
        """
253
        Writes data with given a keyword directly on the matters (paricle, tile, or marker object) memory
Ahmad Reza's avatar
Ahmad Reza committed
254

255
        :param matter: The matter can be either a particle, tile, or marker
Ahmad Reza's avatar
Ahmad Reza committed
256
257
258
259
260
261
262
263
264
265
266
267
268
        :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":
Ahmad Reza's avatar
Ahmad Reza committed
269
                    self.world.csv_round.update_metrics( particle_write=1)
Ahmad Reza's avatar
Ahmad Reza committed
270
271
                    self.csv_particle_writer.write_particle(particle_write=1)
                elif matter.type == "tile":
Ahmad Reza's avatar
Ahmad Reza committed
272
                    self.world.csv_round.update_metrics( tile_write=1)
Ahmad Reza's avatar
Ahmad Reza committed
273
                    self.csv_particle_writer.write_particle(tile_write=1)
274
                elif matter.type == "marker":
Ahmad Reza's avatar
Ahmad Reza committed
275
                    self.world.csv_round.update_metrics( marker_write=1)
276
                    self.csv_particle_writer.write_particle(marker_write=1)
Ahmad Reza's avatar
Ahmad Reza committed
277
278
279
280
281
282
                return True
            else:
                return False
        else:
            return False

Ahmad Reza's avatar
Ahmad Reza committed
283
284
    def scan_for_matter_within(self, matter='all', hop=1):
        """
285
        Scans for particles, tiles, or marker on a given hop distance and all the matters within the hop distance
Ahmad Reza's avatar
Ahmad Reza committed
286
287
288

        :todo: If nothing then everything should be scanned

289
        :param matter: For what matter this method should scan for. Can be either particles, tiles, markers, or (default)all
Ahmad Reza's avatar
Ahmad Reza committed
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
        :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):
        """
306
        Scanning for particles, tiles, or marker on a given hop distance
Ahmad Reza's avatar
Ahmad Reza committed
307

308
        :param matter: For what matter this method should scan for. Can be either particles, tiles, markers, or (default)all
Ahmad Reza's avatar
Ahmad Reza committed
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
        :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":
Ahmad Reza's avatar
Ahmad Reza committed
325
326
327
328
                    if (x_scan_pos, y_scan_coord_neg) in self.world.particle_map_coords:
                        hop_list.append(self.world.particle_map_coords[(x_scan_pos, y_scan_coord_neg)])
                    if (x_scan_neg, y_scan_coord_neg) in self.world.particle_map_coords:
                        hop_list.append(self.world.particle_map_coords[(x_scan_neg, y_scan_coord_neg)])
329
                elif matter == "markers":
Ahmad Reza's avatar
Ahmad Reza committed
330
331
332
333
                    if (x_scan_pos, y_scan_coord_neg) in self.world.marker_map_coords:
                        hop_list.append(self.world.marker_map_coords[(x_scan_pos, y_scan_coord_neg)])
                    if (x_scan_neg, y_scan_coord_neg) in self.world.marker_map_coords:
                        hop_list.append(self.world.marker_map_coords[(x_scan_neg, y_scan_coord_neg)])
Ahmad Reza's avatar
Ahmad Reza committed
334
                elif matter == "tiles":
Ahmad Reza's avatar
Ahmad Reza committed
335
336
337
338
                    if (x_scan_pos, y_scan_coord_neg) in self.world.tile_map_coords:
                        hop_list.append(self.world.tile_map_coords[(x_scan_pos, y_scan_coord_neg)])
                    if (x_scan_neg, y_scan_coord_neg) in self.world.tile_map_coords:
                        hop_list.append(self.world.tile_map_coords[(x_scan_neg, y_scan_coord_neg)])
Ahmad Reza's avatar
Ahmad Reza committed
339
                elif matter == "all":
Ahmad Reza Cheraghi's avatar
Ahmad Reza Cheraghi committed
340

Ahmad Reza's avatar
Ahmad Reza committed
341
342
343
344
345
346
347
348
349
350
351
352
                    if (x_scan_pos, y_scan_coord_neg) in self.world.tile_map_coords:
                        hop_list.append(self.world.tile_map_coords[(x_scan_pos, y_scan_coord_neg)])
                    if (x_scan_neg, y_scan_coord_neg) in self.world.tile_map_coords:
                        hop_list.append(self.world.tile_map_coords[(x_scan_neg, y_scan_coord_neg)])
                    if (x_scan_pos, y_scan_coord_neg) in self.world.marker_map_coords:
                        hop_list.append(self.world.marker_map_coords[(x_scan_pos, y_scan_coord_neg)])
                    if (x_scan_neg, y_scan_coord_neg) in self.world.marker_map_coords:
                        hop_list.append(self.world.marker_map_coords[(x_scan_neg, y_scan_coord_neg)])
                    if (x_scan_pos, y_scan_coord_neg) in self.world.particle_map_coords:
                        hop_list.append(self.world.particle_map_coords[(x_scan_pos, y_scan_coord_neg)])
                    if (x_scan_neg, y_scan_coord_neg) in self.world.particle_map_coords:
                        hop_list.append(self.world.particle_map_coords[(x_scan_neg, y_scan_coord_neg)])
Ahmad Reza's avatar
Ahmad Reza committed
353
354
355
356
                else:
                    logging.info("No matter specified")
            else:
                if matter == "particles":
Ahmad Reza's avatar
Ahmad Reza committed
357
358
359
360
361
362
363
364
                    if (x_scan_pos, y_scan_coord_pos) in self.world.particle_map_coords:
                        hop_list.append(self.world.particle_map_coords[(x_scan_pos, y_scan_coord_pos)])
                    if (x_scan_pos, y_scan_coord_neg) in self.world.particle_map_coords:
                        hop_list.append(self.world.particle_map_coords[(x_scan_pos, y_scan_coord_neg)])
                    if (x_scan_neg, y_scan_coord_pos) in self.world.particle_map_coords:
                        hop_list.append(self.world.particle_map_coords[(x_scan_neg, y_scan_coord_pos)])
                    if (x_scan_neg, y_scan_coord_neg) in self.world.particle_map_coords:
                        hop_list.append(self.world.particle_map_coords[(x_scan_neg, y_scan_coord_neg)])
365
                elif matter == "markers":
Ahmad Reza's avatar
Ahmad Reza committed
366
367
368
369
370
371
372
373
                    if (x_scan_pos, y_scan_coord_pos) in self.world.marker_map_coords:
                        hop_list.append(self.world.marker_map_coords[(x_scan_pos, y_scan_coord_pos)])
                    if (x_scan_pos, y_scan_coord_neg) in self.world.marker_map_coords:
                        hop_list.append(self.world.marker_map_coords[(x_scan_pos, y_scan_coord_neg)])
                    if (x_scan_neg, y_scan_coord_pos) in self.world.marker_map_coords:
                        hop_list.append(self.world.marker_map_coords[(x_scan_neg, y_scan_coord_pos)])
                    if (x_scan_neg, y_scan_coord_neg) in self.world.marker_map_coords:
                        hop_list.append(self.world.marker_map_coords[(x_scan_neg, y_scan_coord_neg)])
Ahmad Reza's avatar
Ahmad Reza committed
374
                elif matter == "tiles":
Ahmad Reza's avatar
Ahmad Reza committed
375
376
377
378
379
380
381
382
                    if (x_scan_pos, y_scan_coord_pos) in self.world.tile_map_coords:
                        hop_list.append(self.world.tile_map_coords[(x_scan_pos, y_scan_coord_pos)])
                    if (x_scan_pos, y_scan_coord_neg) in self.world.tile_map_coords:
                        hop_list.append(self.world.tile_map_coords[(x_scan_pos, y_scan_coord_neg)])
                    if (x_scan_pos, y_scan_coord_neg) in self.world.tile_map_coords:
                        hop_list.append(self.world.tile_map_coords[(x_scan_pos, y_scan_coord_neg)])
                    if (x_scan_neg, y_scan_coord_neg) in self.world.tile_map_coords:
                        hop_list.append(self.world.tile_map_coords[(x_scan_neg, y_scan_coord_neg)])
Ahmad Reza's avatar
Ahmad Reza committed
383
                elif matter == "all":
Ahmad Reza's avatar
Ahmad Reza committed
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
                    if (x_scan_pos, y_scan_coord_pos) in self.world.particle_map_coords:
                        hop_list.append(self.world.particle_map_coords[(x_scan_pos, y_scan_coord_pos)])
                    if (x_scan_pos, y_scan_coord_neg) in self.world.particle_map_coords:
                        hop_list.append(self.world.particle_map_coords[(x_scan_pos, y_scan_coord_neg)])
                    if (x_scan_neg, y_scan_coord_pos) in self.world.particle_map_coords:
                        hop_list.append(self.world.particle_map_coords[(x_scan_neg, y_scan_coord_pos)])
                    if (x_scan_neg, y_scan_coord_neg) in self.world.particle_map_coords:
                        hop_list.append(self.world.particle_map_coords[(x_scan_neg, y_scan_coord_neg)])

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

                    if (x_scan_pos, y_scan_coord_pos) in self.world.tile_map_coords:
                        hop_list.append(self.world.tile_map_coords[(x_scan_pos, y_scan_coord_pos)])
                    if (x_scan_pos, y_scan_coord_neg) in self.world.tile_map_coords:
                        hop_list.append(self.world.tile_map_coords[(x_scan_pos, y_scan_coord_neg)])
                    if (x_scan_pos, y_scan_coord_neg) in self.world.tile_map_coords:
                        hop_list.append(self.world.tile_map_coords[(x_scan_pos, y_scan_coord_neg)])
                    if (x_scan_neg, y_scan_coord_neg) in self.world.tile_map_coords:
                        hop_list.append(self.world.tile_map_coords[(x_scan_neg, y_scan_coord_neg)])
Ahmad Reza's avatar
Ahmad Reza committed
410
411
412
413
414
415
416
417
418
419
420
421

                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":
Ahmad Reza's avatar
Ahmad Reza committed
422
423
424
425
                if (x_upper_scan, y_up_scan) in self.world.particle_map_coords:
                    hop_list.append(self.world.particle_map_coords[(x_upper_scan, y_up_scan)])
                if (x_upper_scan, y_down_scan) in self.world.particle_map_coords:
                    hop_list.append(self.world.particle_map_coords[(x_upper_scan, y_down_scan)])
426
            elif matter == "markers":
Ahmad Reza's avatar
Ahmad Reza committed
427
428
429
430
                if (x_upper_scan, y_up_scan) in self.world.marker_map_coords:
                    hop_list.append(self.world.marker_map_coords[(x_upper_scan, y_up_scan)])
                if (x_upper_scan, y_down_scan) in self.world.marker_map_coords:
                    hop_list.append(self.world.marker_map_coords[(x_upper_scan, y_down_scan)])
Ahmad Reza's avatar
Ahmad Reza committed
431
            elif matter == "tiles":
Ahmad Reza's avatar
Ahmad Reza committed
432
433
434
435
                if (x_upper_scan, y_up_scan) in self.world.tile_map_coords:
                    hop_list.append(self.world.tile_map_coords[(x_upper_scan, y_up_scan)])
                if (x_upper_scan, y_down_scan) in self.world.tile_map_coords:
                    hop_list.append(self.world.tile_map_coords[(x_upper_scan, y_down_scan)])
Ahmad Reza's avatar
Ahmad Reza committed
436
437
            if matter == "all":
                if hop == 0:
Ahmad Reza's avatar
Ahmad Reza committed
438
439
440
441
442
443
                    if (0, 0) in self.world.particle_map_coords:
                        hop_list.append(self.world.particle_map_coords[(0, 0)])
                    if (0, 0) in self.world.marker_map_coords:
                        hop_list.append(self.world.marker_map_coords[(0, 0)])
                    if (0, 0) in self.world.tile_map_coords:
                        hop_list.append(self.world.tile_map_coords[(0, 0)])
Ahmad Reza's avatar
Ahmad Reza committed
444
                else:
Ahmad Reza's avatar
Ahmad Reza committed
445
446
447
448
                    if (x_upper_scan, y_up_scan) in self.world.particle_map_coords:
                        hop_list.append(self.world.particle_map_coords[(x_upper_scan, y_up_scan)])
                    if (x_upper_scan, y_down_scan) in self.world.particle_map_coords:
                        hop_list.append(self.world.particle_map_coords[(x_upper_scan, y_down_scan)])
Ahmad Reza's avatar
Ahmad Reza committed
449

Ahmad Reza's avatar
Ahmad Reza committed
450
451
452
453
                    if (x_upper_scan, y_up_scan) in self.world.marker_map_coords:
                        hop_list.append(self.world.marker_map_coords[(x_upper_scan, y_up_scan)])
                    if (x_upper_scan, y_down_scan) in self.world.marker_map_coords:
                        hop_list.append(self.world.marker_map_coords[(x_upper_scan, y_down_scan)])
Ahmad Reza's avatar
Ahmad Reza committed
454

Ahmad Reza's avatar
Ahmad Reza committed
455
456
457
458
                    if (x_upper_scan, y_up_scan) in self.world.tile_map_coords:
                        hop_list.append(self.world.tile_map_coords[(x_upper_scan, y_up_scan)])
                    if (x_upper_scan, y_down_scan) in self.world.tile_map_coords:
                        hop_list.append(self.world.tile_map_coords[(x_upper_scan, y_down_scan)])
Ahmad Reza's avatar
Ahmad Reza committed
459
460
461
462
463
464
465
466
467
468
469
470
471
472

            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):
        """
473
        Scans for particles, tiles, or marker on a given hop distance and all the matters within the hop distance
Ahmad Reza's avatar
Ahmad Reza committed
474
475
476

        :todo: If nothing then everything should be scanned

477
        :param matter: For what matter this method should scan for. Can be either particles, tiles, markers, or (default)all
Ahmad Reza's avatar
Ahmad Reza committed
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
        :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):
        """
494
        Scanning for particles, tiles, or marker on a given hop distance
Ahmad Reza's avatar
Ahmad Reza committed
495

496
        :param matter: For what matter this method should scan for. Can be either particles, tiles, markers, or (default)all
Ahmad Reza's avatar
Ahmad Reza committed
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
        :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:
Ahmad Reza's avatar
Ahmad Reza committed
512
513
514
515
516
517
                # if self.coords in self.world.particle_map_coords:
                #     hop_list.append(self.world.particle_map_coords[self.coords])
                if (x_scan_pos, y_scan_coord_neg) in self.world.particle_map_coords:
                    hop_list.append(self.world.particle_map_coords[(x_scan_pos, y_scan_coord_neg)])
                if (x_scan_neg, y_scan_coord_neg) in self.world.particle_map_coords:
                    hop_list.append(self.world.particle_map_coords[(x_scan_neg, y_scan_coord_neg)])
Ahmad Reza's avatar
Ahmad Reza committed
518
            else:
Ahmad Reza's avatar
Ahmad Reza committed
519
520
521
522
523
524
525
526
                if (x_scan_pos, y_scan_coord_pos) in self.world.particle_map_coords:
                    hop_list.append(self.world.particle_map_coords[(x_scan_pos, y_scan_coord_pos)])
                if (x_scan_pos, y_scan_coord_neg) in self.world.particle_map_coords:
                    hop_list.append(self.world.particle_map_coords[(x_scan_pos, y_scan_coord_neg)])
                if (x_scan_neg, y_scan_coord_pos) in self.world.particle_map_coords:
                    hop_list.append(self.world.particle_map_coords[(x_scan_neg, y_scan_coord_pos)])
                if (x_scan_neg, y_scan_coord_neg) in self.world.particle_map_coords:
                    hop_list.append(self.world.particle_map_coords[(x_scan_neg, y_scan_coord_neg)])
Ahmad Reza's avatar
Ahmad Reza committed
527
528
529
530
531
532
533
534
            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
Ahmad Reza's avatar
Ahmad Reza committed
535
536
537
538
            if (x_upper_scan, y_up_scan) in self.world.particle_map_coords:
                hop_list.append(self.world.particle_map_coords[(x_upper_scan, y_up_scan)])
            if (x_upper_scan, y_down_scan) in self.world.particle_map_coords:
                hop_list.append(self.world.particle_map_coords[(x_upper_scan, y_down_scan)])
Ahmad Reza's avatar
Ahmad Reza committed
539
540
541
542
543
544
545
546
547
548
549
            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):
        """
550
        Scans for particles, tiles, or marker on a given hop distance and all the matters within the hop distance
Ahmad Reza's avatar
Ahmad Reza committed
551
552
553

        :todo: If nothing then everything should be scanned

554
        :param matter: For what matter this method should scan for. Can be either particles, tiles, markers, or (default)all
Ahmad Reza's avatar
Ahmad Reza committed
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
        :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):
        """
571
        Scanning for particles, tiles, or marker on a given hop distance
Ahmad Reza's avatar
Ahmad Reza committed
572

573
        :param matter: For what matter this method should scan for. Can be either particles, tiles, markers, or (default)all
Ahmad Reza's avatar
Ahmad Reza committed
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
        :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:
Ahmad Reza's avatar
Ahmad Reza committed
589
590
591
592
593
594
                # if self.coords in self.world.tile_map_coords:
                #     hop_list.append(self.world.tile_map_coords[self.coords])
                if (x_scan_pos, y_scan_coord_neg) in self.world.tile_map_coords:
                    hop_list.append(self.world.tile_map_coords[(x_scan_pos, y_scan_coord_neg)])
                if (x_scan_neg, y_scan_coord_neg) in self.world.tile_map_coords:
                    hop_list.append(self.world.tile_map_coords[(x_scan_neg, y_scan_coord_neg)])
Ahmad Reza's avatar
Ahmad Reza committed
595
            else:
Ahmad Reza's avatar
Ahmad Reza committed
596
597
598
599
600
601
602
603
                if (x_scan_pos, y_scan_coord_pos) in self.world.tile_map_coords:
                    hop_list.append(self.world.tile_map_coords[(x_scan_pos, y_scan_coord_pos)])
                if (x_scan_pos, y_scan_coord_neg) in self.world.tile_map_coords:
                    hop_list.append(self.world.tile_map_coords[(x_scan_pos, y_scan_coord_neg)])
                if (x_scan_pos, y_scan_coord_neg) in self.world.tile_map_coords:
                    hop_list.append(self.world.tile_map_coords[(x_scan_pos, y_scan_coord_neg)])
                if (x_scan_neg, y_scan_coord_neg) in self.world.tile_map_coords:
                    hop_list.append(self.world.tile_map_coords[(x_scan_neg, y_scan_coord_neg)])
Ahmad Reza's avatar
Ahmad Reza committed
604
605
606
607
608
609
610
611
            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
Ahmad Reza's avatar
Ahmad Reza committed
612
613
614
615
            if (x_upper_scan, y_up_scan) in self.world.tile_map_coords:
                hop_list.append(self.world.tile_map_coords[(x_upper_scan, y_up_scan)])
            if (x_upper_scan, y_down_scan) in self.world.tile_map_coords:
                hop_list.append(self.world.tile_map_coords[(x_upper_scan, y_down_scan)])
Ahmad Reza's avatar
Ahmad Reza committed
616
617
618
619
620
621
622
623
624
            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

625
    def scan_for_marker_within(self, hop=1):
Ahmad Reza's avatar
Ahmad Reza committed
626
        """
627
        Scans for particles, tiles, or marker on a given hop distance and all the matters within the hop distance
Ahmad Reza's avatar
Ahmad Reza committed
628
629
630

        :todo: If nothing then everything should be scanned

631
        :param matter: For what matter this method should scan for. Can be either particles, tiles, markers, or (default)all
Ahmad Reza's avatar
Ahmad Reza committed
632
633
634
635
636
637
        :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):
638
            list = self.scan_for_marker_in(i)
Ahmad Reza's avatar
Ahmad Reza committed
639
640
641
642
643
644
645
            if list != None:
                hop_list.extend(list)
        if len(hop_list) != 0:
            return hop_list
        else:
            return None

646
    def scan_for_marker_in(self, hop=1):
Ahmad Reza's avatar
Ahmad Reza committed
647
        """
648
        Scanning for particles, tiles, or marker on a given hop distance
Ahmad Reza's avatar
Ahmad Reza committed
649

650
        :param matter: For what matter this method should scan for. Can be either particles, tiles, markers, or (default)all
Ahmad Reza's avatar
Ahmad Reza committed
651
652
653
654
        :param hop: The hop distance from thee actual position of the scanning particle
        :return: A list of the founded matters
        """
        hop_list = []
655
        logging.info("particle is scanning for marker in %i hops", hop)
Ahmad Reza's avatar
Ahmad Reza committed
656
657
658
659
660
661
662
663
664
665
        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:
Ahmad Reza's avatar
Ahmad Reza committed
666
667
668
669
670
671
                # if self.coords in self.world.marker_map_coords:
                #     hop_list.append(self.world.marker_map_coords[self.coords])
                if (x_scan_pos, y_scan_coord_neg) in self.world.marker_map_coords:
                    hop_list.append(self.world.marker_map_coords[(x_scan_pos, y_scan_coord_neg)])
                if (x_scan_neg, y_scan_coord_neg) in self.world.marker_map_coords:
                    hop_list.append(self.world.marker_map_coords[(x_scan_neg, y_scan_coord_neg)])
Ahmad Reza's avatar
Ahmad Reza committed
672
673
            else:

Ahmad Reza's avatar
Ahmad Reza committed
674
675
676
677
678
679
680
681
                if (x_scan_pos, y_scan_coord_pos) in self.world.marker_map_coords:
                    hop_list.append(self.world.marker_map_coords[(x_scan_pos, y_scan_coord_pos)])
                if (x_scan_pos, y_scan_coord_neg) in self.world.marker_map_coords:
                    hop_list.append(self.world.marker_map_coords[(x_scan_pos, y_scan_coord_neg)])
                if (x_scan_neg, y_scan_coord_pos) in self.world.marker_map_coords:
                    hop_list.append(self.world.marker_map_coords[(x_scan_neg, y_scan_coord_pos)])
                if (x_scan_neg, y_scan_coord_neg) in self.world.marker_map_coords:
                    hop_list.append(self.world.marker_map_coords[(x_scan_neg, y_scan_coord_neg)])
Ahmad Reza's avatar
Ahmad Reza committed
682
683
684
685
686
687
688
689
            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
Ahmad Reza's avatar
Ahmad Reza committed
690
691
692
693
            if (x_upper_scan, y_up_scan) in self.world.marker_map_coords:
                hop_list.append(self.world.marker_map_coords[(x_upper_scan, y_up_scan)])
            if (x_upper_scan, y_down_scan) in self.world.marker_map_coords:
                hop_list.append(self.world.marker_map_coords[(x_upper_scan, y_down_scan)])
Ahmad Reza's avatar
Ahmad Reza committed
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
            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:
Ahmad Reza's avatar
Ahmad Reza committed
712
713
            if self.coords in self.world.particle_map_coords:
                del self.world.particle_map_coords[self.coords]
Ahmad Reza's avatar
Ahmad Reza committed
714
715
            self.__isCarried = True
            self.coords = coords
716
            self.set_alpha(0.5)
Ahmad Reza's avatar
Ahmad Reza committed
717
718
719
720
721
722
723
724
725
726
727
728
            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
        """
Ahmad Reza's avatar
Ahmad Reza committed
729
        self.world.particle_map_coords[coords] = self
Ahmad Reza's avatar
Ahmad Reza committed
730
731
        self.coords = coords
        self.__isCarried = False
732
        self.set_alpha(1)
Ahmad Reza's avatar
Ahmad Reza committed
733
734
735
736
737
738
        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
739
        :return: New Tile or False
Ahmad Reza's avatar
Ahmad Reza committed
740
741
        """
        logging.info("Going to create a tile on position %s", str(self.coords))
Ahmad Reza's avatar
Ahmad Reza committed
742
        new_tile = self.world.add_tile(self.coords[0], self.coords[1], color, alpha)
Ahmad Reza's avatar
Ahmad Reza committed
743
        if new_tile:
Ahmad Reza's avatar
Ahmad Reza committed
744
            self.world.tile_map_coords[self.coords[0], self.coords[1]].created = True
Ahmad Reza's avatar
Ahmad Reza committed
745
            self.csv_particle_writer.write_particle(tile_created=1)
Ahmad Reza's avatar
Ahmad Reza committed
746
747
            self.world.csv_round.update_tiles_num(len(self.world.get_tiles_list()))
            self.world.csv_round.update_metrics( tile_created=1)
Ahmad Reza's avatar
Ahmad Reza committed
748
749
750
            return new_tile
        else:
            return False
Ahmad Reza's avatar
Ahmad Reza committed
751
752
753
754
755
756

    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
757
        :return: New tile or False
Ahmad Reza's avatar
Ahmad Reza committed
758
759
760
761
        """
        logging.info("particle with id %s is", self.get_id())
        logging.info("Going to create a tile in %s ", str(dir) )
        if dir != None:
Ahmad Reza's avatar
Ahmad Reza committed
762
763
            coords = self.world.get_coords_in_dir(self.coords, dir)
            new_tile = self.world.add_tile(coords[0], coords[1], color, alpha)
Ahmad Reza's avatar
Ahmad Reza committed
764
            if new_tile:
Ahmad Reza's avatar
Ahmad Reza committed
765
                self.world.tile_map_coords[coords[0], coords[1]].created = True
Ahmad Reza's avatar
Ahmad Reza committed
766
                logging.info("Tile is created")
Ahmad Reza's avatar
Ahmad Reza committed
767
                self.world.new_tile_flag = True
Ahmad Reza's avatar
Ahmad Reza committed
768
                self.csv_particle_writer.write_particle(tile_created=1)
Ahmad Reza's avatar
Ahmad Reza committed
769
770
                self.world.csv_round.update_tiles_num(len(self.world.get_tiles_list()))
                self.world.csv_round.update_metrics( tile_created=1)
Ahmad Reza's avatar
Ahmad Reza committed
771
772
773
                return new_tile
            else:
                return False
Ahmad Reza's avatar
Ahmad Reza committed
774
775
        else:
            logging.info("Not created tile ")
Ahmad Reza's avatar
Ahmad Reza committed
776
            return False
Ahmad Reza's avatar
Ahmad Reza committed
777
778
779
780
781
782
783

    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
784
        :return: New Tile or False
Ahmad Reza's avatar
Ahmad Reza committed
785
786
787
788
789
        """

        logging.info("particle with id %s is", self.get_id())
        if x is not None and y is not None:
            coords = (x, y)
790
            if check_coords(x,y):
Ahmad Reza's avatar
Ahmad Reza committed
791
                logging.info("Going to create a tile on position \(%i , %i\)", x,y )
Ahmad Reza's avatar
Ahmad Reza committed
792
793
794
                if self.world.add_tile(coords[0], coords[1], color, alpha) == True:
                    self.world.tile_map_coords[coords[0], coords[1]].created = True
                    self.world.new_tile_flag = True
Ahmad Reza's avatar
Ahmad Reza committed
795
                    self.csv_particle_writer.write_particle(tile_created=1)
Ahmad Reza's avatar
Ahmad Reza committed
796
797
                    self.world.csv_round.update_tiles_num(len(self.world.get_tiles_list()) )
                    self.world.csv_round.update_metrics( tile_created=1)
Ahmad Reza's avatar
Ahmad Reza committed
798
799
800
801
802
803
                    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
804
                return False
Ahmad Reza's avatar
Ahmad Reza committed
805
806
807
808
809
810
811
812
813

    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")
Ahmad Reza's avatar
Ahmad Reza committed
814
815
        if self.coords in self.world.get_tile_map_coords():
            if self.world.remove_tile_on(self.coords):
Ahmad Reza's avatar
Ahmad Reza committed
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
                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))
Ahmad Reza's avatar
Ahmad Reza committed
831
        if self.world.remove_tile(id):
Ahmad Reza's avatar
Ahmad Reza committed
832
833
834
835
836
837
            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
838
    def delete_tile_in(self, dir=None):
Ahmad Reza's avatar
Ahmad Reza committed
839
840
841
842
843
844
845
846
        """
        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
847
        if dir is not None:
Ahmad Reza's avatar
Ahmad Reza committed
848
            coords = self.world.get_coords_in_dir(self.coords, dir)
Ahmad Reza's avatar
Ahmad Reza committed
849
850
            logging.info("Deleting tile in %s direction", str(dir))
            if coords is not None:
Ahmad Reza's avatar
Ahmad Reza committed
851
                if self.world.remove_tile_on(coords):
Ahmad Reza's avatar
Ahmad Reza committed
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
                    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)
Ahmad Reza's avatar
Ahmad Reza committed
873
            if self.world.remove_tile_on(coords):
Ahmad Reza's avatar
Ahmad Reza committed
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
                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:
Ahmad Reza's avatar
Ahmad Reza committed
892
893
            if self.coords in self.world.tile_map_coords:
                self.carried_tile = self.world.tile_map_coords[self.coords]
Ahmad Reza's avatar
Ahmad Reza committed
894
895
                if self.carried_tile.take(coords=self.coords):
                    logging.info("Tile has been taken")
Ahmad Reza's avatar
Ahmad Reza committed
896
                    self.world.csv_round.update_metrics( tiles_taken=1)
Ahmad Reza's avatar
Ahmad Reza committed
897
898
899
900
901
902
                    self.csv_particle_writer.write_particle(tiles_taken=1)
                    return True
                else:
                    logging.info("Tile could not be taken")
                    return False
            else:
Ahmad Reza's avatar
Ahmad Reza committed
903
                logging.info("No tile on the actual position not in the world")
Ahmad Reza's avatar
Ahmad Reza committed
904
905
906
907
908
909
910
911
912
913
914
915
916
                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:
Ahmad Reza's avatar
Ahmad Reza committed
917
918
919
            if id in self.world.tile_map_id:
                logging.info("Tile with tile id %s is in the world", str(id))
                self.carried_tile = self.world.tile_map_id[id]
Ahmad Reza's avatar
Ahmad Reza committed
920
921
                if self.carried_tile.take(coords=self.coords):
                    logging.info("Tile with tile id %s  has been taken", str(id))
Ahmad Reza's avatar
Ahmad Reza committed
922
                    self.world.csv_round.update_metrics( tiles_taken=1)
Ahmad Reza's avatar
Ahmad Reza committed
923
924
925
926
927
928
                    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:
Ahmad Reza's avatar
Ahmad Reza committed
929
                logging.info("Tile with tile id %s is not in the world", str(id))
Ahmad Reza's avatar
Ahmad Reza committed
930
931
932
933
934
935
936
937
938
939
940
941
942
                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:
Ahmad Reza's avatar
Ahmad Reza committed
943
944
945
946
            coords = self.world.get_coords_in_dir(self.coords, dir)
            if coords in self.world.tile_map_coords:
                self.carried_tile = self.world.tile_map_coords[coords]
                logging.info("Tile with tile id %s is in the world", str(self.carried_tile.get_id()))
Ahmad Reza's avatar
Ahmad Reza committed
947
948
                if self.carried_tile.take(coords=self.coords):
                    logging.info("Tile with tile id %s  has been taken", str(self.carried_tile.get_id()))
Ahmad Reza's avatar
Ahmad Reza committed
949
                    self.world.csv_round.update_metrics( tiles_taken=1)
Ahmad Reza's avatar
Ahmad Reza committed
950
951
952
953
954
955
                    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:
Ahmad Reza's avatar
Ahmad Reza committed
956
                logging.info("Tile is not in the world")
Ahmad Reza's avatar
Ahmad Reza committed
957
958
959
960
961
962
963
964
965
966
967
968
969
970
                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:
971
            if check_coords(x, y):
Ahmad Reza's avatar
Ahmad Reza committed
972
                coords = (x, y)
Ahmad Reza's avatar
Ahmad Reza committed
973
974
975
                if coords in self.world.tile_map_coords:
                    self.carried_tile = self.world.tile_map_coords[coords]
                    logging.info("Tile with tile id %s is in the world", str(self.carried_tile.get_id()))
Ahmad Reza's avatar
Ahmad Reza committed
976
                    if self.carried_tile.take(coords=self.coords):
Ahmad Reza's avatar
Ahmad Reza committed
977
                        self.world.csv_round.update_metrics( tiles_taken=1)
Ahmad Reza's avatar
Ahmad Reza committed
978
979
980
981
982
983
984
                        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:
Ahmad Reza's avatar
Ahmad Reza committed
985
                    logging.info("Tile is not in the world")
Ahmad Reza's avatar
Ahmad Reza committed
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
                    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:
Ahmad Reza's avatar
Ahmad Reza committed
1001
            if self.coords not in self.world.tile_map_coords:
Ahmad Reza's avatar
Ahmad Reza committed
1002
1003
1004
1005
1006
1007
                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")
Ahmad Reza's avatar
Ahmad Reza committed
1008
                self.world.csv_round.update_metrics( tiles_dropped=1)
Ahmad Reza's avatar
Ahmad Reza committed
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
                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:
Ahmad Reza's avatar
Ahmad Reza committed
1024
1025
            coords = self.world.get_coords_in_dir(self.coords, dir)
            if coords not in self.world.tile_map_coords:
Ahmad Reza's avatar
Ahmad Reza committed
1026
1027
1028
1029
1030
                try:  # cher: insert so to overcome the AttributeError
                    self.carried_tile.drop_me(coords)
                except AttributeError:
                    pass
                self.carried_tile = None
Ahmad Reza's avatar
Ahmad Reza committed
1031
                self.world.csv_round.update_metrics( tiles_dropped=1)
Ahmad Reza's avatar
Ahmad Reza committed
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
                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:
1051
            if check_coords(x, y):
Ahmad Reza's avatar
Ahmad Reza committed
1052
                coords = (x, y)
Ahmad Reza's avatar
Ahmad Reza committed
1053
                if coords not in self.world.get_tile_map_coords():
Ahmad Reza's avatar
Ahmad Reza committed
1054
1055
1056
1057
1058
                    try:  # cher: insert so to overcome the AttributeError
                        self.carried_tile.drop_me(coords)
                    except AttributeError:
                        pass
                    self.carried_tile = None
Ahmad Reza's avatar
Ahmad Reza committed
1059
                    self.world.csv_round.update_metrics( tiles_dropped=1)
Ahmad Reza's avatar
Ahmad Reza committed
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
                    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
1077
        :return: New Particle or False
Ahmad Reza's avatar
Ahmad Reza committed
1078
1079
        """
        logging.info("Going to create on position %s", str(self.coords))
Ahmad Reza's avatar
Ahmad Reza committed
1080
        new_particle = self.world.add_particle(self.coords[0], self.coords[1], color, alpha)
Ahmad Reza's avatar
Ahmad Reza committed
1081
        if new_particle:
Ahmad Reza's avatar
Ahmad Reza committed
1082
            self.world.particle_map_coords[self.coords[0], self.coords[1]].created=True
Ahmad Reza's avatar
Ahmad Reza committed
1083
            self.csv_particle_writer.write_particle(particle_created=1)
Ahmad Reza's avatar
Ahmad Reza committed
1084
1085
            self.world.csv_round.update_particle_num(len(self.world.get_particle_list()))
            self.world.csv_round.update_metrics( particle_created=1)
Ahmad Reza's avatar
Ahmad Reza committed
1086
1087
1088
            return new_particle
        else:
            return False
Ahmad Reza's avatar
Ahmad Reza committed
1089
1090
1091
1092
1093
1094
1095
1096

    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
1097
        :return: New Particle or False
Ahmad Reza's avatar
Ahmad Reza committed
1098
1099
1100
        """
        coords = (0, 0)
        if dir is not None:
Ahmad Reza's avatar
Ahmad Reza committed
1101
            coords = self.world.get_coords_in_dir(self.coords, dir)
Ahmad Reza's avatar
Ahmad Reza committed
1102
            logging.info("Going to create a particle in %s on position %s", str(dir), str(coords))
Ahmad Reza's avatar
Ahmad Reza committed
1103
            new_particle= self.world.add_particle(coords[0], coords[1], color, alpha)
Ahmad Reza's avatar
Ahmad Reza committed
1104
            if new_particle:
Ahmad Reza's avatar
Ahmad Reza committed
1105
                self.world.particle_map_coords[coords[0], coords[1]].created = True
Ahmad Reza's avatar
Ahmad Reza committed
1106
                logging.info("Created particle on coords %s", coords)
Ahmad Reza's avatar
Ahmad Reza committed
1107
1108
                self.world.csv_round.update_particle_num(len(self.world.get_particle_list()))
                self.world.csv_round.update_metrics( particle_created=1)
Ahmad Reza's avatar
Ahmad Reza committed
1109
                self.csv_particle_writer.write_particle(particle_created=1)
Ahmad Reza's avatar
Ahmad Reza committed
1110
1111
1112
                return new_particle
            else:
                return False
Ahmad Reza's avatar
Ahmad Reza committed
1113
1114
        else:
            logging.info("Not created particle on coords %s", str(coords))
Ahmad Reza's avatar
Ahmad Reza committed
1115
            return False
Ahmad Reza's avatar
Ahmad Reza committed
1116
1117
1118
1119
1120
1121
1122
1123
1124

    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
1125
        :return: New Particle or False
Ahmad Reza's avatar
Ahmad Reza committed
1126
1127
1128
        """
        coords = (0, 0)
        if x is not None and y is not None:
1129
            if check_coords(x, y):
Ahmad Reza's avatar
Ahmad Reza committed
1130
1131
                coords = (x, y)
                logging.info("Going to create a particle on position %s", str(coords))
Ahmad Reza's avatar
Ahmad Reza committed
1132
                new_particle = self.world.add_particle(coords[0], coords[1], color, alpha)
Ahmad Reza's avatar
Ahmad Reza committed
1133
                if new_particle:
Ahmad Reza's avatar
Ahmad Reza committed
1134
                    self.world.particle_map_coords[coords[0], coords[1]].created = True
Ahmad Reza's avatar
Ahmad Reza committed
1135
                    logging.info("Created particle on coords %s", str(coords))
Ahmad Reza's avatar
Ahmad Reza committed
1136
1137
                    self.world.csv_round.update_particle_num(len(self.world.get_particle_list()))
                    self.world.csv_round.update_metrics( particle_created=1)
Ahmad Reza's avatar
Ahmad Reza committed
1138
                    self.csv_particle_writer.write_particle(particle_created=1)
Ahmad Reza's avatar
Ahmad Reza committed
1139
                    return new_particle
Ahmad Reza's avatar
Ahmad Reza committed
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
                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")
Ahmad Reza's avatar
Ahmad Reza committed
1156
1157
        if self.coords in self.world.get_particle_map_coords():
            if self.world.remove_particle_on(self.coords):
Ahmad Reza's avatar
Ahmad Reza committed
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
                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))
Ahmad Reza's avatar
Ahmad Reza committed
1173
        if self.world.remove_particle(id):
Ahmad Reza's avatar
Ahmad Reza committed
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
            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
1186
        if dir is not None:
Ahmad Reza's avatar
Ahmad Reza committed
1187
            coords = self.world.get_coords_in_dir(self.coords, dir)
Ahmad Reza's avatar
Ahmad Reza committed
1188
            logging.info("Deleting tile in %s direction", str(dir))
Ahmad Reza's avatar
Ahmad Reza committed
1189
            if self.world.remove_particle_on(coords):
Ahmad Reza's avatar
Ahmad Reza committed
1190
1191
1192
1193
                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
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203

    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:
1204
            if check_coords(x, y):
Ahmad Reza's avatar
Ahmad Reza committed
1205
                coords = (x, y)
Ahmad Reza's avatar
Ahmad Reza committed
1206
                if self.world.remove_particle_on(coords):
Ahmad Reza's avatar
Ahmad Reza committed
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
                    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:
Ahmad Reza's avatar
Ahmad Reza committed
1225
1226
            if self.coords in self.world.particle_map_coords:
                self.carried_particle = self.world.particle_map_coords[self.coords]
Ahmad Reza's avatar
Ahmad Reza committed
1227
1228
                if self.carried_particle.take_me(coords=self.coords):
                    logging.info("particle has been taken")
Ahmad Reza's avatar
Ahmad Reza committed
1229
                    self.world.csv_round.update_metrics( particles_taken=1)
Ahmad Reza's avatar
Ahmad Reza committed
1230
1231
1232
1233
1234
1235
                    self.csv_particle_writer.write_particle(particles_taken=1)
                    return True
                else:
                    logging.info("particle could not be taken")
                    return False
            else:
Ahmad Reza's avatar
Ahmad Reza committed
1236
                logging.info("No particle on the actual position not in the world")
Ahmad Reza's avatar
Ahmad Reza committed
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
                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:
Ahmad Reza's avatar
Ahmad Reza committed
1250
1251
1252
            if id in self.world.get_particle_map_id():
                logging.info("particle with particle id %s is in the world", str(id))
                self.carried_particle = self.world.particle_map_id[id]
Ahmad Reza's avatar
Ahmad Reza committed
1253
1254
1255
                if self.carried_particle.take_me(self.coords):
                    logging.info("particle with particle id %s  has been taken", str(id))

Ahmad Reza's avatar
Ahmad Reza committed
1256
                    self.world.csv_round.update_metrics(
Ahmad Reza's avatar
Ahmad Reza committed
1257
1258
1259
1260
1261
1262
1263
                                                               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: