Домашни > Хелоуин в Припят > Решения > Решението на Атанас Ников

Резултати
10 точки от тестове
0 точки от учител

10 точки общо

12 успешни теста
0 неуспешни теста
Код

  1import math
  2from collections import defaultdict
  3
  4
  5class Candy:
  6    def __init__(self, mass, uranium):
  7        self._mass = mass
  8        self._uranium = uranium
  9
 10    def get_uranium_quantity(self):
 11        return self._mass * self._uranium
 12
 13    def get_mass(self):
 14        return self._mass
 15
 16
 17class Person:
 18    def __init__(self, position):
 19        self._position = position
 20
 21    def set_position(self, position):
 22        self._position = position
 23
 24    def get_position(self):
 25        return self._position
 26
 27
 28class Kid(Person):
 29
 30    _BOUNDARY = 20
 31
 32    def __init__(self, position, initiative):
 33        super().__init__(position)
 34        self._initiative = initiative
 35        self._candies = []
 36
 37    def get_initiative(self):
 38        return self._initiative
 39
 40    def add_candy(self, new_candy):
 41        if new_candy:
 42            self._candies.append(new_candy)
 43
 44    def is_critical(self):
 45        return sum(map(lambda candy: candy.get_uranium_quantity(), self._candies)) > self._BOUNDARY
 46
 47
 48class Host(Person):
 49    def __init__(self, position, candies):
 50        super().__init__(position)
 51        self._basket = {Candy(*args) for args in candies}
 52
 53    def remove_candy(self, function):
 54        if not self._basket:
 55            return None
 56
 57        retrieved_candy = function(self._basket)
 58        self._basket.remove(retrieved_candy)
 59
 60        return retrieved_candy
 61
 62    def get_basket(self):
 63        return self._basket
 64
 65
 66class FluxCapacitor:
 67    def __init__(self, participants):
 68        self._hosts = {participant.get_position(): participant for participant in participants if isinstance(participant, Host)}
 69        self._kids = {participant: set() for participant in participants if isinstance(participant, Kid)}
 70
 71    def get_victim(self):
 72        dead_kids = set()
 73        roams = len(self._hosts)
 74
 75        for _ in range(roams):
 76            self._roam_around_pripyat()
 77
 78            for dead_kid in filter(lambda kid: kid.is_critical(), self._kids.keys()):
 79                dead_kids.add(dead_kid)
 80
 81            if dead_kids:
 82                return dead_kids
 83
 84        return None
 85
 86    def _roam_around_pripyat(self):
 87        hosts_and_their_kids = defaultdict(list)
 88
 89        for kid in sorted(self._kids.keys(), key=lambda current: current.get_initiative(), reverse=True):
 90            hosts_and_their_kids[self._get_closest_host(kid)].append(kid)
 91
 92        for host, their_kids in hosts_and_their_kids.items():
 93            for kid in their_kids:
 94                old_key = kid
 95
 96                kid.add_candy(host.remove_candy(lambda candies: max(candies, key=lambda candy: candy.get_mass())))
 97
 98                self._hosts[host.get_position()] = host
 99                self._kids[kid] = self._kids.pop(old_key)
100
101    def _get_closest_host(self, kid):
102        closest_distance = None
103        current_host = None
104
105        for host in self._hosts.values():
106            if host.get_position() in self._kids[kid]:
107                continue
108
109            distance = math.dist(host.get_position(), kid.get_position())
110            is_closest = False
111
112            if not current_host:
113                is_closest = True
114            else:
115                is_closest |= distance < closest_distance
116                is_closest |= (math.isclose(distance, closest_distance) and
117                               (host.get_position()[0] < current_host.get_position()[0]))
118                is_closest |= (math.isclose(distance, closest_distance) and
119                               host.get_position()[0] == current_host.get_position()[0] and
120                               host.get_position()[1] < current_host.get_position()[1])
121
122            if is_closest:
123                closest_distance = distance
124                current_host = host
125
126        self._kids[kid].add(current_host.get_position())
127        kid.set_position(current_host.get_position())
128
129        return current_host

