From 681b67b25d164d106e13d595e39ee5bdf353cdab Mon Sep 17 00:00:00 2001 From: Pavel Date: Thu, 7 Nov 2019 11:07:23 +0100 Subject: [PATCH] improve random_attack --- python/tipc19py.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/python/tipc19py.py b/python/tipc19py.py index 4c78d81..ea0095b 100644 --- a/python/tipc19py.py +++ b/python/tipc19py.py @@ -132,22 +132,22 @@ def random_pokemon(code): def random_attack(code): score_max = fast_score(code) for k in range(300): - code_next = code.copy() - i = 10 - j = 10 - while i == j: + while True: i = randint(10, 19) j = randint(10, 19) + if i != j: + break d = randint(-93, 93) - vi = code_next[i] + d - vj = code_next[j] - d + vi = code[i] + d + vj = code[j] - d if vi >= 0 and vi <= 93 and vj >= 0 and vj <= 93: + code_next = code.copy() code_next[i] = vi code_next[j] = vj - score = fast_score(code_next) - if score_max < score: + score_next = fast_score(code_next) + if score_max < score_next: code[:] = code_next - score_max = score + score_max = score_next seed(time())