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

.. moduleauthor:: Ahmad Reza Cheraghi

TODO: Erase Memory

"""

import logging, math
from lib import csv_generator, matter

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


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


read = 0
write = 1
particle_counter=0

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

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

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

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

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

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


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

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

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

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


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

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

106
    def check_on_marker(self):
Ahmad Reza's avatar
Ahmad Reza committed
107
        """
108
        Checks if the particle is on a marker
Ahmad Reza's avatar
Ahmad Reza committed
109

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

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

        :param dir: The direction must be either: E, SE, SW, W, NW, or NE
        :return: True: Success Moving;  False: Non moving
        """
124
        dir_coord = self.sim.get_coords_in_dir(self.coords, dir)
Ahmad Reza Cheraghi's avatar
Ahmad Reza Cheraghi committed
125
        dir, dir_coord = self.check_within_border(dir, dir_coord)
126
        if self.sim.check_coords(dir_coord[0], dir_coord[1]):
Ahmad Reza's avatar
Ahmad Reza committed
127

128
            if self.coords in self.sim.particle_map_coords:
129
                del self.sim.particle_map_coords[self.coords]
Ahmad Reza Cheraghi's avatar
Ahmad Reza Cheraghi committed
130
131
132

            if not dir_coord in self.sim.particle_map_coords:
                self.coords = dir_coord
133
                self.sim.particle_map_coords[self.coords] = self
Ahmad Reza's avatar
Ahmad Reza committed
134
                logging.info("particle %s successfully moved to %s", str(self.get_id()), dir)
Ahmad Reza's avatar
Ahmad Reza committed
135
                self.sim.csv_round_writer.update_metrics( steps=1)
Ahmad Reza's avatar
Ahmad Reza committed
136
137
                self.csv_particle_writer.write_particle(steps=1)
                self.touch()
Ahmad Reza Cheraghi's avatar
Ahmad Reza Cheraghi committed
138
                self.check_for_carried_tile_or_particle()
Ahmad Reza's avatar
Ahmad Reza committed
139
                return True
140
        return False
Ahmad Reza's avatar
Ahmad Reza committed
141

Ahmad Reza Cheraghi's avatar
Ahmad Reza Cheraghi committed
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
    def check_for_carried_tile_or_particle(self):
        if self.carried_tile is not None:
            self.carried_tile.coords = self.coords
            self.carried_tile.touch()
        elif self.carried_particle is not None:
            self.carried_particle.coords = self.coords
            self.carried_particle.touch()

    def check_within_border(self, dir, dir_coord):
        if self.sim.border == 1 and \
                (abs(dir_coord[0]) > self.sim.get_sim_x_size() or abs(dir_coord[1]) > self.sim.get_sim_y_size()):
            dir = dir - 3 if dir > 2 else dir + 3
            dir_coord = self.sim.get_coords_in_dir(self.coords, dir)
        return dir, dir_coord

Ahmad Reza's avatar
Ahmad Reza committed
157
158
159
160
161
162
163
    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
        """
164
165
166
167
        dir_coord = self.sim.get_coords_in_dir(self.coords, dir)
        sim_coord = self.coords_to_sim(dir_coord)
        if self.sim.get_sim_x_size() >=  abs(sim_coord[0]) and \
                        self.sim.get_sim_y_size() >=  abs(sim_coord[1]):
Ahmad Reza's avatar
Ahmad Reza committed
168
169
170
171
172
173
174
175
            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):
        """
176
        Read the memories from the matters (paricle, tile, or marker object) memories with a given keyword
Ahmad Reza's avatar
Ahmad Reza committed
177

178
        :param matter: The matter can be either a particle, tile, or marker
Ahmad Reza's avatar
Ahmad Reza committed
179
180
181
182
183
184
185
186
187
188
        :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":
189
                self.sim.csv_round_writer.update_metrics( particle_read=1)
Ahmad Reza's avatar
Ahmad Reza committed
190
191
                self.csv_particle_writer.write_particle(particle_read=1)
            elif matter.type == "tile":
192
                self.sim.csv_round_writer.update_metrics( tile_read=1)
Ahmad Reza's avatar
Ahmad Reza committed
193
                self.csv_particle_writer.write_particle(tile_read=1)
194
195
196
            elif matter.type == "marker":
                self.sim.csv_round_writer.update_metrics( marker_read=1)
                self.csv_particle_writer.write_particle(marker_read=1)
Ahmad Reza's avatar
Ahmad Reza committed
197
198
199
200
            return tmp_memory
        else:
            return None

Ahmad Reza Cheraghi's avatar
Ahmad Reza Cheraghi committed
201
202
203
204
205
206
207
208
209
210
211
    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
        """
        if  self.sim.get_coords_in_dir(self.coords, dir) in self.sim.get_tile_map_coords() \
            or self.sim.get_coords_in_dir(self.coords, dir) in self.sim.get_particle_map_coords() \
            or self.sim.get_coords_in_dir(self.coords, dir) in self.sim.get_marker_map_coords():
            return True
        else:
            return False
