Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
scos
scos.projects
2PSnake
Commits
97cfe5bb
Commit
97cfe5bb
authored
Oct 14, 2020
by
Julian Rudolf
Browse files
debugging
parent
ab1bf200
Changes
4
Hide whitespace changes
Inline
Side-by-side
Game/main.py
View file @
97cfe5bb
...
...
@@ -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
:
...
...
Game/maps.py
View file @
97cfe5bb
...
...
@@ -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
],
...
...
Shield/graph_from_map.py
View file @
97cfe5bb
...
...
@@ -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 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1 1 -
72
1 1 1 1 1 1 1 1 -
73
1 1 1 1 -7
4
1]
# [ 1 -
70
1 1 1 1 -7
1
1 1 1 1 1 1 1 -
72
1 1 1 1 1 1 1 1 -
73
1 1 1 1 -7
4
1]
# [-7
5
4
5
-7
6
-7
6
-7
6
-7
6
4
6
-7
7
-7
7
-7
7
-7
7
-7
7
-7
7
-7
7
4
7
-7
8
-7
8
4
8
-7
9
-7
9
-7
9
-7
9
-7
9
4
9
-
80 -80 -80 -80 50
-7
5
]
# [ 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 -1 1 1 1 1 1 1 1 1 1 1 1 1]
# [ 1 1 1 1 1 1 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]
...
...
Shield/shield.py
View file @
97cfe5bb
...
...
@@ -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
(
"
\n
module 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
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment