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

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

8 точки общо

10 успешни теста
2 неуспешни теста
Код (дано третият път е на късмет и без безкрайни цикли)

  1import math
  2
  3
  4class Candy:
  5    def __init__(self, mass, uranium):
  6        self.mass = mass
  7        self.uranium = uranium
  8        
  9    def get_uranium_quantity(self):
 10        return self.mass * self.uranium
 11    
 12    def get_mass(self):
 13        return self.mass
 14    
 15    
 16class Person:
 17    def __init__(self, position):
 18        self.position = list(position)
 19        
 20    def get_position(self):
 21        return self.position
 22    
 23    def set_position(self, new_position):
 24        self.position[0] = new_position[0]
 25        self.position[1] = new_position[1]
 26        
 27        
 28class Kid(Person):
 29    def __init__(self, position, initiative):
 30        super().__init__(position)
 31        self.initiative = initiative
 32        self.bucket = []
 33        self.meeted_hosts = []
 34        
 35    def get_initiative(self):
 36        return self.initiative
 37    
 38    def add_candy(self, candy):
 39        self.bucket.append(candy)
 40        
 41    def is_critical(self) :
 42        sum = 0
 43        for candy in self.bucket :
 44            sum += candy.get_uranium_quantity()
 45        return sum > 20
 46        #return sum(candy.get_uranium_quantity() for candy in self.bucket) > 20
 47    
 48    
 49def choose_candy(bucket):
 50    return max(bucket, key=lambda candy: candy.get_mass())
 51
 52
 53class Host(Person):
 54    def __init__(self, position, candies) :
 55        super().__init__(position)
 56        self.candies = candies
 57        self.bucket = []
 58        for candy in candies:
 59            current_candy = Candy(*candy)
 60            self.bucket.append(current_candy)
 61            
 62    def remove_candy(self, choose_candy_func) :
 63        if not self.bucket:
 64            return None
 65        chosen_candy = choose_candy_func(self.bucket)
 66        self.bucket.remove(chosen_candy)
 67        return chosen_candy
 68    
 69    
 70def find_distance(kid_position, host_positon) :
 71    return math.sqrt((kid_position[0] - host_positon[0])**2 + (kid_position[1] - host_positon[1])**2)
 72
 73
 74def find_closest(kid, hosts) :
 75    if not hosts :
 76        return None
 77    closest_dist = float('inf') #това го видях от chatgpt, понеже в python няма int_max
 78    closest_host = None
 79    for host in hosts :
 80        if host not in kid.meeted_hosts and host != closest_host :
 81            curr_dist = find_distance(kid.position, host.position)
 82            if curr_dist < closest_dist :
 83                closest_dist = curr_dist
 84                closest_host = host
 85            elif curr_dist == closest_dist :
 86                curr_x, curr_y = host.get_position()
 87                closest_x, closest_y = closest_host.get_position()
 88                if curr_x < closest_x or (curr_x == closest_x and curr_y < closest_y) :
 89                    closest_dist = curr_dist
 90                    closest_host = host
 91    return closest_host    
 92    
 93    
 94class FluxCapacitor:
 95    def __init__(self, participants) :
 96        self.kids = []
 97        self.hosts = []
 98        self.victim_set = set()
 99        for human in participants :
100            if isinstance(human, Kid) :
101                self.kids.append(human)
102            elif isinstance(human, Host) :
103                self.hosts.append(human)
104                
105    def get_victim(self):
106        is_finished = False
107        if not self.kids :
108            return None
109        while not is_finished :
110            for kid in sorted(self.kids, key=lambda x: x.get_initiative(), reverse=True) :
111                closest_host = find_closest(kid, self.hosts)
112                if closest_host is None :
113                    self.kids.remove(kid)
114                    continue
115                curr_candy = closest_host.remove_candy(choose_candy)
116                if curr_candy == None :
117                    kid.meeted_hosts.append(closest_host)
118                    continue
119                kid.add_candy(curr_candy)
120                kid.meeted_hosts.append(closest_host)
121                kid.set_position(closest_host.get_position())
122                if kid.is_critical() :
123                    self.victim_set.add(kid)
124                    self.kids.remove(kid)           
125            if len(self.victim_set) != 0 : 
126                return self.victim_set
127            if not self.kids :
128                    is_finished = True
129                    break
130        return None