Ahmad Reza's avatar
Ahmad Reza committed
212
213

    def tile_in(self, dir=E):
Ahmad Reza Cheraghi's avatar
Ahmad Reza Cheraghi committed
214
215
216
217
218
219
220
221
        """
        :param dir: the direction to check if a tile is there
        :return: True: if a tile is there, False: if not
        """
        if self.sim.get_coords_in_dir(self.coords, dir) in self.sim.get_tile_map_coords():
            return True
        else:
            return False
Ahmad Reza's avatar
Ahmad Reza committed
222
223

    def particle_in(self, dir=E):
Ahmad Reza Cheraghi's avatar
Ahmad Reza Cheraghi committed
224
225
226
227
228
229
230
231
        """
        :param dir: the direction to check if a particle is there
        :return: True: if a particle is there, False: if not
        """
        if self.sim.get_coords_in_dir(self.coords, dir) in self.sim.get_particle_map_coords():
            return True
        else:
            return False
Ahmad Reza's avatar
Ahmad Reza committed
232

233
    def marker_in(self, dir=E):
Ahmad Reza Cheraghi's avatar
Ahmad Reza Cheraghi committed
234
235
236
237
238
239
240
241
        """
        :param dir: the direction to check if a marker is there
        :return: True: if a marker is there, False: if not
        """
        if self.sim.get_coords_in_dir(self.coords, dir) in self.sim.get_marker_map_coords():
            return True
        else:
            return False
Ahmad Reza's avatar
Ahmad Reza committed
242

Ahmad Reza Cheraghi's avatar
Ahmad Reza Cheraghi committed
243
244
245
246
247
248
249
250
251
    def get_matter_in(self, dir=E):
        if self.sim.get_coords_in_dir(self.coords, dir) in self.sim.get_tile_map_coords():
            return self.sim.get_tile_map_coords()[self.sim.get_coords_in_dir(self.coords, dir)]
        elif self.sim.get_coords_in_dir(self.coords, dir) in self.sim.get_particle_map_coords():
            return self.sim.get_particle_map_coords()[self.sim.get_coords_in_dir(self.coords, dir)]
        elif self.sim.get_coords_in_dir(self.coords, dir) in self.sim.get_marker_map_coords():
            return self.sim.get_marker_map_coords()[self.sim.get_coords_in_dir(self.coords, dir)]
        else:
            return False
Ahmad Reza's avatar
Ahmad Reza committed
252
253

    def get_tile_in(self, dir=E):
254
255
        if self.sim.get_coords_in_dir(self.coords, dir) in self.sim.get_tile_map_coords():
            return self.sim.get_tile_map_coords()[self.sim.get_coords_in_dir(self.coords, dir)]
Ahmad Reza Cheraghi's avatar
Ahmad Reza Cheraghi committed
256
257
        else:
            return False
Ahmad Reza's avatar
Ahmad Reza committed
258
259

    def get_particle_in(self, dir=E):
260
261
        if self.sim.get_coords_in_dir(self.coords, dir) in self.sim.get_particle_map_coords():
            return self.sim.get_particle_map_coords()[self.sim.get_coords_in_dir(self.coords, dir)]
Ahmad Reza Cheraghi's avatar
Ahmad Reza Cheraghi committed
262
263
        else:
            return False
Ahmad Reza's avatar
Ahmad Reza committed
264

265
266
267
    def get_marker_in(self, dir=E):
        if self.sim.get_coords_in_dir(self.coords, dir) in self.sim.get_marker_map_coords():
            return self.sim.get_marker_map_coords()[self.sim.get_coords_in_dir(self.coords, dir)]
Ahmad Reza Cheraghi's avatar
Ahmad Reza Cheraghi committed
268
269
        else:
            return False
Ahmad Reza's avatar
Ahmad Reza committed
270

271
272
273
    def get_marker(self):
        if self.coords in self.sim.marker_map_coords:
            return self.sim.get_marker_map_coords()[self.coords]
Ahmad Reza Cheraghi's avatar
Ahmad Reza Cheraghi committed
274
275
        else:
            return False
Ahmad Reza's avatar
Ahmad Reza committed
276

Ahmad Reza Cheraghi's avatar
Ahmad Reza Cheraghi committed
277
278
279
    def get_tile(self):
        if self.self.coords in self.sim.get_tile_map_coords():
            return self.sim.get_tile_map_coords()[self.coords]
Ahmad Reza Cheraghi's avatar
Ahmad Reza Cheraghi committed
280
281
        else:
            return False
Ahmad Reza's avatar
Ahmad Reza committed
282
283
284

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

287
        :param matter: The matter can be either a particle, tile, or marker
