scuffed evolution algorithm
This commit is contained in:
parent
be022504c5
commit
480401f8fd
Before Width: | Height: | Size: 134 KiB After Width: | Height: | Size: 134 KiB |
@ -87,13 +87,33 @@ class AI:
|
||||
|
||||
|
||||
def bfs(self):
|
||||
def mojafunkcja(ileczasu, jakdaleko, jaktrudno, jakciezko):
|
||||
return ((200-ileczasu)+(200-jakdaleko*10))-jaktrudno*jakciezko
|
||||
|
||||
def fitness(x, y, z, w): #funkcja do ewaluacji
|
||||
ans = mojafunkcja(x, y, z, w)
|
||||
return abs(ans-400)
|
||||
dists = [] # how long way is to all encounters from start([0, 0])
|
||||
ranked = []
|
||||
for encounter in self.current_map.encounters:
|
||||
# dists.append(sqrt((self.saper.position_x-mine.position_x)**2 + (self.saper.position_y-mine.position_y)**2))
|
||||
dists.append(abs(self.saper.position_x - encounter.position_x) + abs(self.saper.position_y - encounter.position_y))
|
||||
#print(dists)
|
||||
ind = dists.index(min(dists)) # choose nearest mine
|
||||
goal_state = [self.current_map.encounters[ind].position_x, self.current_map.encounters[ind].position_y]
|
||||
|
||||
for a in self.current_map.mines:
|
||||
ranked.append((fitness(a.explosion_timer, (abs(self.saper.position_x - encounter.position_x) + abs(self.saper.position_y - encounter.position_y)), a.difficulty, a.weight), a))
|
||||
ranked.sort() #posortowana lista najlepszych wyborów dla min
|
||||
if ranked:
|
||||
print(ranked[0][0])
|
||||
indx = ranked[0][1].position_x
|
||||
indy = ranked[0][1].position_y
|
||||
else:
|
||||
ind = dists.index(min(dists))
|
||||
indx = self.current_map.encounters[ind].position_x
|
||||
indy = self.current_map.encounters[ind].position_y
|
||||
|
||||
|
||||
|
||||
|
||||
goal_state = [indx, indy]
|
||||
print(f'We go to {goal_state}')
|
||||
|
||||
find_path = bfs.BFS(self.saper, self.window)
|
||||
|
@ -1,31 +1,31 @@
|
||||
[
|
||||
{"current_level": 1, "leaf_id": "2d804728-e749-11ec-ae0d-d43d7ef1576e", "parents": "root", "rule": "else: return 'detonate'", "feature_idx": -1, "feature_name": "", "instances": 200, "metric": 0, "return_statement": 0, "tree_id": 0},
|
||||
{"current_level": 1, "leaf_id": "2d81316f-e749-11ec-9802-d43d7ef1576e", "parents": "root", "rule": "if obj[4]<=80.67436609605278:", "feature_idx": 4, "feature_name": "Random_detonation_chance", "instances": 200, "metric": 0.9964625048848765, "return_statement": 0, "tree_id": 0},
|
||||
{"current_level": 2, "leaf_id": "2d8f8825-e749-11ec-a3fb-d43d7ef1576e", "parents": "2d81316f-e749-11ec-9802-d43d7ef1576e", "rule": "else: return 'detonate'", "feature_idx": -1, "feature_name": "", "instances": 161, "metric": 0, "return_statement": 0, "tree_id": 0},
|
||||
{"current_level": 2, "leaf_id": "2d90726e-e749-11ec-bfae-d43d7ef1576e", "parents": "2d81316f-e749-11ec-9802-d43d7ef1576e", "rule": "if obj[2]<=0:", "feature_idx": 2, "feature_name": "Protection_from_defuse", "instances": 161, "metric": 0.9203523274205176, "return_statement": 0, "tree_id": 0},
|
||||
{"current_level": 3, "leaf_id": "2d9dded6-e749-11ec-9432-d43d7ef1576e", "parents": "2d90726e-e749-11ec-bfae-d43d7ef1576e", "rule": "else: return 'detonate'", "feature_idx": -1, "feature_name": "", "instances": 135, "metric": 0, "return_statement": 0, "tree_id": 0},
|
||||
{"current_level": 3, "leaf_id": "2d9ef023-e749-11ec-8f51-d43d7ef1576e", "parents": "2d90726e-e749-11ec-bfae-d43d7ef1576e", "rule": "if obj[3]<=7:", "feature_idx": 3, "feature_name": "Meters_under_the_ground", "instances": 135, "metric": 0.7364977795505669, "return_statement": 0, "tree_id": 0},
|
||||
{"current_level": 4, "leaf_id": "2da8da63-e749-11ec-acec-d43d7ef1576e", "parents": "2d9ef023-e749-11ec-8f51-d43d7ef1576e", "rule": "else: return 'defuse'", "feature_idx": -1, "feature_name": "", "instances": 116, "metric": 0, "return_statement": 0, "tree_id": 0},
|
||||
{"current_level": 4, "leaf_id": "2da9ec73-e749-11ec-b423-d43d7ef1576e", "parents": "2d9ef023-e749-11ec-8f51-d43d7ef1576e", "rule": "if obj[1]<=1997.8794790831414:", "feature_idx": 1, "feature_name": "Year(older_more_difficult)", "instances": 116, "metric": 0.3936164041111624, "return_statement": 0, "tree_id": 0},
|
||||
{"current_level": 5, "leaf_id": "2db117cc-e749-11ec-ba73-d43d7ef1576e", "parents": "2da9ec73-e749-11ec-b423-d43d7ef1576e", "rule": "else: return 'defuse'", "feature_idx": -1, "feature_name": "", "instances": 97, "metric": 0, "return_statement": 0, "tree_id": 0},
|
||||
{"current_level": 5, "leaf_id": "2db2286d-e749-11ec-9a48-d43d7ef1576e", "parents": "2da9ec73-e749-11ec-b423-d43d7ef1576e", "rule": "if obj[5]<=2:", "feature_idx": 5, "feature_name": "Detonation_power_in_m", "instances": 97, "metric": 0.445693177722561, "return_statement": 0, "tree_id": 0},
|
||||
{"current_level": 6, "leaf_id": "2db5f8ab-e749-11ec-94f9-d43d7ef1576e", "parents": "2db2286d-e749-11ec-9a48-d43d7ef1576e", "rule": "else: return 'defuse'", "feature_idx": -1, "feature_name": "", "instances": 65, "metric": 0, "return_statement": 0, "tree_id": 0},
|
||||
{"current_level": 6, "leaf_id": "2db70a13-e749-11ec-85e8-d43d7ef1576e", "parents": "2db2286d-e749-11ec-9a48-d43d7ef1576e", "rule": "if obj[0]>3:", "feature_idx": 0, "feature_name": "Size(bigger_more_difficult)", "instances": 65, "metric": 0.33352200393097664, "return_statement": 0, "tree_id": 0},
|
||||
{"current_level": 7, "leaf_id": "2db70a14-e749-11ec-8eed-d43d7ef1576e", "parents": "2db70a13-e749-11ec-85e8-d43d7ef1576e", "rule": "return 'defuse'", "feature_idx": 0, "feature_name": "Size(bigger_more_difficult)", "instances": 65, "metric": 0, "return_statement": 1, "tree_id": 0},
|
||||
{"current_level": 6, "leaf_id": "2dc2c8dc-e749-11ec-be38-d43d7ef1576e", "parents": "2db2286d-e749-11ec-9a48-d43d7ef1576e", "rule": "if obj[0]<=3:", "feature_idx": 0, "feature_name": "Size(bigger_more_difficult)", "instances": 65, "metric": 0.33352200393097664, "return_statement": 0, "tree_id": 0},
|
||||
{"current_level": 7, "leaf_id": "2dc2c8dd-e749-11ec-9e73-d43d7ef1576e", "parents": "2dc2c8dc-e749-11ec-be38-d43d7ef1576e", "rule": "return 'defuse'", "feature_idx": 0, "feature_name": "Size(bigger_more_difficult)", "instances": 65, "metric": 0, "return_statement": 1, "tree_id": 0},
|
||||
{"current_level": 5, "leaf_id": "2dda202e-e749-11ec-83ae-d43d7ef1576e", "parents": "2da9ec73-e749-11ec-b423-d43d7ef1576e", "rule": "if obj[5]>2:", "feature_idx": 5, "feature_name": "Detonation_power_in_m", "instances": 97, "metric": 0.445693177722561, "return_statement": 0, "tree_id": 0},
|
||||
{"current_level": 6, "leaf_id": "2dddf03d-e749-11ec-9dea-d43d7ef1576e", "parents": "2dda202e-e749-11ec-83ae-d43d7ef1576e", "rule": "else: return 'defuse'", "feature_idx": -1, "feature_name": "", "instances": 32, "metric": 0, "return_statement": 0, "tree_id": 0},
|
||||
{"current_level": 6, "leaf_id": "2ddf01c7-e749-11ec-9cff-d43d7ef1576e", "parents": "2dda202e-e749-11ec-83ae-d43d7ef1576e", "rule": "if obj[0]<=7:", "feature_idx": 0, "feature_name": "Size(bigger_more_difficult)", "instances": 32, "metric": 0.6252624052234231, "return_statement": 0, "tree_id": 0},
|
||||
{"current_level": 7, "leaf_id": "2ddf01c8-e749-11ec-b129-d43d7ef1576e", "parents": "2ddf01c7-e749-11ec-9cff-d43d7ef1576e", "rule": "return 'defuse'", "feature_idx": 0, "feature_name": "Size(bigger_more_difficult)", "instances": 32, "metric": 0, "return_statement": 1, "tree_id": 0},
|
||||
{"current_level": 6, "leaf_id": "2deb0e8a-e749-11ec-a871-d43d7ef1576e", "parents": "2dda202e-e749-11ec-83ae-d43d7ef1576e", "rule": "if obj[0]>7:", "feature_idx": 0, "feature_name": "Size(bigger_more_difficult)", "instances": 32, "metric": 0.6252624052234231, "return_statement": 0, "tree_id": 0},
|
||||
{"current_level": 7, "leaf_id": "2deb0e8b-e749-11ec-9c32-d43d7ef1576e", "parents": "2deb0e8a-e749-11ec-a871-d43d7ef1576e", "rule": "return 'defuse'", "feature_idx": 0, "feature_name": "Size(bigger_more_difficult)", "instances": 32, "metric": 0, "return_statement": 1, "tree_id": 0},
|
||||
{"current_level": 4, "leaf_id": "2e0e7215-e749-11ec-b6df-d43d7ef1576e", "parents": "2d9ef023-e749-11ec-8f51-d43d7ef1576e", "rule": "if obj[1]>1997.8794790831414:", "feature_idx": 1, "feature_name": "Year(older_more_difficult)", "instances": 116, "metric": 0.3936164041111624, "return_statement": 0, "tree_id": 0},
|
||||
{"current_level": 5, "leaf_id": "2e0e7216-e749-11ec-86c6-d43d7ef1576e", "parents": "2e0e7215-e749-11ec-b6df-d43d7ef1576e", "rule": "return 'defuse'", "feature_idx": 1, "feature_name": "Year(older_more_difficult)", "instances": 116, "metric": 0, "return_statement": 1, "tree_id": 0},
|
||||
{"current_level": 3, "leaf_id": "2e26646c-e749-11ec-9044-d43d7ef1576e", "parents": "2d90726e-e749-11ec-bfae-d43d7ef1576e", "rule": "if obj[3]>7:", "feature_idx": 3, "feature_name": "Meters_under_the_ground", "instances": 135, "metric": 0.7364977795505669, "return_statement": 0, "tree_id": 0},
|
||||
{"current_level": 4, "leaf_id": "2e26646d-e749-11ec-a43b-d43d7ef1576e", "parents": "2e26646c-e749-11ec-9044-d43d7ef1576e", "rule": "return 'detonate'", "feature_idx": 3, "feature_name": "Meters_under_the_ground", "instances": 135, "metric": 0, "return_statement": 1, "tree_id": 0},
|
||||
{"current_level": 2, "leaf_id": "2e3ea553-e749-11ec-a56d-d43d7ef1576e", "parents": "2d81316f-e749-11ec-9802-d43d7ef1576e", "rule": "if obj[2]>0:", "feature_idx": 2, "feature_name": "Protection_from_defuse", "instances": 161, "metric": 0.9203523274205176, "return_statement": 0, "tree_id": 0},
|
||||
{"current_level": 3, "leaf_id": "2e3ea554-e749-11ec-9e27-d43d7ef1576e", "parents": "2e3ea553-e749-11ec-a56d-d43d7ef1576e", "rule": "return 'detonate'", "feature_idx": 2, "feature_name": "Protection_from_defuse", "instances": 161, "metric": 0, "return_statement": 1, "tree_id": 0},
|
||||
{"current_level": 1, "leaf_id": "2e567198-e749-11ec-86e3-d43d7ef1576e", "parents": "root", "rule": "if obj[4]>80.67436609605278:", "feature_idx": 4, "feature_name": "Random_detonation_chance", "instances": 200, "metric": 0.9964625048848765, "return_statement": 0, "tree_id": 0},
|
||||
{"current_level": 2, "leaf_id": "2e567199-e749-11ec-b99f-d43d7ef1576e", "parents": "2e567198-e749-11ec-86e3-d43d7ef1576e", "rule": "return 'detonate'", "feature_idx": 4, "feature_name": "Random_detonation_chance", "instances": 200, "metric": 0, "return_statement": 1, "tree_id": 0}
|
||||
{"current_level": 1, "leaf_id": "2ece3328-e767-11ec-802c-4ccc6afd6a08", "parents": "root", "rule": "else: return 'detonate'", "feature_idx": -1, "feature_name": "", "instances": 200, "metric": 0, "return_statement": 0, "tree_id": 0},
|
||||
{"current_level": 1, "leaf_id": "2ececefd-e767-11ec-804a-4ccc6afd6a08", "parents": "root", "rule": "if obj[4]<=80.67436609605278:", "feature_idx": 4, "feature_name": "Random_detonation_chance", "instances": 200, "metric": 0.9964625048848765, "return_statement": 0, "tree_id": 0},
|
||||
{"current_level": 2, "leaf_id": "2edc6e09-e767-11ec-b67a-4ccc6afd6a08", "parents": "2ececefd-e767-11ec-804a-4ccc6afd6a08", "rule": "else: return 'detonate'", "feature_idx": -1, "feature_name": "", "instances": 161, "metric": 0, "return_statement": 0, "tree_id": 0},
|
||||
{"current_level": 2, "leaf_id": "2edd09e1-e767-11ec-b87c-4ccc6afd6a08", "parents": "2ececefd-e767-11ec-804a-4ccc6afd6a08", "rule": "if obj[2]<=0:", "feature_idx": 2, "feature_name": "Protection_from_defuse", "instances": 161, "metric": 0.9203523274205176, "return_statement": 0, "tree_id": 0},
|
||||
{"current_level": 3, "leaf_id": "2ee9f96f-e767-11ec-b259-4ccc6afd6a08", "parents": "2edd09e1-e767-11ec-b87c-4ccc6afd6a08", "rule": "else: return 'detonate'", "feature_idx": -1, "feature_name": "", "instances": 135, "metric": 0, "return_statement": 0, "tree_id": 0},
|
||||
{"current_level": 3, "leaf_id": "2eea9544-e767-11ec-9dee-4ccc6afd6a08", "parents": "2edd09e1-e767-11ec-b87c-4ccc6afd6a08", "rule": "if obj[3]<=7:", "feature_idx": 3, "feature_name": "Meters_under_the_ground", "instances": 135, "metric": 0.7364977795505669, "return_statement": 0, "tree_id": 0},
|
||||
{"current_level": 4, "leaf_id": "2ef42ba3-e767-11ec-99b1-4ccc6afd6a08", "parents": "2eea9544-e767-11ec-9dee-4ccc6afd6a08", "rule": "else: return 'defuse'", "feature_idx": -1, "feature_name": "", "instances": 116, "metric": 0, "return_statement": 0, "tree_id": 0},
|
||||
{"current_level": 4, "leaf_id": "2ef4c777-e767-11ec-8b3d-4ccc6afd6a08", "parents": "2eea9544-e767-11ec-9dee-4ccc6afd6a08", "rule": "if obj[1]<=1997.8794790831414:", "feature_idx": 1, "feature_name": "Year(older_more_difficult)", "instances": 116, "metric": 0.3936164041111624, "return_statement": 0, "tree_id": 0},
|
||||
{"current_level": 5, "leaf_id": "2efb52ad-e767-11ec-a8d9-4ccc6afd6a08", "parents": "2ef4c777-e767-11ec-8b3d-4ccc6afd6a08", "rule": "else: return 'defuse'", "feature_idx": -1, "feature_name": "", "instances": 97, "metric": 0, "return_statement": 0, "tree_id": 0},
|
||||
{"current_level": 5, "leaf_id": "2efbef9f-e767-11ec-8aeb-4ccc6afd6a08", "parents": "2ef4c777-e767-11ec-8b3d-4ccc6afd6a08", "rule": "if obj[5]<=2:", "feature_idx": 5, "feature_name": "Detonation_power_in_m", "instances": 97, "metric": 0.445693177722561, "return_statement": 0, "tree_id": 0},
|
||||
{"current_level": 6, "leaf_id": "2eff6e8b-e767-11ec-a0f6-4ccc6afd6a08", "parents": "2efbef9f-e767-11ec-8aeb-4ccc6afd6a08", "rule": "else: return 'defuse'", "feature_idx": -1, "feature_name": "", "instances": 65, "metric": 0, "return_statement": 0, "tree_id": 0},
|
||||
{"current_level": 6, "leaf_id": "2f003159-e767-11ec-bc64-4ccc6afd6a08", "parents": "2efbef9f-e767-11ec-8aeb-4ccc6afd6a08", "rule": "if obj[0]>3:", "feature_idx": 0, "feature_name": "Size(bigger_more_difficult)", "instances": 65, "metric": 0.33352200393097664, "return_statement": 0, "tree_id": 0},
|
||||
{"current_level": 7, "leaf_id": "2f00315a-e767-11ec-b1ab-4ccc6afd6a08", "parents": "2f003159-e767-11ec-bc64-4ccc6afd6a08", "rule": "return 'defuse'", "feature_idx": 0, "feature_name": "Size(bigger_more_difficult)", "instances": 65, "metric": 0, "return_statement": 1, "tree_id": 0},
|
||||
{"current_level": 6, "leaf_id": "2f09062d-e767-11ec-bec0-4ccc6afd6a08", "parents": "2efbef9f-e767-11ec-8aeb-4ccc6afd6a08", "rule": "if obj[0]<=3:", "feature_idx": 0, "feature_name": "Size(bigger_more_difficult)", "instances": 65, "metric": 0.33352200393097664, "return_statement": 0, "tree_id": 0},
|
||||
{"current_level": 7, "leaf_id": "2f09062e-e767-11ec-b567-4ccc6afd6a08", "parents": "2f09062d-e767-11ec-bec0-4ccc6afd6a08", "rule": "return 'defuse'", "feature_idx": 0, "feature_name": "Size(bigger_more_difficult)", "instances": 65, "metric": 0, "return_statement": 1, "tree_id": 0},
|
||||
{"current_level": 5, "leaf_id": "2f1a3992-e767-11ec-bcb8-4ccc6afd6a08", "parents": "2ef4c777-e767-11ec-8b3d-4ccc6afd6a08", "rule": "if obj[5]>2:", "feature_idx": 5, "feature_name": "Detonation_power_in_m", "instances": 97, "metric": 0.445693177722561, "return_statement": 0, "tree_id": 0},
|
||||
{"current_level": 6, "leaf_id": "2f1df45d-e767-11ec-9b1a-4ccc6afd6a08", "parents": "2f1a3992-e767-11ec-bcb8-4ccc6afd6a08", "rule": "else: return 'defuse'", "feature_idx": -1, "feature_name": "", "instances": 32, "metric": 0, "return_statement": 0, "tree_id": 0},
|
||||
{"current_level": 6, "leaf_id": "2f1e9032-e767-11ec-8145-4ccc6afd6a08", "parents": "2f1a3992-e767-11ec-bcb8-4ccc6afd6a08", "rule": "if obj[0]<=7:", "feature_idx": 0, "feature_name": "Size(bigger_more_difficult)", "instances": 32, "metric": 0.6252624052234231, "return_statement": 0, "tree_id": 0},
|
||||
{"current_level": 7, "leaf_id": "2f1e9033-e767-11ec-ae84-4ccc6afd6a08", "parents": "2f1e9032-e767-11ec-8145-4ccc6afd6a08", "rule": "return 'defuse'", "feature_idx": 0, "feature_name": "Size(bigger_more_difficult)", "instances": 32, "metric": 0, "return_statement": 1, "tree_id": 0},
|
||||
{"current_level": 6, "leaf_id": "2f273cd1-e767-11ec-9821-4ccc6afd6a08", "parents": "2f1a3992-e767-11ec-bcb8-4ccc6afd6a08", "rule": "if obj[0]>7:", "feature_idx": 0, "feature_name": "Size(bigger_more_difficult)", "instances": 32, "metric": 0.6252624052234231, "return_statement": 0, "tree_id": 0},
|
||||
{"current_level": 7, "leaf_id": "2f273cd2-e767-11ec-96af-4ccc6afd6a08", "parents": "2f273cd1-e767-11ec-9821-4ccc6afd6a08", "rule": "return 'defuse'", "feature_idx": 0, "feature_name": "Size(bigger_more_difficult)", "instances": 32, "metric": 0, "return_statement": 1, "tree_id": 0},
|
||||
{"current_level": 4, "leaf_id": "2f4108be-e767-11ec-bfcb-4ccc6afd6a08", "parents": "2eea9544-e767-11ec-9dee-4ccc6afd6a08", "rule": "if obj[1]>1997.8794790831414:", "feature_idx": 1, "feature_name": "Year(older_more_difficult)", "instances": 116, "metric": 0.3936164041111624, "return_statement": 0, "tree_id": 0},
|
||||
{"current_level": 5, "leaf_id": "2f4108bf-e767-11ec-aecd-4ccc6afd6a08", "parents": "2f4108be-e767-11ec-bfcb-4ccc6afd6a08", "rule": "return 'defuse'", "feature_idx": 1, "feature_name": "Year(older_more_difficult)", "instances": 116, "metric": 0, "return_statement": 1, "tree_id": 0},
|
||||
{"current_level": 3, "leaf_id": "2f52d6df-e767-11ec-ac3e-4ccc6afd6a08", "parents": "2edd09e1-e767-11ec-b87c-4ccc6afd6a08", "rule": "if obj[3]>7:", "feature_idx": 3, "feature_name": "Meters_under_the_ground", "instances": 135, "metric": 0.7364977795505669, "return_statement": 0, "tree_id": 0},
|
||||
{"current_level": 4, "leaf_id": "2f52d6e0-e767-11ec-b6e4-4ccc6afd6a08", "parents": "2f52d6df-e767-11ec-ac3e-4ccc6afd6a08", "rule": "return 'detonate'", "feature_idx": 3, "feature_name": "Meters_under_the_ground", "instances": 135, "metric": 0, "return_statement": 1, "tree_id": 0},
|
||||
{"current_level": 2, "leaf_id": "2f6567d1-e767-11ec-ae72-4ccc6afd6a08", "parents": "2ececefd-e767-11ec-804a-4ccc6afd6a08", "rule": "if obj[2]>0:", "feature_idx": 2, "feature_name": "Protection_from_defuse", "instances": 161, "metric": 0.9203523274205176, "return_statement": 0, "tree_id": 0},
|
||||
{"current_level": 3, "leaf_id": "2f6567d2-e767-11ec-b1b8-4ccc6afd6a08", "parents": "2f6567d1-e767-11ec-ae72-4ccc6afd6a08", "rule": "return 'detonate'", "feature_idx": 2, "feature_name": "Protection_from_defuse", "instances": 161, "metric": 0, "return_statement": 1, "tree_id": 0},
|
||||
{"current_level": 1, "leaf_id": "2f793070-e767-11ec-9adb-4ccc6afd6a08", "parents": "root", "rule": "if obj[4]>80.67436609605278:", "feature_idx": 4, "feature_name": "Random_detonation_chance", "instances": 200, "metric": 0.9964625048848765, "return_statement": 0, "tree_id": 0},
|
||||
{"current_level": 2, "leaf_id": "2f793071-e767-11ec-9798-4ccc6afd6a08", "parents": "2f793070-e767-11ec-9adb-4ccc6afd6a08", "rule": "return 'detonate'", "feature_idx": 4, "feature_name": "Random_detonation_chance", "instances": 200, "metric": 0, "return_statement": 1, "tree_id": 0}
|
||||
]
|
Loading…
Reference in New Issue
Block a user