particle.py 70.2 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"""
Ahmad Reza's avatar
Ahmad Reza committed
21
    def __init__(self, world, x, y, color=black, alpha=1):
22
        """Initializing the marker constructor"""
Ahmad Reza's avatar
Ahmad Reza committed
23
        super().__init__( world, (x, y), color, alpha, type="particle", mm_size=world.config_data.particle_mm_size)
Ahmad Reza's avatar
Ahmad Reza committed
24
25
26
27
28
29
30
31
32
33
34
35
        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)

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

39
    def sim_to_coords(self, x, y):
Ahmad Reza's avatar
Ahmad Reza committed
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
        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
        """
Ahmad Reza's avatar
Ahmad Reza committed
69
        if self.coords in self.world.tile_map_coords:
Ahmad Reza's avatar
Ahmad Reza committed
70
71
72
73
74
75
76
77
78
79
80
            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
81
        if self.coords in self.world.particle_map_coords:
Ahmad Reza's avatar
Ahmad Reza committed
82
83
84
85
            return True
        else:
            return False

86
    def check_on_marker(self):
Ahmad Reza's avatar
Ahmad Reza committed
87
        """
88
        Checks if the particle is on a marker
Ahmad Reza's avatar
Ahmad Reza committed
89

90
        :return: True: On a marker; False: Not on a marker
Ahmad Reza's avatar
Ahmad Reza committed
91
        """
Ahmad Reza's avatar
Ahmad Reza committed
92
        if self.coords in self.world.marker_map_coords:
Ahmad Reza's avatar
Ahmad Reza committed
93
94
95
96
97
98
99
100
101
102
103
            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
104
        dir_coord = self.world.get_coords_in_dir(self.coords, dir)
Ahmad Reza Cheraghi's avatar
Ahmad Reza Cheraghi committed
105
        dir, dir_coord = self.check_within_border(dir, dir_coord)
Ahmad Reza's avatar
Ahmad Reza committed
106
        if self.world.check_coords(dir_coord[0], dir_coord[1]):
Ahmad Reza's avatar
Ahmad Reza committed
107

Ahmad Reza's avatar
Ahmad Reza committed
108
109
            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
110

Ahmad Reza's avatar
Ahmad Reza committed
111
            if not dir_coord in self.world.particle_map_coords:
Ahmad Reza Cheraghi's avatar
Ahmad Reza Cheraghi committed
112
                self.coords = dir_coord
Ahmad Reza's avatar
Ahmad Reza committed
113
                self.world.particle_map_coords[self.coords] = self
Ahmad Reza's avatar
Ahmad Reza committed
114
                logging.info("particle %s successfully moved to %s", str(self.get_id()), dir)
Ahmad Reza's avatar
Ahmad Reza committed
115
                self.world.csv_round.update_metrics( steps=1)
Ahmad Reza's avatar
Ahmad Reza committed
116
117
                self.csv_particle_writer.write_particle(steps=1)
                self.touch()
Ahmad Reza Cheraghi's avatar
Ahmad Reza Cheraghi committed
118
                self.check_for_carried_tile_or_particle()
Ahmad Reza's avatar
Ahmad Reza committed
119
                return True
120
        return False
Ahmad Reza's avatar
Ahmad Reza committed
121

Ahmad Reza Cheraghi's avatar
Ahmad Reza Cheraghi committed
122
123
124
125
126
127
128
129
130
    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
131
132
        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
133
            dir = dir - 3 if dir > 2 else dir + 3
Ahmad Reza's avatar
Ahmad Reza committed
134
            dir_coord = self.world.get_coords_in_dir(self.coords, dir)
Ahmad Reza Cheraghi's avatar
Ahmad Reza Cheraghi committed
135
136
        return dir, dir_coord

Ahmad Reza's avatar
Ahmad Reza committed
137
138
139
140
141
142
143
    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
144
        dir_coord = self.world.get_coords_in_dir(self.coords, dir)
145
        sim_coord = self.coords_to_sim(dir_coord)