Ahmad Reza's avatar
Ahmad Reza committed
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
        :param key: A string keyword so to order the data that is written into the memory
        :param data: The data that should be stored into the memory
        :return: True: Successful written into the memory; False: Unsuccessful
        """
        wrote=False
        if data != None:
            wrote=False
            if key==None:
                wrote=matter.write_memory(data)
            else:
                wrote= matter.write_memory_with(key, data)
            if  wrote==True:
                if matter.type == "particle":
                    self.sim.csv_round_writer.update_metrics( particle_write=1)
                    self.csv_particle_writer.write_particle(particle_write=1)
                elif matter.type == "tile":
                    self.sim.csv_round_writer.update_metrics( tile_write=1)
                    self.csv_particle_writer.write_particle(tile_write=1)
306
307
308
                elif matter.type == "marker":
                    self.sim.csv_round_writer.update_metrics( marker_write=1)
                    self.csv_particle_writer.write_particle(marker_write=1)
Ahmad Reza's avatar
Ahmad Reza committed
309
310
311
312
313
314
                return True
            else:
                return False
        else:
            return False

Ahmad Reza's avatar
Ahmad Reza committed
315
316
    def scan_for_matter_within(self, matter='all', hop=1):
        """
317
        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
318
319
320

        :todo: If nothing then everything should be scanned

