swarm_sim_header.py 2.03 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import sys


def eeprint(*args, sep=' ', end='\n'):
    """
    prints error message to stderr, stops the program with error code -1
    :param args: like in print()
    :param sep: like in print()
    :param end: like in print()
    :return:
    """
    print(*args, sep, end, file=sys.stderr)
    exit(-1)


def eprint(*args, sep=' ', end='\n'):
    """
    prints error message to stderr
    :param args: like in print()
    :param sep: like in print()
    :param end: like in print()
    :return:
    """
    print(*args, sep, end, file=sys.stderr)


27
def get_coordinates_in_direction(coordinates, direction):
28
29
30
    """
    Returns the coordination data of the pointed directions

31
    :param coordinates: particles actual staying coordination
32
33
34
    :param direction: The direction. Options:  E, SE, SW, W, NW, or NE
    :return: The coordinaiton of the pointed directions
    """
Karol Actun's avatar
Karol Actun committed
35
    return coordinates[0] + direction[0], coordinates[1] + direction[1], coordinates[2] + direction[2]
36
37


Karol Actun's avatar
Karol Actun committed
38
39
40
41
42
43
44
def scan_in(matter_map: dict, center, hop, grid):
    result = []
    n_sphere_border = grid.get_n_sphere_border(center, hop)
    for l in n_sphere_border:
        if l in matter_map:
            result.append(matter_map[l])
    return result
45
46


Karol Actun's avatar
Karol Actun committed
47
48
49
50
51
52
53
def scan_within(matter_map, center, hop, grid):
    result = []
    n_sphere_border = grid.get_n_sphere(center, hop)
    for l in n_sphere_border:
        if l in matter_map:
            result.append(matter_map[l])
    return result
54

55
56
57
58
59
60
61
62
63
64
65
66
67
68

def create_matter_in_line(world, start, direction, amount, matter_type='particle'):
    current_position = start
    for _ in range(amount):
        if matter_type == 'particle':
            world.add_particle(current_position)
        elif matter_type == 'tile':
            world.add_tile(current_position)
        elif matter_type == 'location':
            world.add_location(current_position)
        else:
            print("create_matter_in_line: unknown type (allowed: particle, tile or location")
            return
        current_position = get_coordinates_in_direction(current_position, direction)