Ahmad Reza's avatar
Ahmad Reza committed
146
147
        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
148
149
150
151
152
153
154
155
            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):
        """
156
        Read the memories from the matters (paricle, tile, or marker object) memories with a given keyword
Ahmad Reza's avatar
Ahmad Reza committed
157

158
        :param matter: The matter can be either a particle, tile, or marker
Ahmad Reza's avatar
Ahmad Reza committed
159
160
161
162
163
164
165
166
167
168
        :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
169
                self.world.csv_round.update_metrics( particle_read=1)
Ahmad Reza's avatar
Ahmad Reza committed
170
171
                self.csv_particle_writer.write_particle(particle_read=1)
            elif matter.type == "tile":
Ahmad Reza's avatar
Ahmad Reza committed
172
                self.world.csv_round.update_metrics( tile_read=1)
Ahmad Reza's avatar
Ahmad Reza committed
173
                self.csv_particle_writer.write_particle(tile_read=1)
174
            elif matter.type == "marker":
Ahmad Reza's avatar
Ahmad Reza committed
175
                self.world.csv_round.update_metrics( marker_read=1)
176
                self.csv_particle_writer.write_particle(marker_read=1)
Ahmad Reza's avatar
Ahmad Reza committed
177
178
179
180
            return tmp_memory
        else:
            return None

Ahmad Reza Cheraghi's avatar
Ahmad Reza Cheraghi committed
181
182
183
184
185
    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
186
187
188
        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
189
190
191
            return True
        else:
            return False
Ahmad Reza's avatar
Ahmad Reza committed
192
193

    def tile_in(self, dir=E):
Ahmad Reza Cheraghi's avatar
Ahmad Reza Cheraghi committed
194
195
196
197
        """
        :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
198
        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
199
200
201
            return True
        else:
            return False
Ahmad Reza's avatar
Ahmad Reza committed
202
203

    def particle_in(self, dir=E):
Ahmad Reza Cheraghi's avatar
Ahmad Reza Cheraghi committed
204
205
206
207
        """
        :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
208
        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
209
210
211
            return True
        else:
            return False
Ahmad Reza's avatar
Ahmad Reza committed
212

213
    def marker_in(self, dir=E):
Ahmad Reza Cheraghi's avatar
Ahmad Reza Cheraghi committed
214
215
216
217
        """
        :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
218
        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
219
220
221
            return True
        else:
            return False
Ahmad Reza's avatar
Ahmad Reza committed
222

Ahmad Reza Cheraghi's avatar
Ahmad Reza Cheraghi committed
223
    def get_matter_in(self, dir=E):
Ahmad Reza's avatar
Ahmad Reza committed
224
225
226
227
228
229
        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
230
231
        else:
            return False
Ahmad Reza's avatar
Ahmad Reza committed
232
233

    def get_tile_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_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
236
237
        else:
            return False
Ahmad Reza's avatar
Ahmad Reza committed
238
239

    def get_particle_in(self, dir=E):
Ahmad Reza's avatar
Ahmad Reza committed
240
241
        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
242
243
        else:
            return False
Ahmad Reza's avatar
Ahmad Reza committed
244

245
    def get_marker_in(self, dir=E):
Ahmad Reza's avatar
Ahmad Reza committed
246
247
        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
248
249
        else:
            return False
Ahmad Reza's avatar
Ahmad Reza committed
250

251
    def get_marker(self):
Ahmad Reza's avatar
Ahmad Reza committed
252
253
        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
254
255
        else:
            return False
Ahmad Reza's avatar
Ahmad Reza committed
256

Ahmad Reza Cheraghi's avatar
Ahmad Reza Cheraghi committed
257
    def get_tile(self):
Ahmad Reza's avatar
Ahmad Reza committed
258
259
        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
260
261
        else:
            return False
Ahmad Reza's avatar
Ahmad Reza committed
262
263
264

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

267
        :param matter: The matter can be either a particle, tile, or marker
Ahmad Reza's avatar
Ahmad Reza committed
268
269
270
271
272
273
274
275
276
277
278
279
280
        :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