321
        :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
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
        :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):
        """
338
        Scanning for particles, tiles, or marker on a given hop distance
Ahmad Reza's avatar
Ahmad Reza committed
339

340
        :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
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
        :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":
357
358
359
360
                    if (x_scan_pos, y_scan_coord_neg) in self.sim.particle_map_coords:
                        hop_list.append(self.sim.particle_map_coords[(x_scan_pos, y_scan_coord_neg)])
                    if (x_scan_neg, y_scan_coord_neg) in self.sim.particle_map_coords:
                        hop_list.append(self.sim.particle_map_coords[(x_scan_neg, y_scan_coord_neg)])
361
362
363
364
365
                elif matter == "markers":
                    if (x_scan_pos, y_scan_coord_neg) in self.sim.marker_map_coords:
                        hop_list.append(self.sim.marker_map_coords[(x_scan_pos, y_scan_coord_neg)])
                    if (x_scan_neg, y_scan_coord_neg) in self.sim.marker_map_coords:
                        hop_list.append(self.sim.marker_map_coords[(x_scan_neg, y_scan_coord_neg)])
Ahmad Reza's avatar
Ahmad Reza committed
366
                elif matter == "tiles":
367
368
369
370
                    if (x_scan_pos, y_scan_coord_neg) in self.sim.tile_map_coords:
                        hop_list.append(self.sim.tile_map_coords[(x_scan_pos, y_scan_coord_neg)])
                    if (x_scan_neg, y_scan_coord_neg) in self.sim.tile_map_coords:
                        hop_list.append(self.sim.tile_map_coords[(x_scan_neg, y_scan_coord_neg)])
Ahmad Reza's avatar
Ahmad Reza committed
371
                elif matter == "all":
Ahmad Reza Cheraghi's avatar
Ahmad Reza Cheraghi committed
372

373
374
375
376
                    if (x_scan_pos, y_scan_coord_neg) in self.sim.tile_map_coords:
                        hop_list.append(self.sim.tile_map_coords[(x_scan_pos, y_scan_coord_neg)])
                    if (x_scan_neg, y_scan_coord_neg) in self.sim.tile_map_coords:
                        hop_list.append(self.sim.tile_map_coords[(x_scan_neg, y_scan_coord_neg)])
377
378
379
380
                    if (x_scan_pos, y_scan_coord_neg) in self.sim.marker_map_coords:
                        hop_list.append(self.sim.marker_map_coords[(x_scan_pos, y_scan_coord_neg)])
                    if (x_scan_neg, y_scan_coord_neg) in self.sim.marker_map_coords:
                        hop_list.append(self.sim.marker_map_coords[(x_scan_neg, y_scan_coord_neg)])
381
382
383
384
                    if (x_scan_pos, y_scan_coord_neg) in self.sim.particle_map_coords:
                        hop_list.append(self.sim.particle_map_coords[(x_scan_pos, y_scan_coord_neg)])
                    if (x_scan_neg, y_scan_coord_neg) in self.sim.particle_map_coords:
                        hop_list.append(self.sim.particle_map_coords[(x_scan_neg, y_scan_coord_neg)])
Ahmad Reza's avatar
Ahmad Reza committed
385
386
387
388
                else:
                    logging.info("No matter specified")
            else:
                if matter == "particles":
389
390
391
392
393
394
395
396
                    if (x_scan_pos, y_scan_coord_pos) in self.sim.particle_map_coords:
                        hop_list.append(self.sim.particle_map_coords[(x_scan_pos, y_scan_coord_pos)])
                    if (x_scan_pos, y_scan_coord_neg) in self.sim.particle_map_coords:
                        hop_list.append(self.sim.particle_map_coords[(x_scan_pos, y_scan_coord_neg)])
                    if (x_scan_neg, y_scan_coord_pos) in self.sim.particle_map_coords:
                        hop_list.append(self.sim.particle_map_coords[(x_scan_neg, y_scan_coord_pos)])
                    if (x_scan_neg, y_scan_coord_neg) in self.sim.particle_map_coords:
                        hop_list.append(self.sim.particle_map_coords[(x_scan_neg, y_scan_coord_neg)])
397
398
399
400
401
402
403
404
405
                elif matter == "markers":
                    if (x_scan_pos, y_scan_coord_pos) in self.sim.marker_map_coords:
                        hop_list.append(self.sim.marker_map_coords[(x_scan_pos, y_scan_coord_pos)])
                    if (x_scan_pos, y_scan_coord_neg) in self.sim.marker_map_coords:
                        hop_list.append(self.sim.marker_map_coords[(x_scan_pos, y_scan_coord_neg)])
                    if (x_scan_neg, y_scan_coord_pos) in self.sim.marker_map_coords:
                        hop_list.append(self.sim.marker_map_coords[(x_scan_neg, y_scan_coord_pos)])
                    if (x_scan_neg, y_scan_coord_neg) in self.sim.marker_map_coords:
                        hop_list.append(self.sim.marker_map_coords[(x_scan_neg, y_scan_coord_neg)])
Ahmad Reza's avatar
Ahmad Reza committed
406
                elif matter == "tiles":
407
408
409
410
411
412
413
414
                    if (x_scan_pos, y_scan_coord_pos) in self.sim.tile_map_coords:
                        hop_list.append(self.sim.tile_map_coords[(x_scan_pos, y_scan_coord_pos)])
                    if (x_scan_pos, y_scan_coord_neg) in self.sim.tile_map_coords:
                        hop_list.append(self.sim.tile_map_coords[(x_scan_pos, y_scan_coord_neg)])
                    if (x_scan_pos, y_scan_coord_neg) in self.sim.tile_map_coords:
                        hop_list.append(self.sim.tile_map_coords[(x_scan_pos, y_scan_coord_neg)])
                    if (x_scan_neg, y_scan_coord_neg) in self.sim.tile_map_coords:
                        hop_list.append(self.sim.tile_map_coords[(x_scan_neg, y_scan_coord_neg)])
Ahmad Reza's avatar
Ahmad Reza committed
415
                elif matter == "all":
416
417
418
419
420
421
422
423
424
                    if (x_scan_pos, y_scan_coord_pos) in self.sim.particle_map_coords:
                        hop_list.append(self.sim.particle_map_coords[(x_scan_pos, y_scan_coord_pos)])
                    if (x_scan_pos, y_scan_coord_neg) in self.sim.particle_map_coords:
                        hop_list.append(self.sim.particle_map_coords[(x_scan_pos, y_scan_coord_neg)])
                    if (x_scan_neg, y_scan_coord_pos) in self.sim.particle_map_coords:
                        hop_list.append(self.sim.particle_map_coords[(x_scan_neg, y_scan_coord_pos)])
                    if (x_scan_neg, y_scan_coord_neg) in self.sim.particle_map_coords:
                        hop_list.append(self.sim.particle_map_coords[(x_scan_neg, y_scan_coord_neg)])

425
426
427
428
429
430
431
432
                    if (x_scan_pos, y_scan_coord_pos) in self.sim.marker_map_coords:
                        hop_list.append(self.sim.marker_map_coords[(x_scan_pos, y_scan_coord_pos)])
                    if (x_scan_pos, y_scan_coord_neg) in self.sim.marker_map_coords:
                        hop_list.append(self.sim.marker_map_coords[(x_scan_pos, y_scan_coord_neg)])
                    if (x_scan_neg, y_scan_coord_pos) in self.sim.marker_map_coords:
                        hop_list.append(self.sim.marker_map_coords[(x_scan_neg, y_scan_coord_pos)])
                    if (x_scan_neg, y_scan_coord_neg) in self.sim.marker_map_coords:
                        hop_list.append(self.sim.marker_map_coords[(x_scan_neg, y_scan_coord_neg)])
433
434
435
436
437
438
439
440
441

                    if (x_scan_pos, y_scan_coord_pos) in self.sim.tile_map_coords:
                        hop_list.append(self.sim.tile_map_coords[(x_scan_pos, y_scan_coord_pos)])
                    if (x_scan_pos, y_scan_coord_neg) in self.sim.tile_map_coords:
                        hop_list.append(self.sim.tile_map_coords[(x_scan_pos, y_scan_coord_neg)])
                    if (x_scan_pos, y_scan_coord_neg) in self.sim.tile_map_coords:
                        hop_list.append(self.sim.tile_map_coords[(x_scan_pos, y_scan_coord_neg)])
                    if (x_scan_neg, y_scan_coord_neg) in self.sim.tile_map_coords:
                        hop_list.append(self.sim.tile_map_coords[(x_scan_neg, y_scan_coord_neg)])
Ahmad Reza's avatar
Ahmad Reza committed
442
443
444
445
446
447
448
449
450
451
452
453

                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":
454
455
456
457
                if (x_upper_scan, y_up_scan) in self.sim.particle_map_coords:
                    hop_list.append(self.sim.particle_map_coords[(x_upper_scan, y_up_scan)])
                if (x_upper_scan, y_down_scan) in self.sim.particle_map_coords:
                    hop_list.append(self.sim.particle_map_coords[(x_upper_scan, y_down_scan)])
458
459
460
461
462
            elif matter == "markers":
                if (x_upper_scan, y_up_scan) in self.sim.marker_map_coords:
                    hop_list.append(self.sim.marker_map_coords[(x_upper_scan, y_up_scan)])
                if (x_upper_scan, y_down_scan) in self.sim.marker_map_coords:
                    hop_list.append(self.sim.marker_map_coords[(x_upper_scan, y_down_scan)])
Ahmad Reza's avatar
Ahmad Reza committed
463
            elif matter == "tiles":
464
465
466
467
                if (x_upper_scan, y_up_scan) in self.sim.tile_map_coords:
                    hop_list.append(self.sim.tile_map_coords[(x_upper_scan, y_up_scan)])
                if (x_upper_scan, y_down_scan) in self.sim.tile_map_coords:
                    hop_list.append(self.sim.tile_map_coords[(x_upper_scan, y_down_scan)])
Ahmad Reza's avatar
Ahmad Reza committed
468
469
            if matter == "all":
                if hop == 0:
470
471
                    if (0, 0) in self.sim.particle_map_coords:
                        hop_list.append(self.sim.particle_map_coords[(0, 0)])
472
473
                    if (0, 0) in self.sim.marker_map_coords:
                        hop_list.append(self.sim.marker_map_coords[(0, 0)])
474
475
                    if (0, 0) in self.sim.tile_map_coords:
                        hop_list.append(self.sim.tile_map_coords[(0, 0)])
Ahmad Reza's avatar
Ahmad Reza committed
476
                else:
477
478
479
480
                    if (x_upper_scan, y_up_scan) in self.sim.particle_map_coords:
                        hop_list.append(self.sim.particle_map_coords[(x_upper_scan, y_up_scan)])
                    if (x_upper_scan, y_down_scan) in self.sim.particle_map_coords:
                        hop_list.append(self.sim.particle_map_coords[(x_upper_scan, y_down_scan)])
Ahmad Reza's avatar
Ahmad Reza committed
481

482
483
484
485
                    if (x_upper_scan, y_up_scan) in self.sim.marker_map_coords:
                        hop_list.append(self.sim.marker_map_coords[(x_upper_scan, y_up_scan)])
                    if (x_upper_scan, y_down_scan) in self.sim.marker_map_coords:
                        hop_list.append(self.sim.marker_map_coords[(x_upper_scan, y_down_scan)])
Ahmad Reza's avatar
Ahmad Reza committed
486

487
488
489
490
                    if (x_upper_scan, y_up_scan) in self.sim.tile_map_coords:
                        hop_list.append(self.sim.tile_map_coords[(x_upper_scan, y_up_scan)])
                    if (x_upper_scan, y_down_scan) in self.sim.tile_map_coords:
                        hop_list.append(self.sim.tile_map_coords[(x_upper_scan, y_down_scan)])
Ahmad Reza's avatar
Ahmad Reza committed
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506

            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):
        """