............
----------------------------------------------------------------------
Ran 12 tests in 0.001s

OK

Дискусия
Атанас Ников
04.11.2023 20:39

Оо, много се радвам, благодаря за обратната връзка, апришиейтед : )
Георги Кунчев
04.11.2023 20:37

Потвърждавам, че сега е ок.
Атанас Ников
04.11.2023 20:32

За жалост в момента все още търся конкретния случай, който не работи, но се надявам вече да не се получава безкраен цикъл, ако съм хванал проблема.
Георги Кунчев
04.11.2023 20:05

Мисля, че сам си отговори. Ти имаш тест, който работи. Аз имам тест, който зависва. Ерго -> не е винаги :smile:
Атанас Ников
04.11.2023 19:53

Мога ли да попитам дали става въпрос за конкретен случай, или изобщо, т.е., дали става някакво разминаване, понеже тестовете, които написах досега, работят (уж) :(
Георги Кунчев
04.11.2023 19:43

Имаш безкраен цикъл и тестовете ни ще зависнат, т.е. няма да имаш точки. Моля изтествай с реален случай.
История

f1import mathf1import math
2from collections import defaultdict2from collections import defaultdict
33
44
5class Candy:5class Candy:
6    def __init__(self, mass, uranium):6    def __init__(self, mass, uranium):
7        self._mass = mass7        self._mass = mass
8        self._uranium = uranium8        self._uranium = uranium
99
10    def get_uranium_quantity(self):10    def get_uranium_quantity(self):
11        return self._mass * self._uranium11        return self._mass * self._uranium
1212
13    def get_mass(self):13    def get_mass(self):
14        return self._mass14        return self._mass
1515
1616
17class Person:17class Person:
18    def __init__(self, position):18    def __init__(self, position):
19        self._position = position19        self._position = position
2020
21    def set_position(self, position):21    def set_position(self, position):
22        self._position = position22        self._position = position
2323
24    def get_position(self):24    def get_position(self):
25        return self._position25        return self._position
2626
2727
28class Kid(Person):28class Kid(Person):
nn29 
29    _BOUNDARY = 2030    _BOUNDARY = 20
3031
31    def __init__(self, position, initiative):32    def __init__(self, position, initiative):
32        super().__init__(position)33        super().__init__(position)
n33 n
34        self._initiative = initiative34        self._initiative = initiative
35        self._candies = []35        self._candies = []
3636
37    def get_initiative(self):37    def get_initiative(self):
38        return self._initiative38        return self._initiative
3939
40    def add_candy(self, new_candy):40    def add_candy(self, new_candy):
41        if new_candy:41        if new_candy:
42            self._candies.append(new_candy)42            self._candies.append(new_candy)
4343
44    def is_critical(self):44    def is_critical(self):
45        return sum(map(lambda candy: candy.get_uranium_quantity(), self._candies)) > self._BOUNDARY45        return sum(map(lambda candy: candy.get_uranium_quantity(), self._candies)) > self._BOUNDARY
4646
4747
48class Host(Person):48class Host(Person):
49    def __init__(self, position, candies):49    def __init__(self, position, candies):
50        super().__init__(position)50        super().__init__(position)
n51 n
52        self._basket = {Candy(*args) for args in candies}51        self._basket = {Candy(*args) for args in candies}
5352
54    def remove_candy(self, function):53    def remove_candy(self, function):
55        if not self._basket:54        if not self._basket:
56            return None55            return None
5756
58        retrieved_candy = function(self._basket)57        retrieved_candy = function(self._basket)
59        self._basket.remove(retrieved_candy)58        self._basket.remove(retrieved_candy)
6059
61        return retrieved_candy60        return retrieved_candy
6261
63    def get_basket(self):62    def get_basket(self):
64        return self._basket63        return self._basket
6564
6665
67class FluxCapacitor:66class FluxCapacitor:
68    def __init__(self, participants):67    def __init__(self, participants):
69        self._hosts = {participant.get_position(): participant for participant in participants if isinstance(participant, Host)}68        self._hosts = {participant.get_position(): participant for participant in participants if isinstance(participant, Host)}
70        self._kids = {participant: set() for participant in participants if isinstance(participant, Kid)}69        self._kids = {participant: set() for participant in participants if isinstance(participant, Kid)}
7170
72    def get_victim(self):71    def get_victim(self):
73        dead_kids = set()72        dead_kids = set()
74        roams = len(self._hosts)73        roams = len(self._hosts)
7574
76        for _ in range(roams):75        for _ in range(roams):
77            self._roam_around_pripyat()76            self._roam_around_pripyat()
7877
79            for dead_kid in filter(lambda kid: kid.is_critical(), self._kids.keys()):78            for dead_kid in filter(lambda kid: kid.is_critical(), self._kids.keys()):
80                dead_kids.add(dead_kid)79                dead_kids.add(dead_kid)
8180
82            if dead_kids:81            if dead_kids:
83                return dead_kids82                return dead_kids
8483
85        return None84        return None
8685
87    def _roam_around_pripyat(self):86    def _roam_around_pripyat(self):
88        hosts_and_their_kids = defaultdict(list)87        hosts_and_their_kids = defaultdict(list)
8988
90        for kid in sorted(self._kids.keys(), key=lambda current: current.get_initiative(), reverse=True):89        for kid in sorted(self._kids.keys(), key=lambda current: current.get_initiative(), reverse=True):
91            hosts_and_their_kids[self._get_closest_host(kid)].append(kid)90            hosts_and_their_kids[self._get_closest_host(kid)].append(kid)
9291
93        for host, their_kids in hosts_and_their_kids.items():92        for host, their_kids in hosts_and_their_kids.items():
94            for kid in their_kids:93            for kid in their_kids:
95                old_key = kid94                old_key = kid
9695
97                kid.add_candy(host.remove_candy(lambda candies: max(candies, key=lambda candy: candy.get_mass())))96                kid.add_candy(host.remove_candy(lambda candies: max(candies, key=lambda candy: candy.get_mass())))
9897
99                self._hosts[host.get_position()] = host98                self._hosts[host.get_position()] = host
100                self._kids[kid] = self._kids.pop(old_key)99                self._kids[kid] = self._kids.pop(old_key)
101100
102    def _get_closest_host(self, kid):101    def _get_closest_host(self, kid):
103        closest_distance = None102        closest_distance = None
104        current_host = None103        current_host = None
105104
106        for host in self._hosts.values():105        for host in self._hosts.values():
107            if host.get_position() in self._kids[kid]:106            if host.get_position() in self._kids[kid]:
108                continue107                continue
109108
110            distance = math.dist(host.get_position(), kid.get_position())109            distance = math.dist(host.get_position(), kid.get_position())
111            is_closest = False110            is_closest = False
112111
113            if not current_host:112            if not current_host:
114                is_closest = True113                is_closest = True
115            else:114            else:
116                is_closest |= distance < closest_distance115                is_closest |= distance < closest_distance
117                is_closest |= (math.isclose(distance, closest_distance) and116                is_closest |= (math.isclose(distance, closest_distance) and
118                               (host.get_position()[0] < current_host.get_position()[0]))117                               (host.get_position()[0] < current_host.get_position()[0]))
119                is_closest |= (math.isclose(distance, closest_distance) and118                is_closest |= (math.isclose(distance, closest_distance) and
120                               host.get_position()[0] == current_host.get_position()[0] and119                               host.get_position()[0] == current_host.get_position()[0] and
121                               host.get_position()[1] < current_host.get_position()[1])120                               host.get_position()[1] < current_host.get_position()[1])
122121
123            if is_closest:122            if is_closest:
124                closest_distance = distance123                closest_distance = distance
125                current_host = host124                current_host = host
126125
t127        if not current_host:t
128            return None
129 
130        self._kids[kid].add(current_host.get_position())126        self._kids[kid].add(current_host.get_position())
131        kid.set_position(current_host.get_position())127        kid.set_position(current_host.get_position())
132128
133        return current_host129        return current_host
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op

f1import mathf1import math
2from collections import defaultdict2from collections import defaultdict
33
44
5class Candy:5class Candy:
6    def __init__(self, mass, uranium):6    def __init__(self, mass, uranium):
7        self._mass = mass7        self._mass = mass
8        self._uranium = uranium8        self._uranium = uranium
99
10    def get_uranium_quantity(self):10    def get_uranium_quantity(self):
11        return self._mass * self._uranium11        return self._mass * self._uranium
1212
13    def get_mass(self):13    def get_mass(self):
14        return self._mass14        return self._mass
1515
1616
17class Person:17class Person:
18    def __init__(self, position):18    def __init__(self, position):
19        self._position = position19        self._position = position
2020
21    def set_position(self, position):21    def set_position(self, position):
22        self._position = position22        self._position = position
2323
24    def get_position(self):24    def get_position(self):
25        return self._position25        return self._position
2626
2727
28class Kid(Person):28class Kid(Person):
29    _BOUNDARY = 2029    _BOUNDARY = 20
3030
31    def __init__(self, position, initiative):31    def __init__(self, position, initiative):
32        super().__init__(position)32        super().__init__(position)
3333
34        self._initiative = initiative34        self._initiative = initiative
35        self._candies = []35        self._candies = []
3636
37    def get_initiative(self):37    def get_initiative(self):
38        return self._initiative38        return self._initiative
3939
40    def add_candy(self, new_candy):40    def add_candy(self, new_candy):
41        if new_candy:41        if new_candy:
42            self._candies.append(new_candy)42            self._candies.append(new_candy)
4343
44    def is_critical(self):44    def is_critical(self):
45        return sum(map(lambda candy: candy.get_uranium_quantity(), self._candies)) > self._BOUNDARY45        return sum(map(lambda candy: candy.get_uranium_quantity(), self._candies)) > self._BOUNDARY
4646
4747
48class Host(Person):48class Host(Person):
49    def __init__(self, position, candies):49    def __init__(self, position, candies):
50        super().__init__(position)50        super().__init__(position)
5151
52        self._basket = {Candy(*args) for args in candies}52        self._basket = {Candy(*args) for args in candies}
5353
54    def remove_candy(self, function):54    def remove_candy(self, function):
55        if not self._basket:55        if not self._basket:
56            return None56            return None
5757
58        retrieved_candy = function(self._basket)58        retrieved_candy = function(self._basket)
59        self._basket.remove(retrieved_candy)59        self._basket.remove(retrieved_candy)
6060
61        return retrieved_candy61        return retrieved_candy
6262
63    def get_basket(self):63    def get_basket(self):
64        return self._basket64        return self._basket
6565
6666
67class FluxCapacitor:67class FluxCapacitor:
68    def __init__(self, participants):68    def __init__(self, participants):
69        self._hosts = {participant.get_position(): participant for participant in participants if isinstance(participant, Host)}69        self._hosts = {participant.get_position(): participant for participant in participants if isinstance(participant, Host)}
70        self._kids = {participant: set() for participant in participants if isinstance(participant, Kid)}70        self._kids = {participant: set() for participant in participants if isinstance(participant, Kid)}
7171
72    def get_victim(self):72    def get_victim(self):
73        dead_kids = set()73        dead_kids = set()
74        roams = len(self._hosts)74        roams = len(self._hosts)
7575
76        for _ in range(roams):76        for _ in range(roams):
77            self._roam_around_pripyat()77            self._roam_around_pripyat()
7878
79            for dead_kid in filter(lambda kid: kid.is_critical(), self._kids.keys()):79            for dead_kid in filter(lambda kid: kid.is_critical(), self._kids.keys()):
80                dead_kids.add(dead_kid)80                dead_kids.add(dead_kid)
8181
82            if dead_kids:82            if dead_kids:
83                return dead_kids83                return dead_kids
8484
85        return None85        return None
8686
87    def _roam_around_pripyat(self):87    def _roam_around_pripyat(self):
88        hosts_and_their_kids = defaultdict(list)88        hosts_and_their_kids = defaultdict(list)
8989
90        for kid in sorted(self._kids.keys(), key=lambda current: current.get_initiative(), reverse=True):90        for kid in sorted(self._kids.keys(), key=lambda current: current.get_initiative(), reverse=True):
91            hosts_and_their_kids[self._get_closest_host(kid)].append(kid)91            hosts_and_their_kids[self._get_closest_host(kid)].append(kid)
9292
93        for host, their_kids in hosts_and_their_kids.items():93        for host, their_kids in hosts_and_their_kids.items():
94            for kid in their_kids:94            for kid in their_kids:
95                old_key = kid95                old_key = kid
9696
97                kid.add_candy(host.remove_candy(lambda candies: max(candies, key=lambda candy: candy.get_mass())))97                kid.add_candy(host.remove_candy(lambda candies: max(candies, key=lambda candy: candy.get_mass())))
9898
99                self._hosts[host.get_position()] = host99                self._hosts[host.get_position()] = host
100                self._kids[kid] = self._kids.pop(old_key)100                self._kids[kid] = self._kids.pop(old_key)
101101
102    def _get_closest_host(self, kid):102    def _get_closest_host(self, kid):
103        closest_distance = None103        closest_distance = None
104        current_host = None104        current_host = None
105105
106        for host in self._hosts.values():106        for host in self._hosts.values():
107            if host.get_position() in self._kids[kid]:107            if host.get_position() in self._kids[kid]:
108                continue108                continue
109109
n110            distance = self._get_euclidean_distance(host.get_position(), kid.get_position())n110            distance = math.dist(host.get_position(), kid.get_position())
111 
112            is_closest = False111            is_closest = False
113112
114            if not current_host:113            if not current_host:
115                is_closest = True114                is_closest = True
116            else:115            else:
117                is_closest |= distance < closest_distance116                is_closest |= distance < closest_distance
118                is_closest |= (math.isclose(distance, closest_distance) and117                is_closest |= (math.isclose(distance, closest_distance) and
119                               (host.get_position()[0] < current_host.get_position()[0]))118                               (host.get_position()[0] < current_host.get_position()[0]))
120                is_closest |= (math.isclose(distance, closest_distance) and119                is_closest |= (math.isclose(distance, closest_distance) and
121                               host.get_position()[0] == current_host.get_position()[0] and120                               host.get_position()[0] == current_host.get_position()[0] and
122                               host.get_position()[1] < current_host.get_position()[1])121                               host.get_position()[1] < current_host.get_position()[1])
123122
124            if is_closest:123            if is_closest:
125                closest_distance = distance124                closest_distance = distance
126                current_host = host125                current_host = host
127126
128        if not current_host:127        if not current_host:
129            return None128            return None
130129
131        self._kids[kid].add(current_host.get_position())130        self._kids[kid].add(current_host.get_position())
132        kid.set_position(current_host.get_position())131        kid.set_position(current_host.get_position())
133132
134        return current_host133        return current_host
t135 t
136    @staticmethod
137    def _get_euclidean_distance(starting_point, ending_point):
138        d_x = starting_point[0] - ending_point[0]
139        d_y = starting_point[1] - ending_point[1]
140 
141        return math.sqrt(d_x ** 2 + d_y ** 2)
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op

f1import mathf1import math
2from collections import defaultdict2from collections import defaultdict
33
44
5class Candy:5class Candy:
6    def __init__(self, mass, uranium):6    def __init__(self, mass, uranium):
7        self._mass = mass7        self._mass = mass
8        self._uranium = uranium8        self._uranium = uranium
99
10    def get_uranium_quantity(self):10    def get_uranium_quantity(self):
11        return self._mass * self._uranium11        return self._mass * self._uranium
1212
13    def get_mass(self):13    def get_mass(self):
14        return self._mass14        return self._mass
1515
1616
17class Person:17class Person:
18    def __init__(self, position):18    def __init__(self, position):
19        self._position = position19        self._position = position
2020
21    def set_position(self, position):21    def set_position(self, position):
22        self._position = position22        self._position = position
2323
24    def get_position(self):24    def get_position(self):
25        return self._position25        return self._position
2626
2727
28class Kid(Person):28class Kid(Person):
29    _BOUNDARY = 2029    _BOUNDARY = 20
3030
31    def __init__(self, position, initiative):31    def __init__(self, position, initiative):
32        super().__init__(position)32        super().__init__(position)
3333
34        self._initiative = initiative34        self._initiative = initiative
35        self._candies = []35        self._candies = []
3636
37    def get_initiative(self):37    def get_initiative(self):
38        return self._initiative38        return self._initiative
3939
40    def add_candy(self, new_candy):40    def add_candy(self, new_candy):
41        if new_candy:41        if new_candy:
42            self._candies.append(new_candy)42            self._candies.append(new_candy)
4343
44    def is_critical(self):44    def is_critical(self):
45        return sum(map(lambda candy: candy.get_uranium_quantity(), self._candies)) > self._BOUNDARY45        return sum(map(lambda candy: candy.get_uranium_quantity(), self._candies)) > self._BOUNDARY
4646
4747
48class Host(Person):48class Host(Person):
49    def __init__(self, position, candies):49    def __init__(self, position, candies):
50        super().__init__(position)50        super().__init__(position)
5151
52        self._basket = {Candy(*args) for args in candies}52        self._basket = {Candy(*args) for args in candies}
5353
54    def remove_candy(self, function):54    def remove_candy(self, function):
55        if not self._basket:55        if not self._basket:
56            return None56            return None
5757
58        retrieved_candy = function(self._basket)58        retrieved_candy = function(self._basket)
59        self._basket.remove(retrieved_candy)59        self._basket.remove(retrieved_candy)
6060
61        return retrieved_candy61        return retrieved_candy
6262
63    def get_basket(self):63    def get_basket(self):
64        return self._basket64        return self._basket
6565
6666
67class FluxCapacitor:67class FluxCapacitor:
68    def __init__(self, participants):68    def __init__(self, participants):
69        self._hosts = {participant.get_position(): participant for participant in participants if isinstance(participant, Host)}69        self._hosts = {participant.get_position(): participant for participant in participants if isinstance(participant, Host)}
70        self._kids = {participant: set() for participant in participants if isinstance(participant, Kid)}70        self._kids = {participant: set() for participant in participants if isinstance(participant, Kid)}
7171
72    def get_victim(self):72    def get_victim(self):
73        dead_kids = set()73        dead_kids = set()
nn74        roams = len(self._hosts)
7475
n75        while not dead_kids and self._roam_around_pripyat():n76        for _ in range(roams):
77            self._roam_around_pripyat()
78 
76            for dead_kid in filter(lambda kid: kid.is_critical(), self._kids.keys()):79            for dead_kid in filter(lambda kid: kid.is_critical(), self._kids.keys()):
77                dead_kids.add(dead_kid)80                dead_kids.add(dead_kid)
7881
n79        return dead_kids if dead_kids else Nonen82            if dead_kids:
83                return dead_kids
84 
85        return None
8086
81    def _roam_around_pripyat(self):87    def _roam_around_pripyat(self):
82        hosts_and_their_kids = defaultdict(list)88        hosts_and_their_kids = defaultdict(list)
8389
84        for kid in sorted(self._kids.keys(), key=lambda current: current.get_initiative(), reverse=True):90        for kid in sorted(self._kids.keys(), key=lambda current: current.get_initiative(), reverse=True):
85            hosts_and_their_kids[self._get_closest_host(kid)].append(kid)91            hosts_and_their_kids[self._get_closest_host(kid)].append(kid)
8692
87        for host, their_kids in hosts_and_their_kids.items():93        for host, their_kids in hosts_and_their_kids.items():
n88            if not host and len(their_kids) == len(self._kids):n
89                return False
90 
91            if not host:
92                continue
93 
94            for kid in their_kids:94            for kid in their_kids:
95                old_key = kid95                old_key = kid
9696
97                kid.add_candy(host.remove_candy(lambda candies: max(candies, key=lambda candy: candy.get_mass())))97                kid.add_candy(host.remove_candy(lambda candies: max(candies, key=lambda candy: candy.get_mass())))
9898
99                self._hosts[host.get_position()] = host99                self._hosts[host.get_position()] = host
100                self._kids[kid] = self._kids.pop(old_key)100                self._kids[kid] = self._kids.pop(old_key)
t101 t
102        return True
103101
104    def _get_closest_host(self, kid):102    def _get_closest_host(self, kid):
105        closest_distance = None103        closest_distance = None
106        current_host = None104        current_host = None
107105
108        for host in self._hosts.values():106        for host in self._hosts.values():
109            if host.get_position() in self._kids[kid]:107            if host.get_position() in self._kids[kid]:
110                continue108                continue
111109
112            distance = self._get_euclidean_distance(host.get_position(), kid.get_position())110            distance = self._get_euclidean_distance(host.get_position(), kid.get_position())
113111
114            is_closest = False112            is_closest = False
115113
116            if not current_host:114            if not current_host:
117                is_closest = True115                is_closest = True
118            else:116            else:
119                is_closest |= distance < closest_distance117                is_closest |= distance < closest_distance
120                is_closest |= (math.isclose(distance, closest_distance) and118                is_closest |= (math.isclose(distance, closest_distance) and
121                               (host.get_position()[0] < current_host.get_position()[0]))119                               (host.get_position()[0] < current_host.get_position()[0]))
122                is_closest |= (math.isclose(distance, closest_distance) and120                is_closest |= (math.isclose(distance, closest_distance) and
123                               host.get_position()[0] == current_host.get_position()[0] and121                               host.get_position()[0] == current_host.get_position()[0] and
124                               host.get_position()[1] < current_host.get_position()[1])122                               host.get_position()[1] < current_host.get_position()[1])
125123
126            if is_closest:124            if is_closest:
127                closest_distance = distance125                closest_distance = distance
128                current_host = host126                current_host = host
129127
130        if not current_host:128        if not current_host:
131            return None129            return None
132130
133        self._kids[kid].add(current_host.get_position())131        self._kids[kid].add(current_host.get_position())
134        kid.set_position(current_host.get_position())132        kid.set_position(current_host.get_position())
135133
136        return current_host134        return current_host
137135
138    @staticmethod136    @staticmethod
139    def _get_euclidean_distance(starting_point, ending_point):137    def _get_euclidean_distance(starting_point, ending_point):
140        d_x = starting_point[0] - ending_point[0]138        d_x = starting_point[0] - ending_point[0]
141        d_y = starting_point[1] - ending_point[1]139        d_y = starting_point[1] - ending_point[1]
142140
143        return math.sqrt(d_x ** 2 + d_y ** 2)141        return math.sqrt(d_x ** 2 + d_y ** 2)
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op