final commit
This commit is contained in:
@@ -211,16 +211,15 @@ keymaker = (5,6)
|
|||||||
initialize_map_dict()
|
initialize_map_dict()
|
||||||
calculate_all_h_for_target(keymaker)
|
calculate_all_h_for_target(keymaker)
|
||||||
|
|
||||||
'''make_blocked((1,1))
|
make_blocked((0,1))
|
||||||
make_blocked((1,2))
|
make_blocked((1,0))
|
||||||
make_blocked((1,3))
|
|
||||||
make_blocked((1,4))
|
#make_blocked((4,6))
|
||||||
make_blocked((4,6))
|
|
||||||
make_blocked((5,5))
|
#make_blocked((6,6))
|
||||||
make_blocked((6,6))
|
|
||||||
make_blocked((4,7))
|
#make_blocked((4,8))
|
||||||
make_blocked((4,8))'''
|
print_map()
|
||||||
#print_map()
|
|
||||||
|
|
||||||
#print_cells_parameters(get_walkable_cells_list(neo))
|
#print_cells_parameters(get_walkable_cells_list(neo))
|
||||||
#time.sleep(0.1)
|
#time.sleep(0.1)
|
||||||
@@ -262,7 +261,7 @@ while (finish == False):
|
|||||||
assign_previous(next_cell, calculate_cell_with_minimal_g(get_walkable_cells_list(next_cell), "-"))
|
assign_previous(next_cell, calculate_cell_with_minimal_g(get_walkable_cells_list(next_cell), "-"))
|
||||||
previous = get_previous(next_cell)
|
previous = get_previous(next_cell)
|
||||||
#print_cells_parameters(get_walkable_cells_list(neo))
|
#print_cells_parameters(get_walkable_cells_list(neo))
|
||||||
#print_map()
|
print_map()
|
||||||
neo = next_cell
|
neo = next_cell
|
||||||
steps_count += 1
|
steps_count += 1
|
||||||
print(f"m {neo[0]} {neo[1]}")
|
print(f"m {neo[0]} {neo[1]}")
|
||||||
|
|||||||
+11
-3
@@ -28,7 +28,7 @@ with open("20k_testset.txt", "r") as file:
|
|||||||
|
|
||||||
|
|
||||||
line_number = 0
|
line_number = 0
|
||||||
while(test_number < 1000):
|
while(test_number < 100):
|
||||||
#time.sleep(.5)
|
#time.sleep(.5)
|
||||||
start_time = time.time()
|
start_time = time.time()
|
||||||
current_test_lines = []
|
current_test_lines = []
|
||||||
@@ -149,14 +149,22 @@ while(test_number < 1000):
|
|||||||
|
|
||||||
average_time = total_time / passed_tests
|
average_time = total_time / passed_tests
|
||||||
|
|
||||||
print("-------RESULTS-------")
|
print("-------A_STAR_RESULTS-------")
|
||||||
print(f"passed tests: {passed_tests}")
|
print(f"passed tests: {passed_tests}")
|
||||||
print(f"failed tests: {failed_tests}")
|
print(f"failed tests: {failed_tests}")
|
||||||
print(f"total time: {total_time}")
|
print(f"total time: {total_time}")
|
||||||
print(f"average time: {average_time}")
|
print(f"average time: {average_time}")
|
||||||
'''
|
'''
|
||||||
|
FOR 100 tests
|
||||||
|
-------A_STAR_RESULTS-------
|
||||||
|
passed tests: 99
|
||||||
|
failed tests: 1
|
||||||
|
total time: 18.093406677246094
|
||||||
|
average time: 0.1827616836085464
|
||||||
|
|
||||||
|
|
||||||
FOR 1000 tests
|
FOR 1000 tests
|
||||||
-------RESULTS-------
|
-------A_STAR_RESULTS-------
|
||||||
passed tests: 995
|
passed tests: 995
|
||||||
failed tests: 5
|
failed tests: 5
|
||||||
total time: 184.33025455474854
|
total time: 184.33025455474854
|
||||||
|
|||||||
+25
-25
@@ -2,30 +2,7 @@
|
|||||||
grid_map = []
|
grid_map = []
|
||||||
min_distances = []
|
min_distances = []
|
||||||
|
|
||||||
def main():
|
|
||||||
global grid_map, min_distances
|
|
||||||
# Create a 9x9 grid map filled with '.'
|
|
||||||
grid_map = [['.' for temp in range(9)] for temp in range(9)]
|
|
||||||
# Create a minimum distance grid with initial values set to "infinity" (10000)
|
|
||||||
min_distances = [[10000 for temp in range(9)] for temp in range(9)]
|
|
||||||
|
|
||||||
# Read perception variant
|
|
||||||
variant = int(input())
|
|
||||||
# Read Keymaker's position
|
|
||||||
position_input = input().split()
|
|
||||||
keymaker_x = int(position_input[0])
|
|
||||||
keymaker_y = int(position_input[1])
|
|
||||||
|
|
||||||
# Set the starting position (0, 0) with a minimum distance of 0
|
|
||||||
min_distances[0][0] = 0
|
|
||||||
# Start the recursive pathfinding search from the starting position
|
|
||||||
find_path(0, 0)
|
|
||||||
|
|
||||||
# Output the result based on the minimum distance to the Keymaker's position
|
|
||||||
if min_distances[keymaker_y][keymaker_x] == 10000:
|
|
||||||
print("e -1") # If no path is found, output -1
|
|
||||||
else:
|
|
||||||
print("e " + str(min_distances[keymaker_y][keymaker_x])) # Output the shortest path length
|
|
||||||
|
|
||||||
def observe(x, y):
|
def observe(x, y):
|
||||||
# Sends a move command and receives information on perceived cells around position (x, y)
|
# Sends a move command and receives information on perceived cells around position (x, y)
|
||||||
@@ -73,5 +50,28 @@ def find_path(x, y):
|
|||||||
|
|
||||||
observe(x, y) # Final exploration after checking all directions.
|
observe(x, y) # Final exploration after checking all directions.
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
main()
|
# Create a 9x9 grid map filled with '.'
|
||||||
|
grid_map = [['.' for temp in range(9)] for temp in range(9)]
|
||||||
|
# Create a minimum distance grid with initial values set to "infinity" (10000)
|
||||||
|
min_distances = [[10000 for temp in range(9)] for temp in range(9)]
|
||||||
|
|
||||||
|
# Read perception variant
|
||||||
|
variant = int(input())
|
||||||
|
# Read Keymaker's position
|
||||||
|
position_input = input().split()
|
||||||
|
keymaker_x = int(position_input[0])
|
||||||
|
keymaker_y = int(position_input[1])
|
||||||
|
|
||||||
|
# Set the starting position (0, 0) with a minimum distance of 0
|
||||||
|
min_distances[0][0] = 0
|
||||||
|
# Start the recursive pathfinding search from the starting position
|
||||||
|
find_path(0, 0)
|
||||||
|
|
||||||
|
# Output the result based on the minimum distance to the Keymaker's position
|
||||||
|
if min_distances[keymaker_y][keymaker_x] == 10000:
|
||||||
|
print("e -1") # If no path is found, output -1
|
||||||
|
else:
|
||||||
|
print("e " + str(min_distances[keymaker_y][keymaker_x])) # Output the shortest path length
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -42,37 +42,14 @@ while(test_number < 1000):
|
|||||||
grid_map = []
|
grid_map = []
|
||||||
min_distances = []
|
min_distances = []
|
||||||
|
|
||||||
def main():
|
|
||||||
global grid_map, min_distances
|
|
||||||
# Create a 9x9 grid map filled with '.'
|
|
||||||
grid_map = [['.' for temp in range(9)] for temp in range(9)]
|
|
||||||
# Create a minimum distance grid with initial values set to "infinity" (10000)
|
|
||||||
min_distances = [[10000 for temp in range(9)] for temp in range(9)]
|
|
||||||
|
|
||||||
# Read perception variant
|
|
||||||
perception_radius = int(current_test_lines[1][0])
|
|
||||||
# Read Keymaker's position
|
|
||||||
keymaker_x = int(current_test_lines[2][1])
|
|
||||||
keymaker_y = int(current_test_lines[2][4])
|
|
||||||
|
|
||||||
# Set the starting position (0, 0) with a minimum distance of 0
|
|
||||||
min_distances[0][0] = 0
|
|
||||||
# Start the recursive pathfinding search from the starting position
|
|
||||||
find_path(0, 0)
|
|
||||||
|
|
||||||
# Output the result based on the minimum distance to the Keymaker's position
|
|
||||||
if min_distances[keymaker_y][keymaker_x] == 10000:
|
|
||||||
print("e -1") # If no path is found, output -1
|
|
||||||
else:
|
|
||||||
print("e " + str(min_distances[keymaker_y][keymaker_x])) # Output the shortest path length
|
|
||||||
|
|
||||||
def observe(x, y):
|
def observe(x, y):
|
||||||
# Sends a move command and receives information on perceived cells around position (x, y)
|
# Sends a move command and receives information on perceived cells around position (x, y)
|
||||||
print(f"m {x} {y}")
|
#print(f"m {x} {y}")
|
||||||
for x_temp in range(len(test_map_matrix)):
|
for x_temp in range(len(test_map_matrix)):
|
||||||
for y_temp in range(len(test_map_matrix)):
|
for y_temp in range(len(test_map_matrix)):
|
||||||
if (x,y) in get_percepted_cells((x, y)) and test_map_matrix[x_temp][y_temp] != ".":
|
if (x_temp,y_temp) in get_percepted_cells((x, y)) and test_map_matrix[x_temp][y_temp] != ".":
|
||||||
grid_map[x][y] = test_map_matrix[x][y]
|
grid_map[x_temp][y_temp] = test_map_matrix[x_temp][y_temp]
|
||||||
|
|
||||||
def find_path(x, y):
|
def find_path(x, y):
|
||||||
# Explore surroundings from the current position (x, y)
|
# Explore surroundings from the current position (x, y)
|
||||||
@@ -106,6 +83,56 @@ while(test_number < 1000):
|
|||||||
|
|
||||||
observe(x, y) # Final exploration after checking all directions.
|
observe(x, y) # Final exploration after checking all directions.
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
main()
|
|
||||||
|
# Create a 9x9 grid map filled with '.'
|
||||||
|
grid_map = [['.' for temp in range(9)] for temp in range(9)]
|
||||||
|
# Create a minimum distance grid with initial values set to "infinity" (10000)
|
||||||
|
min_distances = [[10000 for temp in range(9)] for temp in range(9)]
|
||||||
|
|
||||||
|
# Read perception variant
|
||||||
|
perception_radius = int(current_test_lines[1][0])
|
||||||
|
# Read Keymaker's position
|
||||||
|
keymaker_x = int(current_test_lines[2][1])
|
||||||
|
keymaker_y = int(current_test_lines[2][4])
|
||||||
test_map_matrix = current_test_lines[3:12]
|
test_map_matrix = current_test_lines[3:12]
|
||||||
|
# Set the starting position (0, 0) with a minimum distance of 0
|
||||||
|
min_distances[0][0] = 0
|
||||||
|
# Start the recursive pathfinding search from the starting position
|
||||||
|
find_path(0, 0)
|
||||||
|
|
||||||
|
# Output the result based on the minimum distance to the Keymaker's position
|
||||||
|
if min_distances[keymaker_y][keymaker_x] == 10000:
|
||||||
|
print("e -1") # If no path is found, output -1
|
||||||
|
time.sleep(1)
|
||||||
|
failed_tests += 1
|
||||||
|
test_number += 1
|
||||||
|
end_time = time.time()
|
||||||
|
test_time = end_time - start_time
|
||||||
|
total_time += 0 # we don't consider failed tests in statistics
|
||||||
|
|
||||||
|
else:
|
||||||
|
print("e " + str(min_distances[keymaker_y][keymaker_x])) # Output the shortest path length
|
||||||
|
time.sleep(1)
|
||||||
|
passed_tests += 1
|
||||||
|
test_number += 1
|
||||||
|
end_time = time.time()
|
||||||
|
test_time = end_time - start_time
|
||||||
|
total_time += test_time
|
||||||
|
|
||||||
|
average_time = total_time / passed_tests
|
||||||
|
|
||||||
|
print("-------BACKTRACKING_RESULTS-------")
|
||||||
|
print(f"passed tests: {passed_tests}")
|
||||||
|
print(f"failed tests: {failed_tests}")
|
||||||
|
print(f"total time: {total_time}")
|
||||||
|
print(f"average time: {average_time}")
|
||||||
|
|
||||||
|
'''
|
||||||
|
FOR 100 tests
|
||||||
|
-------BACKTRACKING_RESULTS-------
|
||||||
|
passed tests: 99
|
||||||
|
failed tests: 1
|
||||||
|
total time: 156.93781638145447
|
||||||
|
average time: 1.58523046849954
|
||||||
|
'''
|
||||||
Reference in New Issue
Block a user