507
        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
508
509
510

        :todo: If nothing then everything should be scanned

511
        :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
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
        :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):
        """
528
        Scanning for particles, tiles, or marker on a given hop distance
Ahmad Reza's avatar
Ahmad Reza committed
529

530
        :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
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
        :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:
546
547
548
549
550
551
                # if self.coords in self.sim.particle_map_coords:
                #     hop_list.append(self.sim.particle_map_coords[self.coords])
                if (x_scan_pos, y_scan_coord_neg) in self.sim.particle_map_coords:
                    hop_list.append(self.sim.particle_map_coords[(x_scan_pos, y_scan_coord_neg)])
                if (x_scan_neg, y_scan_coord_neg) in self.sim.particle_map_coords:
                    hop_list.append(self.sim.particle_map_coords[(x_scan_neg, y_scan_coord_neg)])
Ahmad Reza's avatar
Ahmad Reza committed
552
            else:
553
554
555
556
557
558
559
560
                if (x_scan_pos, y_scan_coord_pos) in self.sim.particle_map_coords:
                    hop_list.append(self.sim.particle_map_coords[(x_scan_pos, y_scan_coord_pos)])
                if (x_scan_pos, y_scan_coord_neg) in self.sim.particle_map_coords:
                    hop_list.append(self.sim.particle_map_coords[(x_scan_pos, y_scan_coord_neg)])
                if (x_scan_neg, y_scan_coord_pos) in self.sim.particle_map_coords:
                    hop_list.append(self.sim.particle_map_coords[(x_scan_neg, y_scan_coord_pos)])
                if (x_scan_neg, y_scan_coord_neg) in self.sim.particle_map_coords:
                    hop_list.append(self.sim.particle_map_coords[(x_scan_neg, y_scan_coord_neg)])
Ahmad Reza's avatar
Ahmad Reza committed
561
562
563
564
565
566
567
568
            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
569
570
571
572
            if (x_upper_scan, y_up_scan) in self.sim.particle_map_coords:
                hop_list.append(self.sim.particle_map_coords[(x_upper_scan, y_up_scan)])
            if (x_upper_scan, y_down_scan) in self.sim.particle_map_coords:
                hop_list.append(self.sim.particle_map_coords[(x_upper_scan, y_down_scan)])
Ahmad Reza's avatar
Ahmad Reza committed
573
574
575
576
577
578
579
580
581
582
583
584
585
            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):
        """
