particle.py 69.9 KB
Newer Older
Ahmad Reza's avatar
Ahmad Reza committed
1001
1002
1003
1004
1005
        :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:
1006
            if self.sim.check_coords(x, y):
Ahmad Reza's avatar
Ahmad Reza committed
1007
                coords = (x, y)
1008
1009
1010
                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
1011
                    if self.carried_tile.take(coords=self.coords):
1012
                        self.sim.csv_round_writer.update_metrics( tiles_taken=1)
Ahmad Reza's avatar
Ahmad Reza committed
1013
1014
1015
1016
1017
1018
1019
                        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:
1020
                    logging.info("Tile is not in the sim")
Ahmad Reza's avatar
Ahmad Reza committed
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
                    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:
1036
            if self.coords not in self.sim.tile_map_coords:
Ahmad Reza's avatar
Ahmad Reza committed
1037
1038
1039
1040
1041
1042
                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")
1043
                self.sim.csv_round_writer.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
                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:
1059
1060
            coords = self.sim.get_coords_in_dir(self.coords, dir)
            if coords not in self.sim.tile_map_coords:
Ahmad Reza's avatar
Ahmad Reza committed
1061
1062
1063
1064
1065
                try:  # cher: insert so to overcome the AttributeError
                    self.carried_tile.drop_me(coords)
                except AttributeError:
                    pass
                self.carried_tile = None
1066
                self.sim.csv_round_writer.update_metrics( tiles_dropped=1)
Ahmad Reza's avatar
Ahmad Reza committed
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
                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:
1086
            if self.sim.check_coords(x, y):
Ahmad Reza's avatar
Ahmad Reza committed
1087
                coords = (x, y)
1088
                if coords not in self.sim.get_tile_map_coords():
Ahmad Reza's avatar
Ahmad Reza committed
1089
1090
1091
1092
1093
                    try:  # cher: insert so to overcome the AttributeError
                        self.carried_tile.drop_me(coords)
                    except AttributeError:
                        pass
                    self.carried_tile = None
1094
                    self.sim.csv_round_writer.update_metrics( tiles_dropped=1)
Ahmad Reza's avatar
Ahmad Reza committed
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
                    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
1112
        :return: New Particle or False
Ahmad Reza's avatar
Ahmad Reza committed
1113
1114
        """
        logging.info("Going to create on position %s", str(self.coords))
Ahmad Reza's avatar
Ahmad Reza committed
1115
1116
1117
1118
1119
1120
1121
1122
1123
        new_particle = self.sim.add_particle(self.coords[0], self.coords[1], color, alpha)
        if new_particle:
            self.sim.particle_map_coords[self.coords[0], self.coords[1]].created=True
            self.csv_particle_writer.write_particle(particle_created=1)
            self.sim.csv_round_writer.update_particle_num(len(self.sim.get_particle_list()))
            self.sim.csv_round_writer.update_metrics( particle_created=1)
            return new_particle
        else:
            return False
Ahmad Reza's avatar
Ahmad Reza committed
1124
1125
1126
1127
1128
1129
1130
1131

    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
1132
        :return: New Particle or False
Ahmad Reza's avatar
Ahmad Reza committed
1133
1134
1135
        """
        coords = (0, 0)
        if dir is not None:
1136
            coords = self.sim.get_coords_in_dir(self.coords, dir)
Ahmad Reza's avatar
Ahmad Reza committed
1137
            logging.info("Going to create a particle in %s on position %s", str(dir), str(coords))
Ahmad Reza's avatar
Ahmad Reza committed
1138
1139
            new_particle= self.sim.add_particle(coords[0], coords[1], color, alpha)
            if new_particle:
1140
                self.sim.particle_map_coords[coords[0], coords[1]].created = True
Ahmad Reza's avatar
Ahmad Reza committed
1141
                logging.info("Created particle on coords %s", coords)
1142
1143
                self.sim.csv_round_writer.update_particle_num(len(self.sim.get_particle_list()))
                self.sim.csv_round_writer.update_metrics( particle_created=1)
Ahmad Reza's avatar
Ahmad Reza committed
1144
                self.csv_particle_writer.write_particle(particle_created=1)
Ahmad Reza's avatar
Ahmad Reza committed
1145
1146
1147
                return new_particle
            else:
                return False
Ahmad Reza's avatar
Ahmad Reza committed
1148
1149
        else:
            logging.info("Not created particle on coords %s", str(coords))
Ahmad Reza's avatar
Ahmad Reza committed
1150
            return False
Ahmad Reza's avatar
Ahmad Reza committed
1151
1152
1153
1154
1155
1156
1157
1158
1159

    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