281
                    self.world.csv_round.update_metrics( particle_write=1)
Ahmad Reza's avatar
Ahmad Reza committed
282
283
                    self.csv_particle_writer.write_particle(particle_write=1)
                elif matter.type == "tile":
Ahmad Reza's avatar
Ahmad Reza committed
284
                    self.world.csv_round.update_metrics( tile_write=1)
Ahmad Reza's avatar
Ahmad Reza committed
285
                    self.csv_particle_writer.write_particle(tile_write=1)
286
                elif matter.type == "marker":
Ahmad Reza's avatar
Ahmad Reza committed
287
                    self.world.csv_round.update_metrics( marker_write=1)
288
                    self.csv_particle_writer.write_particle(marker_write=1)
Ahmad Reza's avatar
Ahmad Reza committed
289
290
291
292
293
294
                return True
            else:
                return False
        else:
            return False

Ahmad Reza's avatar
Ahmad Reza committed
295
296
    def scan_for_matter_within(self, matter='all', hop=1):
        """
297
        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
298
299
300

        :todo: If nothing then everything should be scanned

301
        :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
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
        :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):
        """
318
        Scanning for particles, tiles, or marker on a given hop distance
Ahmad Reza's avatar
Ahmad Reza committed
319

320
        :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
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
        :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
337
338
339
340
                    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)])
341
                elif matter == "markers":
Ahmad Reza's avatar
Ahmad Reza committed
342
343
344
345
                    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
346
                elif matter == "tiles":
Ahmad Reza's avatar
Ahmad Reza committed
347
348
349
350
                    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
351
                elif matter == "all":
Ahmad Reza Cheraghi's avatar
Ahmad Reza Cheraghi committed
352

Ahmad Reza's avatar
Ahmad Reza committed
353
354
355
356
357
358
359
360
361
362
363
364
                    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
365
366
367
368
                else:
                    logging.info("No matter specified")
            else:
                if matter == "particles":
Ahmad Reza's avatar
Ahmad Reza committed
369
370
371
372
373
374
375
376
                    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)])
377
                elif matter == "markers":
Ahmad Reza's avatar
Ahmad Reza committed
378
379
380
381
382
383
384
385
                    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
386
                elif matter == "tiles":
Ahmad Reza's avatar
Ahmad Reza committed
387
388
389
390
391
392
393
394
                    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
395
                elif matter == "all":
Ahmad Reza's avatar
Ahmad Reza committed
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
                    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
422
423
424
425
426
427
428
429
430
431
432
433

                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
434
435
436
437
                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)])
438
            elif matter == "markers":
Ahmad Reza's avatar
Ahmad Reza committed
439
440
441
442
                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
443
            elif matter == "tiles":
Ahmad Reza's avatar
Ahmad Reza committed
444
445
446
447
                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
448
449
            if matter == "all":
                if hop == 0:
Ahmad Reza's avatar
Ahmad Reza committed
450
451
452
453
454
455
                    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
456
                else:
Ahmad Reza's avatar
Ahmad Reza committed
457
458
459
460
                    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
461

Ahmad Reza's avatar
Ahmad Reza committed
462
463
464
465
                    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
466

Ahmad Reza's avatar
Ahmad Reza committed
467
468
469
470
                    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
471
472
473
474
475
476
477
478
479
480
481
482
483
484

            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):
        """
485
        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
486
487
488

        :todo: If nothing then everything should be scanned

489
        :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
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
        :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):
        """
506
        Scanning for particles, tiles, or marker on a given hop distance
Ahmad Reza's avatar
Ahmad Reza committed
507

508
        :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
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
        :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
524
525
526
527
528
529
                # 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
530
            else:
Ahmad Reza's avatar
Ahmad Reza committed
531
532
533
534
535
536
537
538
                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
539
540
541
542
543
544
545
546
            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
547
548
549
550
            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
551
552
553
554
555
556
557
558
559
560
561
            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):
        """
562
        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
563
564
565

        :todo: If nothing then everything should be scanned

566
        :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
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
        :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):
        """