586
        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
587
588
589

        :todo: If nothing then everything should be scanned

590
        :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
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
        :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):
        """
607
        Scanning for particles, tiles, or marker on a given hop distance
Ahmad Reza's avatar
Ahmad Reza committed
608

609
        :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
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
        :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:
625
626
627
628
629
630
                # if self.coords in self.sim.tile_map_coords:
                #     hop_list.append(self.sim.tile_map_coords[self.coords])
                if (x_scan_pos, y_scan_coord_neg) in self.sim.tile_map_coords:
                    hop_list.append(self.sim.tile_map_coords[(x_scan_pos, y_scan_coord_neg)])
                if (x_scan_neg, y_scan_coord_neg) in self.sim.tile_map_coords:
                    hop_list.append(self.sim.tile_map_coords[(x_scan_neg, y_scan_coord_neg)])
Ahmad Reza's avatar
Ahmad Reza committed
631
            else:
632
633
634
635
636
637
638
639
                if (x_scan_pos, y_scan_coord_pos) in self.sim.tile_map_coords:
                    hop_list.append(self.sim.tile_map_coords[(x_scan_pos, y_scan_coord_pos)])
                if (x_scan_pos, y_scan_coord_neg) in self.sim.tile_map_coords:
                    hop_list.append(self.sim.tile_map_coords[(x_scan_pos, y_scan_coord_neg)])
                if (x_scan_pos, y_scan_coord_neg) in self.sim.tile_map_coords:
                    hop_list.append(self.sim.tile_map_coords[(x_scan_pos, y_scan_coord_neg)])
                if (x_scan_neg, y_scan_coord_neg) in self.sim.tile_map_coords:
                    hop_list.append(self.sim.tile_map_coords[(x_scan_neg, y_scan_coord_neg)])
Ahmad Reza's avatar
Ahmad Reza committed
640
641
642
643
644
645
646
647
            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
648
649
650
651
            if (x_upper_scan, y_up_scan) in self.sim.tile_map_coords:
                hop_list.append(self.sim.tile_map_coords[(x_upper_scan, y_up_scan)])
            if (x_upper_scan, y_down_scan) in self.sim.tile_map_coords:
                hop_list.append(self.sim.tile_map_coords[(x_upper_scan, y_down_scan)])
Ahmad Reza's avatar
Ahmad Reza committed
652
653
654
655
656
657
658
659
660
661
            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


662
    def scan_for_marker_within(self, hop=1):
Ahmad Reza's avatar
Ahmad Reza committed
663
        """
664
        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
665
666
667

        :todo: If nothing then everything should be scanned

668
        :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
669
670
671
672
673
674
        :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):
675
            list = self.scan_for_marker_in(i)
Ahmad Reza's avatar
Ahmad Reza committed
676
677
678
679
680
681
682
            if list != None:
                hop_list.extend(list)
        if len(hop_list) != 0:
            return hop_list
        else:
            return None

683
    def scan_for_marker_in(self, hop=1):
Ahmad Reza's avatar
Ahmad Reza committed
684
        """
685
        Scanning for particles, tiles, or marker on a given hop distance
Ahmad Reza's avatar
Ahmad Reza committed
686

687
        :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
688
689
690
691
        :param hop: The hop distance from thee actual position of the scanning particle
        :return: A list of the founded matters
        """
        hop_list = []
692
        logging.info("particle is scanning for marker in %i hops", hop)
Ahmad Reza's avatar
Ahmad Reza committed
693
694
695
696
697
698
699
700
701
702
        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:
703
704
705
706
707
708
                # if self.coords in self.sim.marker_map_coords:
                #     hop_list.append(self.sim.marker_map_coords[self.coords])
                if (x_scan_pos, y_scan_coord_neg) in self.sim.marker_map_coords:
                    hop_list.append(self.sim.marker_map_coords[(x_scan_pos, y_scan_coord_neg)])
                if (x_scan_neg, y_scan_coord_neg) in self.sim.marker_map_coords:
                    hop_list.append(self.sim.marker_map_coords[(x_scan_neg, y_scan_coord_neg)])
Ahmad Reza's avatar
Ahmad Reza committed
709
710
            else:

711
712
713
714
715
716
717
718
                if (x_scan_pos, y_scan_coord_pos) in self.sim.marker_map_coords:
                    hop_list.append(self.sim.marker_map_coords[(x_scan_pos, y_scan_coord_pos)])
                if (x_scan_pos, y_scan_coord_neg) in self.sim.marker_map_coords:
                    hop_list.append(self.sim.marker_map_coords[(x_scan_pos, y_scan_coord_neg)])
                if (x_scan_neg, y_scan_coord_pos) in self.sim.marker_map_coords:
                    hop_list.append(self.sim.marker_map_coords[(x_scan_neg, y_scan_coord_pos)])
                if (x_scan_neg, y_scan_coord_neg) in self.sim.marker_map_coords:
                    hop_list.append(self.sim.marker_map_coords[(x_scan_neg, y_scan_coord_neg)])
Ahmad Reza's avatar
Ahmad Reza committed
719
720
721
722
723
724
725
726
            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
727
728
729
730
            if (x_upper_scan, y_up_scan) in self.sim.marker_map_coords:
                hop_list.append(self.sim.marker_map_coords[(x_upper_scan, y_up_scan)])
            if (x_upper_scan, y_down_scan) in self.sim.marker_map_coords:
                hop_list.append(self.sim.marker_map_coords[(x_upper_scan, y_down_scan)])
Ahmad Reza's avatar
Ahmad Reza committed
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
            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:
749
750
            if self.coords in self.sim.particle_map_coords:
                del self.sim.particle_map_coords[self.coords]
Ahmad Reza's avatar
Ahmad Reza committed
751
752
753
754
755
756
757
758
759
760
761
762
763
764
            self.__isCarried = True
            self.coords = coords
            self.touch()
            return True
        else:
            return False

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

        :param coords: the given position
        :return: None
        """
765
        self.sim.particle_map_coords[coords] = self
Ahmad Reza's avatar
Ahmad Reza committed
766
767
768
769
770
771
772
773
        self.coords = coords
        self.__isCarried = False
        self.touch()

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

Ahmad Reza's avatar
Ahmad Reza committed
774
        :return: New Tile or False
Ahmad Reza's avatar
Ahmad Reza committed
775
776
        """
        logging.info("Going to create a tile on position %s", str(self.coords))
Ahmad Reza's avatar
Ahmad Reza committed
777
778
779
780
781
782
783
784
785
        new_tile = self.sim.add_tile(self.coords[0], self.coords[1], color, alpha)
        if new_tile:
            self.sim.tile_map_coords[self.coords[0], self.coords[1]].created = True
            self.csv_particle_writer.write_particle(tile_created=1)
            self.sim.csv_round_writer.update_tiles_num(len(self.sim.get_tiles_list()))
            self.sim.csv_round_writer.update_metrics( tile_created=1)
            return new_tile
        else:
            return False
Ahmad Reza's avatar
Ahmad Reza committed
786
787
788
789
790
791

    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
792
        :return: New tile or False
Ahmad Reza's avatar
Ahmad Reza committed
793
794
795
796
        """
        logging.info("particle with id %s is", self.get_id())
        logging.info("Going to create a tile in %s ", str(dir) )
        if dir != None:
797
            coords = self.sim.get_coords_in_dir(self.coords, dir)
Ahmad Reza's avatar
Ahmad Reza committed
798
799
            new_tile = self.sim.add_tile(coords[0], coords[1], color, alpha)
            if new_tile:
800
                self.sim.tile_map_coords[coords[0], coords[1]].created = True
Ahmad Reza's avatar
Ahmad Reza committed
801
                logging.info("Tile is created")
802
                self.sim.new_tile_flag = True
Ahmad Reza's avatar
Ahmad Reza committed
803
                self.csv_particle_writer.write_particle(tile_created=1)
804
805
                self.sim.csv_round_writer.update_tiles_num(len(self.sim.get_tiles_list()))
                self.sim.csv_round_writer.update_metrics( tile_created=1)
Ahmad Reza's avatar
Ahmad Reza committed
806
807
808
                return new_tile
            else:
                return False
Ahmad Reza's avatar
Ahmad Reza committed
809
810
        else:
            logging.info("Not created tile ")
Ahmad Reza's avatar
Ahmad Reza committed
811
            return False
Ahmad Reza's avatar
Ahmad Reza committed
812
813
814
815
816
817
818

    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
819
        :return: New Tile or False
Ahmad Reza's avatar
Ahmad Reza committed
820
821
822
823
824
        """

        logging.info("particle with id %s is", self.get_id())
        if x is not None and y is not None:
            coords = (x, y)