1160
        :return: New Particle or False
Ahmad Reza's avatar
Ahmad Reza committed
1161
1162
1163
        """
        coords = (0, 0)
        if x is not None and y is not None:
1164
            if self.sim.check_coords(x, y):
Ahmad Reza's avatar
Ahmad Reza committed
1165
1166
                coords = (x, y)
                logging.info("Going to create a particle on position %s", str(coords))
Ahmad Reza's avatar
Ahmad Reza committed
1167
1168
                new_particle = self.sim.add_particle(coords[0], coords[1], color, alpha)
                if new_particle:
1169
                    self.sim.particle_map_coords[coords[0], coords[1]].created = True
Ahmad Reza's avatar
Ahmad Reza committed
1170
                    logging.info("Created particle on coords %s", str(coords))
1171
1172
                    self.sim.csv_round_writer.update_particle_num(len(self.sim.get_particle_list()))
                    self.sim.csv_round_writer.update_metrics( particle_created=1)
Ahmad Reza's avatar
Ahmad Reza committed
1173
                    self.csv_particle_writer.write_particle(particle_created=1)
Ahmad Reza's avatar
Ahmad Reza committed
1174
                    return new_particle
Ahmad Reza's avatar
Ahmad Reza committed
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
                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")
1191
1192
        if self.coords in self.sim.get_particle_map_coords():
            if self.sim.remove_particle_on(self.coords):
Ahmad Reza's avatar
Ahmad Reza committed
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
                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))
1208
        if self.sim.remove_particle(id):
Ahmad Reza's avatar
Ahmad Reza committed
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
            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
1221
        if dir is not None:
1222
            coords = self.sim.get_coords_in_dir(self.coords, dir)
Ahmad Reza's avatar
Ahmad Reza committed
1223
            logging.info("Deleting tile in %s direction", str(dir))
Ahmad Reza's avatar
Ahmad Reza committed
1224
1225
1226
1227
1228
            if self.sim.remove_particle_on(coords):
                logging.info("Deleted particle with particle on coords %s", str(coords))
                self.csv_particle_writer.write_particle(particle_deleted=1)
            else:
                logging.info("Could not delet particle on coords %s", str(coords))
Ahmad Reza's avatar
Ahmad Reza committed
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238

    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:
1239
            if self.sim.check_coords(x, y):
Ahmad Reza's avatar
Ahmad Reza committed
1240
                coords = (x, y)
1241
                if self.sim.remove_particle_on(coords):
Ahmad Reza's avatar
Ahmad Reza committed
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
                    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:
1260
1261
            if self.coords in self.sim.particle_map_coords:
                self.carried_particle = self.sim.particle_map_coords[self.coords]
Ahmad Reza's avatar
Ahmad Reza committed
1262
1263
                if self.carried_particle.take_me(coords=self.coords):
                    logging.info("particle has been taken")
1264
                    self.sim.csv_round_writer.update_metrics( particles_taken=1)
Ahmad Reza's avatar
Ahmad Reza committed
1265
1266
1267
1268
1269
1270
                    self.csv_particle_writer.write_particle(particles_taken=1)
                    return True
                else:
                    logging.info("particle could not be taken")
                    return False
            else:
1271
                logging.info("No particle on the actual position not in the sim")
Ahmad Reza's avatar
Ahmad Reza committed
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
                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:
1285
            if id in self.sim.get_particle_map_id():
1286
1287
                logging.info("particle with particle id %s is in the sim", str(id))
                self.carried_particle = self.sim.particle_map_id[id]
Ahmad Reza's avatar
Ahmad Reza committed
1288
1289
1290
                if self.carried_particle.take_me(self.coords):
                    logging.info("particle with particle id %s  has been taken", str(id))

1291
                    self.sim.csv_round_writer.update_metrics(
Ahmad Reza's avatar
Ahmad Reza committed
1292
1293
1294
1295
1296
1297
1298
                                                               particles_taken=1)
                    self.csv_particle_writer.write_particle(particles_taken=1)
                    return True
                else:
                    logging.info("particle with particle id %s could not be taken", str(id))
                    return False
            else:
1299
                logging.info("particle with particle id %s is not in the sim", str(id))
Ahmad Reza's avatar
Ahmad Reza committed
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
        else:
            logging.info("particle cannot taken because particle is carrieng either a particle or a particle", str(id))

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

        :param dir: The direction on which the particle should be taken. Options: E, SE, SW, W, NW, NE,
        :return: True: successful taken; False: unsuccessful taken
        """
        if self.carried_tile is None and self.carried_particle is None:
1311
1312
            coords = self.sim.get_coords_in_dir(self.coords, dir)
            if coords in self.sim.particle_map_coords:
Ahmad Reza's avatar
Ahmad Reza committed
1313
                logging.info("Take particle")
1314
                self.carried_particle = self.sim.particle_map_coords[coords]
Ahmad Reza's avatar
Ahmad Reza committed
1315
1316
                if self.carried_particle.take_me(coords=self.coords):
                    logging.info("particle with particle id %s  has been taken", str(self.carried_particle.get_id()))
1317
                    self.sim.csv_round_writer.update_metrics(
Ahmad Reza's avatar
Ahmad Reza committed
1318
1319
1320
1321
1322
1323
1324
                                                               particles_taken=1)
                    self.csv_particle_writer.write_particle(particles_taken=1)
                    return True
                else:
                    logging.info("particle could not be taken")
                    return False
            else:
1325
                pass
1326
                logging.info("particl is not in the sim")
Ahmad Reza's avatar
Ahmad Reza committed
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
        else:
            logging.info("particle cannot be  taken")

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

        :param y:
        :param x:
        :return: True: Successful taken; False: Cannot be taken or wrong Coordinates
        """
        if self.carried_particle is None and self.carried_tile is None:
1339
            if self.sim.check_coords(x, y):
Ahmad Reza's avatar
Ahmad Reza committed
1340
                coords = (x, y)
1341
1342
1343
                if coords in self.sim.particle_map_coords:
                    self.carried_particle = self.sim.particle_map_coords[coords]
                    logging.info("Particle with id %s is in the sim", str(self.carried_particle.get_id()))
Ahmad Reza's avatar
Ahmad Reza committed
1344
                    if self.carried_particle.take_me(coords=self.coords):
1345
                        self.sim.csv_round_writer.update_metrics( particles_taken=1)
Ahmad Reza's avatar
Ahmad Reza committed
1346
1347
1348
1349
1350
1351
1352
                        self.csv_particle_writer.write_particle(particles_taken=1)
                        logging.info("particle with tile id %s has been taken", str(self.carried_particle.get_id()))
                        return True
                    else:
                        logging.info("Particle with id %s could not be taken", str(self.carried_particle.get_id()))
                        return False
                else:
1353
                    logging.info("Particle is not in the sim")
Ahmad Reza's avatar
Ahmad Reza committed
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
                    return False
            else:
                logging.info("Coordinates are wrong")
                return False
        else:
            logging.info("Particle cannot taken because particle is carrieng either a tile or a particle")
            return False

    def drop_particle(self):
        """
        Drops the taken particle on the particles actual position

        :return: None
        """
        if self.carried_particle is not None:
1369
            if self.coords not in self.sim.particle_map_coords:
Ahmad Reza's avatar
Ahmad Reza committed
1370
1371
1372
1373
1374
                try:  # cher: insert so to overcome the AttributeError
                    self.carried_particle.drop_me(self.coords)
                except AttributeError:
                    pass
            self.carried_particle = None
1375
            self.sim.csv_round_writer.update_metrics( particles_dropped=1)
Ahmad Reza's avatar
Ahmad Reza committed
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
            self.csv_particle_writer.write_particle(particles_dropped=1)
            logging.info("Particle succesfull dropped")
            return True
        else:
            logging.info("No particle taken to drop")
            return False

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

         :param dir: The direction on which the particle should be dropped. Options: E, SE, SW, W, NW, NE,
        """
        if self.carried_particle is not None:
1390
1391
            coords = self.sim.get_coords_in_dir(self.coords, dir)
            if coords not in self.sim.particle_map_coords:
Ahmad Reza's avatar
Ahmad Reza committed
1392
1393
1394
1395
1396
1397
                try:  # cher: insert so to overcome the AttributeError
                    self.carried_particle.drop_me(coords)
                except AttributeError:
                    pass
                    self.carried_particle = None
                    logging.info("Dropped particle on %s coordinate", str(coords))
1398
                    self.sim.csv_round_writer.update_metrics( particles_dropped=1)
