Commit c5f9cfe6 authored by Julian Rudolf's avatar Julian Rudolf
Browse files

debugging

parent 97cfe5bb
......@@ -138,7 +138,7 @@ class Snake:
# direction : direction of the snake at the crossing
# shield_snake : the player snake in shield logic
# enemy_snake : the enemy snake in shield logic
def __init__(self, pos, vel, angle, id, img=green_head, color=green, apple_img=green_apple, act_shield=False, length=snake_length):
def __init__(self, pos, vel, angle, id, img=green_head, color=green, apple_img=green_apple, act_shield=False, length=snake_length, dir=True):
self.pos = [pos[0][1] * block_size, pos[0][0] * block_size]
self.vel = [vel[0][0] * block_size, vel[0][1] * block_size]
self.poslist = []
......@@ -157,7 +157,7 @@ class Snake:
self.direction = angle
self.score = 0
self.apple_img = apple_img
self.shield_snake = ShieldSnake(pos, start_dir=True)
self.shield_snake = ShieldSnake(pos, start_dir=dir)
self.enemy_snake = None
self.crash_prob_draw = []
self.id = id
......@@ -394,10 +394,11 @@ class Snake:
if int(up) + int(down) + int(right) + int(left) > 2:
if self.shield and self.count != 0:
if self.process is not None:
pid = self.process.pid
self.process.join()
self.process = None
self.crash_prob = self.crash_prob_queue.get()
print("done late " + str(self.id) + ' ' + str(self.crash_prob))
print("done late " + str(self.id) + ' ' + str(self.crash_prob) + " pid: " + str(pid) + " counter = " + str(self.count))
self.color_prob(self.crash_prob)
self.shield_turn(self.crash_prob)
# step the shield_snake one step forward
......@@ -405,12 +406,39 @@ class Snake:
else:
# step the shield_snake one step forward
self.shield_snake.step()
# 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 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 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, self.count, True))
self.process.start()
# 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("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)]))
if self.shield and self.process is None and self.shield_snake.shield_calc_dist():
ps = self.shield_snake.copy()
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()
......@@ -433,30 +461,6 @@ class Snake:
self.process = None
self.color_prob(self.crash_prob)
# 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 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 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))
self.process.start()
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("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
return crash
......@@ -862,6 +866,7 @@ def select_map():
p1_map_filename = '../Shield/maps/map3.pickle'
p1_start = maps.start3
p1_length = snake_length
debug = False
while map_select:
for event in pygame.event.get():
......@@ -875,6 +880,8 @@ def select_map():
map_filename = '../Shield/maps/map8.pickle'
startsnake1, startsnake2 = maps.start8
snake_length = 20
message_screen("Debug Map enabled!", red, -100, "large")
debug = True
elif event.key == pygame.K_LEFT and not p1_pos == pos1:
pygame.draw.rect(Display, white, p1, 5)
p1_pos = (p1_pos[0] - 300, p1_pos[1])
......@@ -906,10 +913,11 @@ def select_map():
p1_start = maps.start6
p1_length = 20
map = p1_map
map_filename = p1_map_filename
startsnake1, startsnake2 = p1_start
snake_length = p1_length
if not debug:
map = p1_map
map_filename = p1_map_filename
startsnake1, startsnake2 = p1_start
snake_length = p1_length
button("Fast", (int(res_x / 2 - 200), res_y - 300, 100, 30), red, light_red, action="speed65")
button("Medium", (int(res_x / 2 - 320), res_y - 300, 100, 30), yellow, light_yellow, action="speed45")
......@@ -1024,7 +1032,7 @@ def game_loop():
snake1 = Snake(startsnake1["pos"], startsnake1["vel"], startsnake1["angle"], 0, img=p1_snake[0], color=p1_snake[1],
apple_img=green_apple, act_shield=True, length=snake_length)
snake2 = Snake(startsnake2["pos"], startsnake2["vel"], startsnake2["angle"], 1, img=p2_snake[0], color=p2_snake[1],
apple_img=purple_apple, act_shield=True, length=snake_length)
apple_img=purple_apple, act_shield=False, length=snake_length, dir=False)
snake1.set_enemy_snake(snake2.shield_snake)
snake2.set_enemy_snake(snake1.shield_snake)
snake1.set_enemy_norm_snake(snake2)
......
......@@ -96,24 +96,24 @@ map1 = [[1,1,1,1,1,1,1,1,1,1,1,1,1,0,1,1,1,1,1,1,1,1,1,1,0,1,1,1,1,1],
# "vel": [[0,-1],[0,-1],[0,-1],[0,-1],[-1,0],[-1,0],[-1,0],[-1,0],[-1,0],[-1,0]],
# "angle": 'up'}]
start3 = [{"pos": [[5,6],[5,5],[5,4],[5,3],[5,2],[5,1],[4,1],[3,1],[2,1],[2,2],[2,3],[2,4],[2,5],[2,6],[2,7],[2,8],[2,9],[2,10],[2,11],[2,12]],
"vel": [[1,0],[1,0],[1,0],[1,0],[1,0],[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]],
"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'}]
# [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]],
# start3 = [{"pos": [[5,6],[5,5],[5,4],[5,3],[5,2],[5,1],[4,1],[3,1],[2,1],[2,2],[2,3],[2,4],[2,5],[2,6],[2,7],[2,8],[2,9],[2,10],[2,11],[2,12]],
# "vel": [[1,0],[1,0],[1,0],[1,0],[1,0],[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]],
# "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'}]
# [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": [[19,6],[19,5],[19,4],[19,3],[19,2],[19,1],[20,1],[21,1],[22,1],[23,1],[24,1],[25,1],[26,1],[27,1],[27,2],[27,3],[27,4],[27,5],[27,6],[27,7]],
"vel": [[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[0,-1],[0,-1],[0,-1],[0,-1],[0,-1],[0,-1],[0,-1],[0,-1],[-1,0],[-1,0],[-1,0],[-1,0],[-1,0],[-1,0]],
"angle": 'right'}]
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],
......@@ -303,41 +303,72 @@ map7 = [[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],
[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]]
start8 = [{"pos": [[4,13],[3,13],[2,13],[1,13]],
"vel": [[0,1],[0,1],[0,1],[0,1]],
start8 = [{"pos": [[4,13],[3,13],[2,13],[1,13],[1,12],[1,11],[1,10],[1,9],[1,8],[1,7],[1,6],[1,5],[1,4],[1,3],[1,2],[1,1],[2,1],[3,1],[4,1],[5,1]],
"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],[0,-1],[0,-1],[0,-1],[0,-1]],
"angle": 'down'},
{"pos": [[26,13],[27,13],[28,13],[29,13]],
"vel": [[0,-1],[0,-1],[0,-1],[0,-1]],
{"pos": [[26,13],[27,13],[28,13],[28,12],[28,11],[28,10],[28,9],[28,8],[28,7],[28,6],[28,5],[28,4],[28,3],[28,2],[28,1],[27,1],[26,1],[25,1],[24,1],[23,1]],
"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],[0,-1],[0,-1],[0,-1],[0,-1],[0,-1]],
"angle": 'up'}]
map8 = [[1,1,1,1,1,1,1,1,1,1,1,0,1,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1],
[1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 1 1 -7 1 1 1 1 1 1 -6 1 1 1 1 1 1 1 1 1]
# [ 1 -4 1 1 1 1 1 1 1 1 1 1 1 5 -6 -6 -6 -6 -6 -6 -6 1 1 1 1 1 1 1 1 1]
# [ 1 -4 1 1 1 1 1 1 1 1 1 1 1 -9 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1]
# [ 1 -4 1 1 1 1 1 1 1 1 1 1 1 -9 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1]
# [ 1 -4 1 1 1 1 1 1 1 1 1 1 1 -9 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1]
# [ 1 -4 1 1 1 1 1 1 1 1 1 1 1 -9 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1]
# [ 1 -4 1 1 1 1 1 1 1 1 1 1 1 -9 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1]
# [ 1 6 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 7 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 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1]]
......@@ -66,6 +66,7 @@ map = np.array(maps.map3)
# [-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]
......
No preview for this file type
......@@ -141,6 +141,7 @@ class ShieldSnake:
# print('START')
# print('max nodes needed: ' + str(max) + '\t max edges needed: ' + str(max))
self.prism_state(start=True)
self.pos = start_pos
# sets the postfix
def set_postfix(self, postfix):
......@@ -509,6 +510,7 @@ def recursion_step_prob(snake, max_steps, start_steps, file=None):
if s.steps - start_steps == max_steps:
cont_flag = True
break
# print("enemy pos after step: nodes " + str(s.nodes) + " edges " + str(s.edges))
if cont_flag:
del s
continue
......@@ -551,7 +553,7 @@ 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)
#print(file)
prop = "Pmin=? [ F \"crash\" ]"
properties = stormpy.parse_properties_for_prism_program(prop, program, None)
model = stormpy.build_model(program, properties)
......@@ -608,7 +610,7 @@ def remove_files(files, master_filename='master.nm'):
# p_move : determines which player starts first (0 enemy, 1 player)
# return:
# crash_prob : probability of a crash for each possible direction
def get_shield(crash_prob_queue, snake_player, snake_enemy, p_move=0):
def get_shield(crash_prob_queue, snake_player, snake_enemy, count=0, recalc=False, p_move=0):
# master file name
master_filename = 'master_' + str(uuid.uuid4()) + '.nm'
......@@ -621,10 +623,13 @@ 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))
if recalc:
print("num of steps: " + str(dist - s.dist + 1) + " count: " + str(count))
for i in range(dist - s.dist + 1):
s.step()
# print("player pos after step: nodes " + str(s.nodes) + " edges " + str(s.edges))
s.prismsteps = 0
s.prism = ''
s.prism_state(start=True)
......@@ -646,10 +651,6 @@ def get_shield(crash_prob_queue, snake_player, snake_enemy, p_move=0):
# calculate the crash probabilities
crash_prob = check_files_prism(files)
#print("ps: " + str(snake_player.edges))
#print("es: " + str(snake_enemy.edges))
# clean up
remove_files(files, master_filename=master_filename)
del s
......@@ -661,11 +662,11 @@ def get_shield(crash_prob_queue, snake_player, snake_enemy, p_move=0):
return crash_prob
# example:
#
# init_shield('../Shield/maps/map3.pickle')
# t = time.time_ns()
# s_e = ShieldSnake([[9, 8], [9, 7], [9, 6], [9, 5], [9, 4], [9, 3], [9, 2], [9, 1], [10, 1], [11, 1], [12, 1], [13, 1], [14, 1], [14, 2], [14, 3]], start_dir=True, postfix='_e')
# s_p = ShieldSnake([[2, 26], [2, 27], [2, 28], [3, 28], [4, 28], [5, 28], [5, 27], [5, 26], [5, 25], [5, 24], [5, 23], [5, 22], [5, 21], [5, 20], [5, 19]], start_dir=False)
# s_e = ShieldSnake([[19, 15], [19, 14], [19, 13], [19, 12], [19, 11], [19, 10], [19, 9], [19, 8], [19, 7], [19, 6], [19, 5], [19, 4], [19, 3], [19, 2], [19, 1]], start_dir=False, postfix='_e')
# s_p = ShieldSnake([[14, 12], [14, 11], [14, 10], [14, 9], [14, 8], [14, 7], [14, 6], [14, 5], [14, 4], [14, 3], [14, 2], [14, 1], [13, 1], [12, 1], [11, 1]], start_dir=False)
# s = s_p.copy()
# _ , dist = edges[s.edges[0]]
#
......
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