........F..F
======================================================================
FAIL: test_basic_usage (test.KidTest)
Test basic usage of Kid class.
----------------------------------------------------------------------
Traceback (most recent call last):
File "/tmp/test.py", line 39, in test_basic_usage
self.assertEqual(kid.get_position(), (0, 0))
AssertionError: [0, 0] != (0, 0)

======================================================================
FAIL: test_basic_usage (test.PersonTest)
Test basic usage of Person class.
----------------------------------------------------------------------
Traceback (most recent call last):
File "/tmp/test.py", line 24, in test_basic_usage
self.assertEqual(person.get_position(), (0, 0))
AssertionError: [0, 0] != (0, 0)

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

FAILED (failures=2)

Дискусия
Георги Кунчев
07.11.2023 14:53

Модифицирахме сайта си, така че дори да имаш безкраен цикъл, това ще афектира само част от тестовете, в които стигаш до този цикъл. Вече не трябва да се притесняваш от нула точки. Но, да ти дам обратна връзка - вече нямаш проблем с безкрайни цикли.
Георги Кунчев
06.11.2023 21:22

Не, все още имаш безкраен цикъл.
Георги Кунчев
06.11.2023 08:53

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

f1import mathf1import math
22
33
4class Candy:4class Candy:
5    def __init__(self, mass, uranium):5    def __init__(self, mass, uranium):
6        self.mass = mass6        self.mass = mass
7        self.uranium = uranium7        self.uranium = uranium
8        8        
9    def get_uranium_quantity(self):9    def get_uranium_quantity(self):
10        return self.mass * self.uranium10        return self.mass * self.uranium
11    11    
12    def get_mass(self):12    def get_mass(self):
13        return self.mass13        return self.mass
14    14    
15    15    
16class Person:16class Person:
17    def __init__(self, position):17    def __init__(self, position):
18        self.position = list(position)18        self.position = list(position)
19        19        
20    def get_position(self):20    def get_position(self):
21        return self.position21        return self.position
22    22    
23    def set_position(self, new_position):23    def set_position(self, new_position):
24        self.position[0] = new_position[0]24        self.position[0] = new_position[0]
25        self.position[1] = new_position[1]25        self.position[1] = new_position[1]
26        26        
27        27        
28class Kid(Person):28class Kid(Person):
29    def __init__(self, position, initiative):29    def __init__(self, position, initiative):
30        super().__init__(position)30        super().__init__(position)
31        self.initiative = initiative31        self.initiative = initiative
32        self.bucket = []32        self.bucket = []
33        self.meeted_hosts = []33        self.meeted_hosts = []
34        34        
35    def get_initiative(self):35    def get_initiative(self):
36        return self.initiative36        return self.initiative
37    37    
38    def add_candy(self, candy):38    def add_candy(self, candy):
39        self.bucket.append(candy)39        self.bucket.append(candy)
40        40        
n41    def is_critical(self):n41    def is_critical(self) :
42        sum = 0
43        for candy in self.bucket :
44            sum += candy.get_uranium_quantity()
45        return sum > 20
42        return sum(candy.get_uranium_quantity() for candy in self.bucket) > 2046        #return sum(candy.get_uranium_quantity() for candy in self.bucket) > 20
43    47    
44    48    
45def choose_candy(bucket):49def choose_candy(bucket):
46    return max(bucket, key=lambda candy: candy.get_mass())50    return max(bucket, key=lambda candy: candy.get_mass())
4751
4852
49class Host(Person):53class Host(Person):
50    def __init__(self, position, candies) :54    def __init__(self, position, candies) :
51        super().__init__(position)55        super().__init__(position)
52        self.candies = candies56        self.candies = candies
53        self.bucket = []57        self.bucket = []
54        for candy in candies:58        for candy in candies:
55            current_candy = Candy(*candy)59            current_candy = Candy(*candy)
56            self.bucket.append(current_candy)60            self.bucket.append(current_candy)
57            61            
58    def remove_candy(self, choose_candy_func) :62    def remove_candy(self, choose_candy_func) :
59        if not self.bucket:63        if not self.bucket:
60            return None64            return None
61        chosen_candy = choose_candy_func(self.bucket)65        chosen_candy = choose_candy_func(self.bucket)
62        self.bucket.remove(chosen_candy)66        self.bucket.remove(chosen_candy)
63        return chosen_candy67        return chosen_candy
64    68    
65    69    
66def find_distance(kid_position, host_positon) :70def find_distance(kid_position, host_positon) :
67    return math.sqrt((kid_position[0] - host_positon[0])**2 + (kid_position[1] - host_positon[1])**2)71    return math.sqrt((kid_position[0] - host_positon[0])**2 + (kid_position[1] - host_positon[1])**2)
6872
6973
70def find_closest(kid, hosts) :74def find_closest(kid, hosts) :
71    if not hosts :75    if not hosts :
72        return None76        return None
73    closest_dist = float('inf') #това го видях от chatgpt, понеже в python няма int_max77    closest_dist = float('inf') #това го видях от chatgpt, понеже в python няма int_max
74    closest_host = None78    closest_host = None
75    for host in hosts :79    for host in hosts :
76        if host not in kid.meeted_hosts and host != closest_host :80        if host not in kid.meeted_hosts and host != closest_host :
77            curr_dist = find_distance(kid.position, host.position)81            curr_dist = find_distance(kid.position, host.position)
78            if curr_dist < closest_dist :82            if curr_dist < closest_dist :
79                closest_dist = curr_dist83                closest_dist = curr_dist
80                closest_host = host84                closest_host = host
81            elif curr_dist == closest_dist :85            elif curr_dist == closest_dist :
82                curr_x, curr_y = host.get_position()86                curr_x, curr_y = host.get_position()
83                closest_x, closest_y = closest_host.get_position()87                closest_x, closest_y = closest_host.get_position()
84                if curr_x < closest_x or (curr_x == closest_x and curr_y < closest_y) :88                if curr_x < closest_x or (curr_x == closest_x and curr_y < closest_y) :
85                    closest_dist = curr_dist89                    closest_dist = curr_dist
86                    closest_host = host90                    closest_host = host
87    return closest_host    91    return closest_host    
88    92    
89    93    
90class FluxCapacitor:94class FluxCapacitor:
91    def __init__(self, participants) :95    def __init__(self, participants) :
92        self.kids = []96        self.kids = []
93        self.hosts = []97        self.hosts = []
94        self.victim_set = set()98        self.victim_set = set()
95        for human in participants :99        for human in participants :
96            if isinstance(human, Kid) :100            if isinstance(human, Kid) :
97                self.kids.append(human)101                self.kids.append(human)
98            elif isinstance(human, Host) :102            elif isinstance(human, Host) :
99                self.hosts.append(human)103                self.hosts.append(human)
100                104                
101    def get_victim(self):105    def get_victim(self):
102        is_finished = False106        is_finished = False
103        if not self.kids :107        if not self.kids :
104            return None108            return None
105        while not is_finished :109        while not is_finished :
106            for kid in sorted(self.kids, key=lambda x: x.get_initiative(), reverse=True) :110            for kid in sorted(self.kids, key=lambda x: x.get_initiative(), reverse=True) :
107                closest_host = find_closest(kid, self.hosts)111                closest_host = find_closest(kid, self.hosts)
108                if closest_host is None :112                if closest_host is None :
109                    self.kids.remove(kid)113                    self.kids.remove(kid)
110                    continue114                    continue
111                curr_candy = closest_host.remove_candy(choose_candy)115                curr_candy = closest_host.remove_candy(choose_candy)
112                if curr_candy == None :116                if curr_candy == None :
tt117                    kid.meeted_hosts.append(closest_host)
113                    continue118                    continue
114                kid.add_candy(curr_candy)119                kid.add_candy(curr_candy)
115                kid.meeted_hosts.append(closest_host)120                kid.meeted_hosts.append(closest_host)
116                kid.set_position(closest_host.get_position())121                kid.set_position(closest_host.get_position())
117                if kid.is_critical() :122                if kid.is_critical() :
118                    self.victim_set.add(kid)123                    self.victim_set.add(kid)
119                    self.kids.remove(kid)           124                    self.kids.remove(kid)           
120            if len(self.victim_set) != 0 : 125            if len(self.victim_set) != 0 : 
121                return self.victim_set126                return self.victim_set
122            if not self.kids :127            if not self.kids :
123                    is_finished = True128                    is_finished = True
124                    break129                    break
125        return None130        return None
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op

f1import mathf1import math
22
33
4class Candy:4class Candy:
5    def __init__(self, mass, uranium):5    def __init__(self, mass, uranium):
6        self.mass = mass6        self.mass = mass
7        self.uranium = uranium7        self.uranium = uranium
8        8        
9    def get_uranium_quantity(self):9    def get_uranium_quantity(self):
10        return self.mass * self.uranium10        return self.mass * self.uranium
11    11    
12    def get_mass(self):12    def get_mass(self):
13        return self.mass13        return self.mass
14    14    
15    15    
16class Person:16class Person:
17    def __init__(self, position):17    def __init__(self, position):
18        self.position = list(position)18        self.position = list(position)
19        19        
20    def get_position(self):20    def get_position(self):
21        return self.position21        return self.position
22    22    
23    def set_position(self, new_position):23    def set_position(self, new_position):
24        self.position[0] = new_position[0]24        self.position[0] = new_position[0]
25        self.position[1] = new_position[1]25        self.position[1] = new_position[1]
26        26        
27        27        
28class Kid(Person):28class Kid(Person):
29    def __init__(self, position, initiative):29    def __init__(self, position, initiative):
30        super().__init__(position)30        super().__init__(position)
31        self.initiative = initiative31        self.initiative = initiative
32        self.bucket = []32        self.bucket = []
33        self.meeted_hosts = []33        self.meeted_hosts = []
34        34        
35    def get_initiative(self):35    def get_initiative(self):
36        return self.initiative36        return self.initiative
37    37    
38    def add_candy(self, candy):38    def add_candy(self, candy):
39        self.bucket.append(candy)39        self.bucket.append(candy)
40        40        
41    def is_critical(self):41    def is_critical(self):
42        return sum(candy.get_uranium_quantity() for candy in self.bucket) > 2042        return sum(candy.get_uranium_quantity() for candy in self.bucket) > 20
43    43    
44    44    
45def choose_candy(bucket):45def choose_candy(bucket):
46    return max(bucket, key=lambda candy: candy.get_mass())46    return max(bucket, key=lambda candy: candy.get_mass())
4747
4848
49class Host(Person):49class Host(Person):
n50    def __init__(self, position, candies):n50    def __init__(self, position, candies) :
51        super().__init__(position)51        super().__init__(position)
52        self.candies = candies52        self.candies = candies
53        self.bucket = []53        self.bucket = []
54        for candy in candies:54        for candy in candies:
55            current_candy = Candy(*candy)55            current_candy = Candy(*candy)
56            self.bucket.append(current_candy)56            self.bucket.append(current_candy)
57            57            
n58    def remove_candy(self, choose_candy_func):n58    def remove_candy(self, choose_candy_func) :
59        if not self.bucket:59        if not self.bucket:
60            return None60            return None
61        chosen_candy = choose_candy_func(self.bucket)61        chosen_candy = choose_candy_func(self.bucket)
62        self.bucket.remove(chosen_candy)62        self.bucket.remove(chosen_candy)
63        return chosen_candy63        return chosen_candy
64    64    
65    65    
n66def find_distance(kid_position, host_positon):n66def find_distance(kid_position, host_positon) :
67    return math.sqrt((kid_position[0] - host_positon[0])**2 + (kid_position[1] - host_positon[1])**2)67    return math.sqrt((kid_position[0] - host_positon[0])**2 + (kid_position[1] - host_positon[1])**2)
6868
6969
n70def find_closest(kid, hosts):n70def find_closest(kid, hosts) :
71    if not hosts :71    if not hosts :
72        return None72        return None
73    closest_dist = float('inf') #това го видях от chatgpt, понеже в python няма int_max73    closest_dist = float('inf') #това го видях от chatgpt, понеже в python няма int_max
74    closest_host = None74    closest_host = None
n75    for host in hosts:n75    for host in hosts :
76        if host not in kid.meeted_hosts and host != closest_host :76        if host not in kid.meeted_hosts and host != closest_host :
77            curr_dist = find_distance(kid.position, host.position)77            curr_dist = find_distance(kid.position, host.position)
n78            if curr_dist < closest_dist:n78            if curr_dist < closest_dist :
79                closest_dist = curr_dist79                closest_dist = curr_dist
80                closest_host = host80                closest_host = host
n81            elif curr_dist == closest_dist:n81            elif curr_dist == closest_dist :
82                curr_x, curr_y = host.get_position()82                curr_x, curr_y = host.get_position()
83                closest_x, closest_y = closest_host.get_position()83                closest_x, closest_y = closest_host.get_position()
n84                if curr_x < closest_x or (curr_x == closest_x and curr_y < closest_y):n84                if curr_x < closest_x or (curr_x == closest_x and curr_y < closest_y) :
85                    closest_dist = curr_dist85                    closest_dist = curr_dist
86                    closest_host = host86                    closest_host = host
87    return closest_host    87    return closest_host    
88    88    
89    89    
90class FluxCapacitor:90class FluxCapacitor:
n91    def __init__(self, participants):n91    def __init__(self, participants) :
92        self.kids = []92        self.kids = []
93        self.hosts = []93        self.hosts = []
94        self.victim_set = set()94        self.victim_set = set()
n95        for human in participants:n95        for human in participants :
96            if isinstance(human, Kid) :96            if isinstance(human, Kid) :
97                self.kids.append(human)97                self.kids.append(human)
98            elif isinstance(human, Host) :98            elif isinstance(human, Host) :
99                self.hosts.append(human)99                self.hosts.append(human)
100                100                
101    def get_victim(self):101    def get_victim(self):
102        is_finished = False102        is_finished = False
n103        if not self.kids:n103        if not self.kids :
104            return None104            return None
n105        while(not is_finished):n105        while not is_finished :
106            for kid in sorted(self.kids, key=lambda x: x.get_initiative(), reverse=True):106            for kid in sorted(self.kids, key=lambda x: x.get_initiative(), reverse=True) :
107                closest_host = find_closest(kid, self.hosts)107                closest_host = find_closest(kid, self.hosts)
n108                if(closest_host is None):n108                if closest_host is None :
109                    self.kids.remove(kid)109                    self.kids.remove(kid)
110                    continue110                    continue
111                curr_candy = closest_host.remove_candy(choose_candy)111                curr_candy = closest_host.remove_candy(choose_candy)
n112                if curr_candy == None:n112                if curr_candy == None :
113                    continue113                    continue
114                kid.add_candy(curr_candy)114                kid.add_candy(curr_candy)
115                kid.meeted_hosts.append(closest_host)115                kid.meeted_hosts.append(closest_host)
116                kid.set_position(closest_host.get_position())116                kid.set_position(closest_host.get_position())
117                if kid.is_critical() :117                if kid.is_critical() :
118                    self.victim_set.add(kid)118                    self.victim_set.add(kid)
119                    self.kids.remove(kid)           119                    self.kids.remove(kid)           
n120            if len(self.victim_set) != 0: n120            if len(self.victim_set) != 0 
121                return self.victim_set121                return self.victim_set
t122            if not self.kids:t122            if not self.kids :
123                    is_finished = True123                    is_finished = True
124                    break124                    break
125        return None125        return None
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op