Ahmad Reza's avatar
Ahmad Reza committed
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
                    self.csv_particle_writer.write_particle(particles_dropped=1)
                    return True
                else:
                    logging.info("Is not possible to drop the particle on that position")
                    return False
            else:
                logging.info("Is not possible to drop the particle on that position because it is occupied")
                return False
        else:
            logging.info("No particle taken to drop")
            return False

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

        :param x: x coordinate
        :param y: y coordinate
        """
        if self.carried_particle is not None:
            if x is not None and y is not None:
1420
                if self.sim.check_coords(x, y):
Ahmad Reza's avatar
Ahmad Reza committed
1421
                    coords = (x, y)
1422
                    if coords not in self.sim.particle_map_coords:
Ahmad Reza's avatar
Ahmad Reza committed
1423
1424
1425
1426
1427
1428
                        try:  # cher: insert so to overcome the AttributeError
                            self.carried_particle.drop_me(coords)
                        except AttributeError:
                            pass
                        self.carried_particle = None
                        logging.info("Dropped particle on %s coordinate", str(coords))
1429
                        self.sim.csv_round_writer.update_metrics(
Ahmad Reza's avatar
Ahmad Reza committed
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
                                                                   particles_dropped=1)
                        self.csv_particle_writer.write_particle(particles_dropped=1)
                        return True
                    else:
                        logging.info("Is not possible to drop the particle on that position  because it is occupied")
                        return False
                else:
                    logging.info("Wrong coordinates for dropping particle")
                    return False
            else:
                logging.info("No coordinates for dropping particle")
                return False
        else:
            logging.info("No particle taken to drop")
            return False

    def update_particle_coords(self, particle, new_coords):
        """
        Upadting the particle with new coordinates
        Only necessary for taking and moving particles

        :param particle: The particle object
        :param new_coords: new coorindation points
        :return: None
        """
        particle.coords = new_coords
        self.particle_map_coords[new_coords] = particle

1458
    def create_marker(self, color=black, alpha=1):
Ahmad Reza's avatar
Ahmad Reza committed
1459
        """
1460
         Creates a marker on the particles actual position
Ahmad Reza's avatar
Ahmad Reza committed
1461

1462
        :return: New marker or False
Ahmad Reza's avatar
Ahmad Reza committed
1463
1464
1465
        """

        logging.info("Going to create on position %s", str(self.coords))
1466
1467
1468
1469
1470
1471
        new_marker=self.sim.add_marker(self.coords[0], self.coords[1], color, alpha)
        if new_marker != False:
            self.csv_particle_writer.write_particle(marker_created=1)
            self.sim.csv_round_writer.update_markers_num(len(self.sim.get_marker_list()))
            self.sim.csv_round_writer.update_metrics( marker_created=1)
            return  new_marker
Ahmad Reza's avatar
Ahmad Reza committed
1472
1473
1474
        else:
            return False

1475
    def create_marker_in(self, dir=None, color=black, alpha=1):
Ahmad Reza's avatar
Ahmad Reza committed
1476
        """
1477
1478
1479
        Creates a marker either in a given direction
        :param dir: The direction on which the marker should be created. Options: E, SE, SW, W, NW, NE,
        :return: New marker or False
Ahmad Reza's avatar
Ahmad Reza committed
1480
1481
1482
1483

        """
        coords = (0, 0)
        if dir is not None:
1484
            coords = self.sim.get_coords_in_dir(self.coords, dir)
1485
1486
1487
1488
1489
1490
1491
            logging.info("Going to create a marker in %s on position %s", str(dir), str(coords))
            new_marker = self.sim.add_marker(coords[0], coords[1], color, alpha)
            if new_marker:
                logging.info("Created marker on coords %s", str(coords))
                self.sim.csv_round_writer.update_markers_num(len(self.sim.get_marker_list()))
                self.sim.csv_round_writer.update_metrics( marker_created=1)
                return new_marker
Ahmad Reza's avatar
Ahmad Reza committed
1492
1493
1494
            else:
                return False
        else:
1495
            logging.info("Not created marker on coords %s", str(coords))
Ahmad Reza's avatar
Ahmad Reza committed
1496
1497
            return False

1498
    def create_marker_on(self, x=None, y=None, color=black, alpha=1):
Ahmad Reza's avatar
Ahmad Reza committed
1499
        """
1500
        Creates a marker either on a given x,y coordinates
Ahmad Reza's avatar
Ahmad Reza committed
1501
1502
1503

        :param x: x coordinate
        :param y: y coordinate
1504
        :return: New marker or False