825
            if self.sim.check_coords(x,y):
Ahmad Reza's avatar
Ahmad Reza committed
826
                logging.info("Going to create a tile on position \(%i , %i\)", x,y )
827
828
829
                if self.sim.add_tile(coords[0], coords[1], color, alpha) == True:
                    self.sim.tile_map_coords[coords[0], coords[1]].created = True
                    self.sim.new_tile_flag = True
Ahmad Reza's avatar
Ahmad Reza committed
830
                    self.csv_particle_writer.write_particle(tile_created=1)
831
832
                    self.sim.csv_round_writer.update_tiles_num(len(self.sim.get_tiles_list()) )
                    self.sim.csv_round_writer.update_metrics( tile_created=1)
Ahmad Reza's avatar
Ahmad Reza committed
833
834
835
836
837
838
                    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
839
                return False
Ahmad Reza's avatar
Ahmad Reza committed
840
841
842
843
844
845
846
847
848

    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")
849
850
        if self.coords in self.sim.get_tile_map_coords():
            if self.sim.remove_tile_on(self.coords):
Ahmad Reza's avatar
Ahmad Reza committed
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
                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))
866
        if self.sim.remove_tile(id):
Ahmad Reza's avatar
Ahmad Reza committed
867
868
869
870
871
872
            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
873
    def delete_tile_in(self, dir=None):
Ahmad Reza's avatar
Ahmad Reza committed
874
875
876
877
878
879
880
881
        """
        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
882
        if dir is not None:
883
            coords = self.sim.get_coords_in_dir(self.coords, dir)
Ahmad Reza's avatar
Ahmad Reza committed
884
885
            logging.info("Deleting tile in %s direction", str(dir))
            if coords is not None:
886
                if self.sim.remove_tile_on(coords):
Ahmad Reza's avatar
Ahmad Reza committed
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
                    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)
908
            if self.sim.remove_tile_on(coords):
Ahmad Reza's avatar
Ahmad Reza committed
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
                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:
927
928
            if self.coords in self.sim.tile_map_coords:
                self.carried_tile = self.sim.tile_map_coords[self.coords]
Ahmad Reza's avatar
Ahmad Reza committed
929
930
                if self.carried_tile.take(coords=self.coords):
                    logging.info("Tile has been taken")
931
                    self.sim.csv_round_writer.update_metrics( tiles_taken=1)
Ahmad Reza's avatar
Ahmad Reza committed
932
933
934
935
936
937
                    self.csv_particle_writer.write_particle(tiles_taken=1)
                    return True
                else:
                    logging.info("Tile could not be taken")
                    return False
            else:
938
                logging.info("No tile on the actual position not in the sim")
Ahmad Reza's avatar
Ahmad Reza committed
939
940
941
942
943
944
945
946
947
948
949
950
951
                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:
952
953
954
            if id in self.sim.tile_map_id:
                logging.info("Tile with tile id %s is in the sim", str(id))
                self.carried_tile = self.sim.tile_map_id[id]
Ahmad Reza's avatar
Ahmad Reza committed
955
956
                if self.carried_tile.take(coords=self.coords):
                    logging.info("Tile with tile id %s  has been taken", str(id))
957
                    self.sim.csv_round_writer.update_metrics( tiles_taken=1)
Ahmad Reza's avatar
Ahmad Reza committed
958
959
960
961
962
963
                    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:
964
                logging.info("Tile with tile id %s is not in the sim", str(id))
Ahmad Reza's avatar
Ahmad Reza committed
965
966
967
968
969
970
971
972
973
974
975
976
977
                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:
978
979
980
981
            coords = self.sim.get_coords_in_dir(self.coords, dir)
            if coords in self.sim.tile_map_coords:
                self.carried_tile = self.sim.tile_map_coords[coords]
                logging.info("Tile with tile id %s is in the sim", str(self.carried_tile.get_id()))
Ahmad Reza's avatar
Ahmad Reza committed
982
983
                if self.carried_tile.take(coords=self.coords):
                    logging.info("Tile with tile id %s  has been taken", str(self.carried_tile.get_id()))
984
                    self.sim.csv_round_writer.update_metrics( tiles_taken=1)
Ahmad Reza's avatar
Ahmad Reza committed
985
986
987
988
989
990
                    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:
991
                logging.info("Tile is not in the sim")
Ahmad Reza's avatar
Ahmad Reza committed
992
993
994
995
996
997
998
999
1000
                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

For faster browsing, not all history is shown. View entire blame