583
        Scanning for particles, tiles, or marker on a given hop distance
Ahmad Reza's avatar
Ahmad Reza committed
584

585
        :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
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
        :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
601
602
603
604
605
606
                # 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
607
            else:
Ahmad Reza's avatar
Ahmad Reza committed
608
609
610
611
612
613
614
615
                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
616
617
618
619
620
621
622
623
            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
624
625
626
627
            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
628
629
630
631
632
633
634
635
636
            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

637
    def scan_for_marker_within(self, hop=1):
Ahmad Reza's avatar
Ahmad Reza committed
638
        """
639
        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
640
641
642

        :todo: If nothing then everything should be scanned

643
        :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
644
645
646
647
648
649
        :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):
650
            list = self.scan_for_marker_in(i)
Ahmad Reza's avatar
Ahmad Reza committed
651
652
653
654
655
656
657
            if list != None:
                hop_list.extend(list)
        if len(hop_list) != 0:
            return hop_list
        else:
            return None

658
    def scan_for_marker_in(self, hop=1):
Ahmad Reza's avatar
Ahmad Reza committed
659
        """
660
        Scanning for particles, tiles, or marker on a given hop distance
Ahmad Reza's avatar
Ahmad Reza committed
661

662
        :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
663
664
665
666
        :param hop: The hop distance from thee actual position of the scanning particle
        :return: A list of the founded matters
        """
        hop_list = []
667
        logging.info("particle is scanning for marker in %i hops", hop)
Ahmad Reza's avatar
Ahmad Reza committed
668
669
670
671
672
673
674
675
676
677
        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
678
679
680
681
682
683
                # 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
684
685
            else:

Ahmad Reza's avatar
Ahmad Reza committed
686
687
688
689
690
691
692
693
                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
694
695
696
697
698
699
700
701
            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
702
703
704
705
            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
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
            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
724
725
            if self.coords in self.world.particle_map_coords:
                del self.world.particle_map_coords[self.coords]
Ahmad Reza's avatar
Ahmad Reza committed
726
727
            self.__isCarried = True
            self.coords = coords
728
            self.set_alpha(0.5)
Ahmad Reza's avatar
Ahmad Reza committed
729
730
731
732
733
734
735
736
737
738
739
740
            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
741
        self.world.particle_map_coords[coords] = self
Ahmad Reza's avatar
Ahmad Reza committed
742
743
        self.coords = coords
        self.__isCarried = False
744
        self.set_alpha(1)
Ahmad Reza's avatar
Ahmad Reza committed
745
746
747
748
749
750
        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
751
        :return: New Tile or False
Ahmad Reza's avatar
Ahmad Reza committed
752
753
        """
        logging.info("Going to create a tile on position %s", str(self.coords))
Ahmad Reza's avatar
Ahmad Reza committed
754
        new_tile = self.world.add_tile(self.coords[0], self.coords[1], color, alpha)
Ahmad Reza's avatar
Ahmad Reza committed
755
        if new_tile:
Ahmad Reza's avatar
Ahmad Reza committed
756
            self.world.tile_map_coords[self.coords[0], self.coords[1]].created = True
Ahmad Reza's avatar
Ahmad Reza committed
757
            self.csv_particle_writer.write_particle(tile_created=1)
Ahmad Reza's avatar
Ahmad Reza committed
758
759
            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
760
761
762
            return new_tile
        else:
            return False
Ahmad Reza's avatar
Ahmad Reza committed
763
764
765
766
767
768

    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
769
        :return: New tile or False