Ahmad Reza's avatar
Ahmad Reza committed
1505
1506
1507
1508

        """
        coords = (0, 0)
        if x is not None and y is not None:
1509
            if self.sim.check_coords(x, y):
Ahmad Reza's avatar
Ahmad Reza committed
1510
                coords = (x, y)
1511
1512
1513
1514
1515
1516
1517
                logging.info("Going to create a marker on position %s", str(coords))
                new_marker =  self.sim.add_marker(coords[0], coords[1], color, alpha)
                if new_marker:
                    logging.info("Created marker on coords %s", str(coords))
                    self.sim.csv_round_writer.update_markers_num(len(self.sim.get_marker_list()))
                    self.sim.csv_round_writer.update_metrics( marker_created=1)
                    return new_marker
Ahmad Reza's avatar
Ahmad Reza committed
1518
1519
1520
            else:
                return False
        else:
1521
            logging.info("Not created marker on coords %s", str(coords))
Ahmad Reza's avatar
Ahmad Reza committed
1522
1523
            return False

1524
    def delete_marker(self):
Ahmad Reza's avatar
Ahmad Reza committed
1525
        """
1526
        Deletes a marker on current position
Ahmad Reza's avatar
Ahmad Reza committed
1527
1528
1529
1530

        :return: True: Deleting successful; False: Deleting unsuccessful
        """
        logging.info("Particle %s is", self.get_id())
1531
1532
1533
1534
        logging.info("is going to delete a marker on current position")
        if self.coords in self.sim.get_marker_map_coords():
            if self.sim.remove_marker_on(self.coords):
                self.csv_particle_writer.write_particle(marker_deleted=1)
Ahmad Reza's avatar
Ahmad Reza committed
1535
1536
                return True
        else:
1537
            logging.info("Could not delet marker")
Ahmad Reza's avatar
Ahmad Reza committed
1538
1539
            return False

1540
    def delete_marker_with(self, marker_id):
Ahmad Reza's avatar
Ahmad Reza committed
1541
        """
1542
        Deletes a marker with a given marker-id
Ahmad Reza's avatar
Ahmad Reza committed
1543

1544
        :param marker_id: The id of the marker that should be deleted
Ahmad Reza's avatar
Ahmad Reza committed
1545
1546
1547
        :return: True: Deleting successful; False: Deleting unsuccessful
        """

1548
1549
1550
1551
        logging.info("marker %s is", self.get_id())
        logging.info("is going to delete a marker with id %s", str(marker_id))
        if self.sim.remove_marker(marker_id):
            self.csv_particle_writer.write_particle(marker_deleted=1)
Ahmad Reza's avatar
Ahmad Reza committed
1552
1553
            return
        else:
1554
            logging.info("Could not delet marker with marker id %s", str(marker_id))
Ahmad Reza's avatar
Ahmad Reza committed
1555

1556
    def delete_marker_in(self, dir=None):
Ahmad Reza's avatar
Ahmad Reza committed
1557
        """
1558
        Deletes a marker either in a given direction or on a given x,y coordinates
Ahmad Reza's avatar
Ahmad Reza committed
1559

1560
        :param dir: The direction on which the marker should be deleted. Options: E, SE, SW, W, NW, NE,
Ahmad Reza's avatar
Ahmad Reza committed
1561
1562
1563
1564
1565
        :param x: x coordinate
        :param y: y coordinate
        :return: True: Deleting successful; False: Deleting unsuccessful
        """

Ahmad Reza's avatar
Ahmad Reza committed
1566
        if dir is not None:
1567
            coords = self.sim.get_coords_in_dir(self.coords, dir)
Ahmad Reza's avatar
Ahmad Reza committed
1568
            logging.info("Deleting tile in %s direction", str(dir))
1569
1570
1571
            if self.sim.remove_marker_on(coords):
                logging.info("Deleted marker with marker on coords %s", str(coords))
                self.csv_particle_writer.write_particle(marker_deleted=1)
Ahmad Reza's avatar
Ahmad Reza committed
1572
            else:
1573
                logging.info("Could not delet marker on coords %s", str(coords))
Ahmad Reza's avatar
Ahmad Reza committed
1574

1575
    def delete_marker_on(self, x=None, y=None):
Ahmad Reza's avatar
Ahmad Reza committed
1576
1577
1578
1579
1580
1581
1582
1583
        """
        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:
1584
            if self.sim.check_coords(x, y):
Ahmad Reza's avatar
Ahmad Reza committed
1585
                coords = (x, y)
1586
1587
1588
                if self.sim.remove_marker_on(coords):
                    logging.info("Deleted marker  oords %s", str(coords))
                    self.csv_particle_writer.write_particle(marker_deleted=1)
Ahmad Reza's avatar
Ahmad Reza committed
1589
1590
                    return True
                else:
1591
                    logging.info("Could not delet marker on coords %s", str(coords))
Ahmad Reza's avatar
Ahmad Reza committed
1592
1593
1594
1595
1596
1597
                    return False
            else:
                return False
        else:
            return False
For faster browsing, not all history is shown. View entire blame