f1import mathf1import math
nn2 
23
3class Candy:4class Candy:
4    def __init__(self, mass, uranium):5    def __init__(self, mass, uranium):
5        self.mass = mass6        self.mass = mass
n6        if uranium < 0 or uranium > 1 :n
7            raise ValueError("Value must be between 0 and 1")
8        self.uranium = uranium7        self.uranium = uranium
9        8        
10    def get_uranium_quantity(self):9    def get_uranium_quantity(self):
11        return self.mass * self.uranium10        return self.mass * self.uranium
12    11    
13    def get_mass(self):12    def get_mass(self):
14        return self.mass13        return self.mass
15    14    
16    15    
17class Person:16class Person:
18    def __init__(self, position):17    def __init__(self, position):
19        self.position = list(position)18        self.position = list(position)
20        19        
21    def get_position(self):20    def get_position(self):
22        return self.position21        return self.position
23    22    
24    def set_position(self, new_position):23    def set_position(self, new_position):
25        self.position[0] = new_position[0]24        self.position[0] = new_position[0]
26        self.position[1] = new_position[1]25        self.position[1] = new_position[1]
27        26        
28        27        
29class Kid(Person):28class Kid(Person):
30    def __init__(self, position, initiative):29    def __init__(self, position, initiative):
31        super().__init__(position)30        super().__init__(position)
n32        self.initative = initiativen31        self.initiative = initiative
33        self.bucket = []32        self.bucket = []
34        self.meeted_hosts = []33        self.meeted_hosts = []
35        34        
n36    def get_iniative(self):n35    def get_initiative(self):
37        return self.initative36        return self.initiative
38    37    
39    def add_candy(self, candy):38    def add_candy(self, candy):
40        self.bucket.append(candy)39        self.bucket.append(candy)
41        40        
42    def is_critical(self):41    def is_critical(self):
n43        sum = 0n42        return sum(candy.get_uranium_quantity() for candy in self.bucket) > 20
44        for candy in self.bucket:43    
45            sum += candy.get_uranium_quantity()
46        return sum > 20
47    44    
48def choose_candy(bucket):45def choose_candy(bucket):
49    return max(bucket, key=lambda candy: candy.get_mass())46    return max(bucket, key=lambda candy: candy.get_mass())
nn47 
5048
51class Host(Person):49class Host(Person):
52    def __init__(self, position, candies):50    def __init__(self, position, candies):
53        super().__init__(position)51        super().__init__(position)
54        self.candies = candies52        self.candies = candies
55        self.bucket = []53        self.bucket = []
56        for candy in candies:54        for candy in candies:
n57            current_candy = Candy(candy[0], candy[1])n55            current_candy = Candy(*candy)
58            self.bucket.append(current_candy)56            self.bucket.append(current_candy)
59            57            
60    def remove_candy(self, choose_candy_func):58    def remove_candy(self, choose_candy_func):
61        if not self.bucket:59        if not self.bucket:
62            return None60            return None
63        chosen_candy = choose_candy_func(self.bucket)61        chosen_candy = choose_candy_func(self.bucket)
64        self.bucket.remove(chosen_candy)62        self.bucket.remove(chosen_candy)
65        return chosen_candy63        return chosen_candy
66    64    
nn65    
67def find_distance(kid_position, host_positon):66def find_distance(kid_position, host_positon):
68    return math.sqrt((kid_position[0] - host_positon[0])**2 + (kid_position[1] - host_positon[1])**2)67    return math.sqrt((kid_position[0] - host_positon[0])**2 + (kid_position[1] - host_positon[1])**2)
nn68 
6969
70def find_closest(kid, hosts):70def find_closest(kid, hosts):
71    if not hosts :71    if not hosts :
72        return None72        return None
73    closest_dist = float('inf') #това го видях от chatgpt, понеже в python няма int_max73    closest_dist = float('inf') #това го видях от chatgpt, понеже в python няма int_max
74    closest_host = None74    closest_host = None
75    for host in hosts:75    for host in hosts:
76        if host not in kid.meeted_hosts and host != closest_host :76        if host not in kid.meeted_hosts and host != closest_host :
77            curr_dist = find_distance(kid.position, host.position)77            curr_dist = find_distance(kid.position, host.position)
78            if curr_dist < closest_dist:78            if curr_dist < closest_dist:
79                closest_dist = curr_dist79                closest_dist = curr_dist
80                closest_host = host80                closest_host = host
81            elif curr_dist == closest_dist:81            elif curr_dist == closest_dist:
82                curr_x, curr_y = host.get_position()82                curr_x, curr_y = host.get_position()
83                closest_x, closest_y = closest_host.get_position()83                closest_x, closest_y = closest_host.get_position()
84                if curr_x < closest_x or (curr_x == closest_x and curr_y < closest_y):84                if curr_x < closest_x or (curr_x == closest_x and curr_y < closest_y):
85                    closest_dist = curr_dist85                    closest_dist = curr_dist
86                    closest_host = host86                    closest_host = host
87    return closest_host    87    return closest_host    
88    88    
89    89    
90class FluxCapacitor:90class FluxCapacitor:
91    def __init__(self, participants):91    def __init__(self, participants):
92        self.kids = []92        self.kids = []
93        self.hosts = []93        self.hosts = []
94        self.victim_set = set()94        self.victim_set = set()
95        for human in participants:95        for human in participants:
n96            if(type(human) == Kid):n96            if isinstance(human, Kid) :
97                self.kids.append(human)97                self.kids.append(human)
n98            elif(type(human) == Host):n98            elif isinstance(human, Host) :
99                self.hosts.append(human)99                self.hosts.append(human)
100                100                
101    def get_victim(self):101    def get_victim(self):
102        is_finished = False102        is_finished = False
nn103        if not self.kids:
104            return None
103        while(is_finished == False):105        while(not is_finished):
104            for kid in sorted(self.kids, key=lambda x: x.get_iniative(), reverse=True):106            for kid in sorted(self.kids, key=lambda x: x.get_initiative(), reverse=True):
105                closest_host = find_closest(kid, self.hosts)107                closest_host = find_closest(kid, self.hosts)
n106                if(closest_host == None):n108                if(closest_host is None):
107                    self.kids.remove(kid)109                    self.kids.remove(kid)
108                    continue110                    continue
109                curr_candy = closest_host.remove_candy(choose_candy)111                curr_candy = closest_host.remove_candy(choose_candy)
110                if curr_candy == None:112                if curr_candy == None:
111                    continue113                    continue
112                kid.add_candy(curr_candy)114                kid.add_candy(curr_candy)
113                kid.meeted_hosts.append(closest_host)115                kid.meeted_hosts.append(closest_host)
114                kid.set_position(closest_host.get_position())116                kid.set_position(closest_host.get_position())
115                if kid.is_critical() :117                if kid.is_critical() :
116                    self.victim_set.add(kid)118                    self.victim_set.add(kid)
117                    self.kids.remove(kid)           119                    self.kids.remove(kid)           
118            if len(self.victim_set) != 0: 120            if len(self.victim_set) != 0: 
119                return self.victim_set121                return self.victim_set
120            if not self.kids:122            if not self.kids:
121                    is_finished = True123                    is_finished = True
tt124                    break
122        return None125        return None
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op