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
03e08974
Commit
03e08974
authored
Nov 11, 2020
by
Julian Rudolf
Browse files
changed how to calculate worst case time
fixed shell script using wall clock time instead of processor time
parent
795f84eb
Changes
4
Hide whitespace changes
Inline
Side-by-side
Experiments/experiment.py
View file @
03e08974
...
...
@@ -9,12 +9,14 @@ def calculate_times(filename):
time_sum
=
0
time_file
=
open
(
"../Experiments/"
+
filename
,
"r"
)
times
=
(
time_file
.
readlines
())[:
200
]
worst_case
=
-
1
for
time
in
times
:
time
=
float
(
time
)
time_sum
+=
time
if
time
>
worst_case
:
worst_case
=
time
mean_time
=
time_sum
/
len
(
times
)
worst_case
=
max
(
times
)
return
mean_time
,
worst_case
...
...
@@ -31,11 +33,11 @@ def run_experiment(max_steps, length, source_filename, target_filename):
reset
(
True
,
int
(
length
))
mean
,
worst_case
=
calculate_times
(
source_filename
)
string
=
(
str
(
mean
)).
ljust
(
25
)
+
" "
+
str
(
worst_case
)
string
=
(
str
(
mean
)).
ljust
(
25
)
+
" "
+
str
(
worst_case
)
+
"
\n
"
target_file
=
open
(
target_filename
,
"a"
)
target_file
.
write
(
string
)
# run_experiment(
1
0, 10, "test.txt", "test2.txt")
# run_experiment(
3
0, 10, "test.txt", "test2.txt")
if
__name__
==
'__main__'
:
globals
()[
sys
.
argv
[
1
]](
sys
.
argv
[
2
],
sys
.
argv
[
3
],
sys
.
argv
[
4
],
sys
.
argv
[
5
])
Experiments/run_experiments.sh
View file @
03e08974
...
...
@@ -25,10 +25,10 @@ echo "-------------------------------------------" >> $TARGET_FILE
echo
"Starting experiments!"
for
i
in
10 15 20
do
echo
"Snake Length: "
$i
echo
"Snake Length: "
$i
>>
$TARGET_FILE
for
j
in
{
10..30
}
do
echo
"Snake length: "
$i
" max_steps: "
$j
echo
"Snake length: "
$i
" max_steps: "
$j
" calculating ..."
python experiment.py run_experiment
$j
$i
$SOURCE_FILE
$TARGET_FILE
rm
$SOURCE_FILE
done
...
...
Game/main.py
View file @
03e08974
...
...
@@ -432,7 +432,7 @@ class Snake:
except
AttributeError
:
choice
=
True
if
not
choice
and
False
:
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
):
...
...
Shield/shield.py
View file @
03e08974
...
...
@@ -617,7 +617,7 @@ def remove_files(files, master_filename='master.nm'):
# return:
# crash_prob : probability of a crash for each possible direction
def
get_shield
(
crash_prob_queue
,
snake_player
,
snake_enemy
,
count
=
0
,
recalc
=
False
,
p_move
=
0
):
shield_start
=
time
.
p
rocess_time_ns
()
shield_start
=
time
.
p
erf_counter
()
# master file name
master_filename
=
'master_'
+
str
(
uuid
.
uuid4
())
+
'.nm'
...
...
@@ -667,9 +667,9 @@ def get_shield(crash_prob_queue, snake_player, snake_enemy, count=0, recalc=Fals
# return the crash probabilities (multiprocessing)
crash_prob_queue
.
put
(
crash_prob
)
shield_end
=
time
.
p
rocess_time_ns
()
shield_end
=
time
.
p
erf_counter
()
total_time
=
shield_end
-
shield_start
total_time
/=
1e+9
#
total_time /= 1e+9
if
times_filename
:
times_file
=
open
(
"../Experiments/"
+
times_filename
,
"a"
)
times_file
.
write
(
str
(
total_time
)
+
"
\n
"
)
...
...
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