Ahmad Reza's avatar
Ahmad Reza committed
770
771
772
773
        """
        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
774
775
            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
776
            if new_tile:
Ahmad Reza's avatar
Ahmad Reza committed
777
                self.world.tile_map_coords[coords[0], coords[1]].created = True
Ahmad Reza's avatar
Ahmad Reza committed
778
                logging.info("Tile is created")
Ahmad Reza's avatar
Ahmad Reza committed
779
                self.world.new_tile_flag = True
Ahmad Reza's avatar
Ahmad Reza committed
780
                self.csv_particle_writer.write_particle(tile_created=1)
Ahmad Reza's avatar
Ahmad Reza committed
781
782
                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
783
784
785
                return new_tile
            else:
                return False
Ahmad Reza's avatar
Ahmad Reza committed
786
787
        else:
            logging.info("Not created tile ")
Ahmad Reza's avatar
Ahmad Reza committed
788
            return False
Ahmad Reza's avatar
Ahmad Reza committed
789
790
791
792
793
794
795

    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
796
        :return: New Tile or False
Ahmad Reza's avatar
Ahmad Reza committed
797
798
799
800
801
        """

        logging.info("particle with id %s is", self.get_id())
        if x is not None and y is not None:
            coords = (x, y)
Ahmad Reza's avatar
Ahmad Reza committed
802
            if self.world.check_coords(x,y):
Ahmad Reza's avatar
Ahmad Reza committed
803
                logging.info("Going to create a tile on position \(%i , %i\)", x,y )
Ahmad Reza's avatar
Ahmad Reza committed
804
805
806
                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
807
                    self.csv_particle_writer.write_particle(tile_created=1)
Ahmad Reza's avatar
Ahmad Reza committed
808
809
                    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
810
811
812
813
814
815
                    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
816
                return False
Ahmad Reza's avatar
Ahmad Reza committed
817
818
819
820
821
822
823
824
825

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

    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
1109
        :return: New Particle or False
Ahmad Reza's avatar
Ahmad Reza committed
1110
1111
1112
        """
        coords = (0, 0)
        if dir is not None:
Ahmad Reza's avatar
Ahmad Reza committed
1113
            coords = self.world.get_coords_in_dir(self.coords, dir)
Ahmad Reza's avatar
Ahmad Reza committed
1114
            logging.info("Going to create a particle in %s on position %s", str(dir), str(coords))
Ahmad Reza's avatar
Ahmad Reza committed
1115
            new_particle= self.world.add_particle(coords[0], coords[1], color, alpha)
Ahmad Reza's avatar
Ahmad Reza committed
1116
            if new_particle:
Ahmad Reza's avatar
Ahmad Reza committed
1117
                self.world.particle_map_coords[coords[0], coords[1]].created = True
Ahmad Reza's avatar
Ahmad Reza committed
1118
                logging.info("Created particle on coords %s", coords)
Ahmad Reza's avatar
Ahmad Reza committed
1119
1120
                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
1121
                self.csv_particle_writer.write_particle(particle_created=1)
Ahmad Reza's avatar
Ahmad Reza committed
1122
1123
1124
                return new_particle
            else:
                return False
Ahmad Reza's avatar
Ahmad Reza committed
1125
1126
        else:
            logging.info("Not created particle on coords %s", str(coords))
Ahmad Reza's avatar
Ahmad Reza committed
1127
            return False
Ahmad Reza's avatar
Ahmad Reza committed
1128
1129
1130
1131
1132
1133
1134
1135
1136

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

    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:
Ahmad Reza's avatar
Ahmad Reza committed
1216
            if self.world.check_coords(x, y):
Ahmad Reza's avatar
Ahmad Reza committed
1217
                coords = (x, y)
Ahmad Reza's avatar
Ahmad Reza committed
1218
                if self.world.remove_particle_on(coords):
Ahmad Reza's avatar
Ahmad Reza committed
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
                    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
1237
1238
            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
1239
1240
                if self.carried_particle.take_me(coords=self.coords):
                    logging.info("particle has been taken")
Ahmad Reza's avatar
Ahmad Reza committed
1241
                    self.world.csv_round.update_metrics( particles_taken=1)
Ahmad Reza's avatar
Ahmad Reza committed
1242
1243
1244
1245
1246
1247
                    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
1248
                logging.info("No particle on the actual position not in the world")
Ahmad Reza's avatar
Ahmad Reza committed
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
                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
1262
1263
1264
            if id in