Commit 97cfe5bb authored by Julian Rudolf's avatar Julian Rudolf
Browse files

debugging

parent ab1bf200
......@@ -410,7 +410,7 @@ class Snake:
es = self.enemy_snake.copy()
self.process = mp.Process(target=get_shield, args=(self.crash_prob_queue, ps, es))
self.process.start()
# print("normal_print ps: nodes " + str(self.shield_snake.nodes) + " edges " + str(self.shield_snake.edges) + ' dist ' + str(self.shield_snake.dist) +'\n' + 'es: nodes ' + str(self.enemy_snake.nodes) + " edges " + str(self.enemy_snake.edges) + 'dist ' + str(self.enemy_snake.dist) + '\n' + 'process ' + str(self.process.pid) + " started snake: " + str(self.id))
print("normal_print ps: nodes " + str(self.shield_snake.nodes) + " edges " + str(self.shield_snake.edges) + ' dist ' + str(self.shield_snake.dist) +'\n' + 'es: nodes ' + str(self.enemy_snake.nodes) + " edges " + str(self.enemy_snake.edges) + 'dist ' + str(self.enemy_snake.dist) + '\n' + 'process ' + str(self.process.pid) + " started snake: " + str(self.id))
self.wrap_around()
......@@ -426,27 +426,26 @@ class Snake:
crash = True
# print(str(self.id) + ' '+str([[int(i[1]/30), int(i[0]/30)] for i in reversed(self.list)]))
if self.shield and self.process is not None and self.process.exitcode is not None and False:
if self.shield and self.process is not None and self.process.exitcode is not None:
self.crash_prob = self.crash_prob_queue.get()
print('pid: ' + str(self.process.pid))
# print("done early id " + str(self.id) + ' ' + str(self.crash_prob) + ' ' + 'pid: ' + str(self.process.pid))
print("done early id " + str(self.id) + ' ' + str(self.crash_prob) + ' ' + 'pid: ' + str(self.process.pid) + ' counter = ' + str(self.count))
self.process.close()
self.process = None
self.color_prob(self.crash_prob)
# nur wenn nicht alle 0.0
# wenn eigene schlange bei crossing -> process töten(?)
# nur wenn nicht alle 0.0
# wenn eigene schlange bei crossing -> process töten(?)
choice = True
try:
choice = all_good_choice(self.crash_prob)
except AttributeError:
choice = True
if not choice:
if not choice and False:
if check_if_after_crossing(self.enemy_norm_snake.pos[1] / block_size,
self.enemy_norm_snake.pos[0] / block_size, self.enemy_norm_snake.direction):
if self.shield and self.process is None:
print("Starting recalc")
print('Starting recalc at counter = ' + str(self.count))
ps = self.shield_snake.copy()
es = self.enemy_snake.copy()
self.process = mp.Process(target=get_shield, args=(self.crash_prob_queue, ps, es))
......@@ -455,6 +454,8 @@ class Snake:
self.shield_snake.dist) + '\n' + 'es: nodes ' + str(self.enemy_snake.nodes) + " edges " + str(
self.enemy_snake.edges) + 'dist ' + str(self.enemy_snake.dist) + '\n' + 'process ' + str(
self.process.pid) + " started snake: " + str(self.id))
print("pos ps: " + str([[posy // block_size, posx // block_size] for posx, posy in reversed(self.poslist)]))
print("pos es: " + str([[posy // block_size, posx // block_size] for posx, posy in reversed(self.enemy_norm_snake.poslist)]))
self.draw_snake()
self.count += 1
......@@ -1098,7 +1099,7 @@ def game_loop():
snake1.key_event("down")
if event.key == pygame.K_UP:
snake1.key_event("up")
if event.key == pygame.K_1:
if event.key == pygame.K_1 and snake1.process is None:
if snake1.shield:
snake1.shield = False
elif not snake1.shield:
......@@ -1112,7 +1113,7 @@ def game_loop():
snake2.key_event("down")
if event.key == pygame.K_w:
snake2.key_event("up")
if event.key == pygame.K_2:
if event.key == pygame.K_2 and snake2.process is None:
if snake2.shield:
snake2.shield = False
elif not snake2.shield:
......
......@@ -104,6 +104,16 @@ start3 = [{"pos": [[5,6],[5,5],[5,4],[5,3],[5,2],[5,1],[4,1],[3,1],[2,1],[2,2],[
"vel": [[0,-1],[0,-1],[0,-1],[0,-1],[-1,0],[-1,0],[-1,0],[-1,0],[-1,0],[-1,0],[-1,0],[-1,0],[-1,0],[-1,0],[-1,0],[-1,0],[-1,0],[-1,0],[-1,0],[-1,0]],
"angle": 'up'}]
# [y, x] [14, 3]
#
# start3 = [{"pos": [[14,3],[14,2],[14,1],[13,1],[12,1],[11,1],[10,1],[9,1],[9,2],[9,3],[9,4],[9,5],[9,6],[9,7],[9,8],[9,9],[9,10],[9,11],[9,12],[9,13]],
# "vel": [[1,0],[1,0],[1,0],[0,1],[0,1],[0,1],[0,1],[0,1],[-1,0],[-1,0],[-1,0],[-1,0],[-1,0],[-1,0],[-1,0],[-1,0],[-1,0],[-1,0],[-1,0],[-1,0]],
# "angle": 'right'},
#
# {"pos": [[24,1],[25,1],[26,1],[27,1],[27,2],[27,3],[27,4],[27,5],[27,6],[27,7],[27,8],[27,9],[27,10],[27,11],[27,12],[27,13],[27,14],[27,15],[27,16],[27,17]],
# "vel": [[0,-1],[0,-1],[0,-1],[0,-1],[-1,0],[-1,0],[-1,0],[-1,0],[-1,0],[-1,0],[-1,0],[-1,0],[-1,0],[-1,0],[-1,0],[-1,0],[-1,0],[-1,0],[-1,0],[-1,0]],
# "angle": 'up'}]
map3 = [[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,1,1,1,1,1,1,1,1,1,1,1,1],
[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,1,1,1,1,1,1,1,1,1,1,1,1],
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
......
......@@ -36,36 +36,36 @@ map = np.array(maps.map3)
# [0,1,0,1,0],
# [0,0,0,0,0]]
# map3
# [[ 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 -1 1 1 1 1 1 1 1 1 1 1 1 1]
# [ 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 -1 1 1 1 1 1 1 1 1 1 1 1 1]
# [ -2 2 -3 -3 -3 -3 -3 -3 -3 3 -4 -4 -4 -4 -4 -4 -4 4 -5 -5 5 -6 -6 -6 -6 -6 -6 -6 6 -2]
# [ 1 -8 1 1 1 1 1 1 1 -9 1 1 1 1 1 1 1 1 1 1 -10 1 1 1 1 1 1 1 -11 1]
# [ 1 -8 1 1 1 1 1 1 1 -9 1 1 1 1 1 1 1 1 1 1 -10 1 1 1 1 1 1 1 -11 1]
# [ 1 -8 -8 -8 -8 -8 7 -12 -12 8 -13 -13 9 -14 -14 -14 -14 -14 10 -15 11 -16 -16 12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1 1 1 -28 1]
# [ 1 -22 -22 19 -31 -31 20 -32 -32 21 -33 -33 22 -34 -34 -34 -34 -34 23 -35 24 -36 -36 25 -37 -37 26 -28 -28 1]
# [ 1 1 1 -39 1 1 -40 1 1 1 1 1 -41 1 1 1 1 1 -42 1 1 1 1 -43 1 1 -44 1 1 1]
# [ 1 1 -39 -39 1 1 -40 1 1 1 1 1 -41 1 1 1 1 1 -42 1 1 1 1 -43 1 1 -44 -44 1 1]
# [ 1 -39 -39 1 1 1 -40 1 1 1 1 1 -41 1 1 1 1 1 -42 1 1 1 1 -43 1 1 1 -44 -44 1]
# [ 1 -39 1 1 1 1 -40 1 1 1 1 1 -41 1 1 1 1 1 -42 1 1 1 1 -43 1 1 1 1 -44 1]
# [ 1 27 -47 -47 -47 -47 28 -48 -48 29 -49 -49 30 -50 31 -51 -51 -51 32 -52 33 -53 -53 34 -54 -54 -54 -54 35 1]
# [ 1 -55 1 1 1 1 1 1 1 -56 1 1 1 1 -57 1 1 1 1 1 -58 1 1 1 1 1 1 1 -59 1]
# [ 1 -55 1 1 1 1 1 1 1 -56 1 1 1 1 -57 1 1 1 1 1 -58 1 1 1 1 1 1 1 -59 1]
# [ 1 -55 1 1 1 1 1 1 1 -56 1 1 1 1 -57 1 1 1 1 1 -58 1 1 1 1 1 1 1 -59 1]
# [ 1 -55 1 1 1 1 1 1 1 -56 1 1 1 1 -57 1 1 1 1 1 -58 1 1 1 1 1 1 1 -59 1]
# [ 1 36 -60 -60 -60 -60 37 -61 -61 38 -62 -62 -62 -62 39 -63 -63 -63 -63 -63 40 -64 -64 41 -65 -65 -65 -65 42 1]
# [ 1 -66 1 1 1 1 -67 1 1 1 1 1 1 1 -68 1 1 1 1 1 1 1 1 -69 1 1 1 1 -70 1]
# [ 1 -66 1 1 1 1 -67 1 1 1 1 1 1 1 -68 1 1 1 1 1 1 1 1 -69 1 1 1 1 -70 1]
# [-71 43 -72 -72 -72 -72 44 -73 -73 -73 -73 -73 -73 -73 45 -74 -74 46 -75 -75 -75 -75 -75 47 -76 -76 -76 -76 48 -71]
# [ 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 -1 1 1 1 1 1 1 1 1 1 1 1 1]
# [ 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 -1 1 1 1 1 1 1 1 1 1 1 1 1]]
# [-22 13 -23 -23 -23 -23 14 -24 -24 15 -25 -25 16 -26 -26 -26 -26 -26 17 -27 18 -28 -28 19 -29 -29 -29 -29 20 -22]
# [ 1 -31 1 1 1 1 1 1 1 -32 1 1 1 1 1 1 1 1 1 1 -33 1 1 1 1 1 1 1 -34 1]
# [ 1 -31 1 1 1 1 1 1 1 -32 1 1 1 1 1 1 1 1 1 1 -33 1 1 1 1 1 1 1 -34 1]
# [ 1 -31 1 1 1 1 1 1 1 -32 1 1 1 1 1 1 1 1 1 1 -33 1 1 1 1 1 1 1 -34 1]
# [ 1 -31 1 1 1 1 1 1 1 -32 1 1 1 1 1 1 1 1 1 1 -33 1 1 1 1 1 1 1 -34 1]
# [ 1 -31 -31 21 -35 -35 22 -36 -36 23 -37 -37 24 -38 -38 -38 -38 -38 25 -39 26 -40 -40 27 -41 -41 28 -34 -34 1]
# [ 1 1 1 -43 1 1 -44 1 1 1 1 1 -45 1 1 1 1 1 -46 1 1 1 1 -47 1 1 -48 1 1 1]
# [ 1 1 -43 -43 1 1 -44 1 1 1 1 1 -45 1 1 1 1 1 -46 1 1 1 1 -47 1 1 -48 -48 1 1]
# [ 1 -43 -43 1 1 1 -44 1 1 1 1 1 -45 1 1 1 1 1 -46 1 1 1 1 -47 1 1 1 -48 -48 1]
# [ 1 -43 1 1 1 1 -44 1 1 1 1 1 -45 1 1 1 1 1 -46 1 1 1 1 -47 1 1 1 1 -48 1]
# [ 1 29 -51 -51 -51 -51 30 -52 -52 31 -53 -53 32 -54 33 -55 -55 -55 34 -56 35 -57 -57 36 -58 -58 -58 -58 37 1]
# [ 1 -59 1 1 1 1 1 1 1 -60 1 1 1 1 -61 1 1 1 1 1 -62 1 1 1 1 1 1 1 -63 1]
# [ 1 -59 1 1 1 1 1 1 1 -60 1 1 1 1 -61 1 1 1 1 1 -62 1 1 1 1 1 1 1 -63 1]
# [ 1 -59 1 1 1 1 1 1 1 -60 1 1 1 1 -61 1 1 1 1 1 -62 1 1 1 1 1 1 1 -63 1]
# [ 1 -59 1 1 1 1 1 1 1 -60 1 1 1 1 -61 1 1 1 1 1 -62 1 1 1 1 1 1 1 -63 1]
# [ 1 38 -64 -64 -64 -64 39 -65 -65 40 -66 -66 -66 -66 41 -67 -67 -67 -67 -67 42 -68 -68 43 -69 -69 -69 -69 44 1]
# [ 1 -70 1 1 1 1 -71 1 1 1 1 1 1 1 -72 1 1 1 1 1 1 1 1 -73 1 1 1 1 -74 1]
# [ 1 -70 1 1 1 1 -71 1 1 1 1 1 1 1 -72 1 1 1 1 1 1 1 1 -73 1 1 1 1 -74 1]
# [-75 45 -76 -76 -76 -76 46 -77 -77 -77 -77 -77 -77 -77 47 -78 -78 48 -79 -79 -79 -79 -79 49 -80 -80 -80 -80 50 -75]
# [ 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 -1 1 1 1 1 1 1 1 1 1 1 1 1]
# [ 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 -1 1 1 1 1 1 1 1 1 1 1 1 1]]
# map5
# [[ 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1]
# [ 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1]
......
......@@ -335,7 +335,9 @@ class ShieldSnake:
return edge_nodes[1] if self.dir else edge_nodes[0]
# return:
# True if the remaining distance of the edge is equal or smaller than shied_calc_dist_min
# if dist of edge is larger then shield_calc_dist_min then return True if
# remaining dist on edge is equal to shield_calc_dist min
# if dist of edge is smaller than shield_calc_dist_min than return true if snake is at first pos of the edge
def shield_calc_dist(self):
_, dist = edges[self.edges[0]]
if dist > shield_calc_dist_min:
......@@ -549,8 +551,8 @@ def step_fast_forward(snake, dir, allow_wrong=False):
# (multiprocess communication)
def check_files_prism_process_funct(file, dir, return_dict):
program = stormpy.parse_prism_program('/dev/shm/' + file)
print(file)
prop = "Pmin=? [ F \"crash\" ]"
properties = stormpy.parse_properties_for_prism_program(prop, program, None)
model = stormpy.build_model(program, properties)
initial_state = model.initial_states[0]
......@@ -558,6 +560,7 @@ def check_files_prism_process_funct(file, dir, return_dict):
return_dict[dir] = result.at(initial_state)
# checks the prism files for the Pmin probability of a crash
# uses multiprocessing, one for each direction
# parameters:
......@@ -618,6 +621,7 @@ def get_shield(crash_prob_queue, snake_player, snake_enemy, p_move=0):
# and reset prism string and parameters
s = snake_player.copy()
_, dist = edges[s.edges[0]]
print("num of steps: " + str(dist - s.dist + 1))
for i in range(dist - s.dist + 1):
s.step()
......@@ -627,6 +631,7 @@ def get_shield(crash_prob_queue, snake_player, snake_enemy, p_move=0):
# write the prism start string and the enemy snake module to the prism file
file = open('/dev/shm/' + master_filename, 'a')
# print("filename: " + master_filename)
file.write(get_prism_start_string(p_move=p_move, presteps=dist))
file.write("\nmodule enemysnake\n")
snake_enemy.append_file(file)
......@@ -646,7 +651,7 @@ def get_shield(crash_prob_queue, snake_player, snake_enemy, p_move=0):
# clean up
#remove_files(files, master_filename=master_filename)
remove_files(files, master_filename=master_filename)
del s
del snake_enemy
del snake_player
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment