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
795f84eb
Commit
795f84eb
authored
Nov 09, 2020
by
Julian Rudolf
Browse files
changed style for saved experiments txt file
parent
9c45fe84
Changes
3
Hide whitespace changes
Inline
Side-by-side
Experiments/experiment.py
View file @
795f84eb
...
...
@@ -15,8 +15,6 @@ def calculate_times(filename):
mean_time
=
time_sum
/
len
(
times
)
worst_case
=
max
(
times
)
print
(
mean_time
)
print
(
worst_case
)
return
mean_time
,
worst_case
...
...
@@ -33,7 +31,7 @@ def run_experiment(max_steps, length, source_filename, target_filename):
reset
(
True
,
int
(
length
))
mean
,
worst_case
=
calculate_times
(
source_filename
)
string
=
"Max Steps: "
+
str
(
max_steps
)
+
" | Snake Length: "
+
str
(
length
)
+
"
\n
"
+
"Mean = "
+
str
(
mean
)
+
"
\n
Worst Case =
"
+
str
(
worst_case
)
+
"
\n
"
string
=
(
str
(
mean
)).
ljust
(
25
)
+
"
"
+
str
(
worst_case
)
target_file
=
open
(
target_filename
,
"a"
)
target_file
.
write
(
string
)
...
...
Experiments/run_experiments.sh
View file @
795f84eb
...
...
@@ -20,9 +20,12 @@ SOURCE_FILE="times.txt"
rm
$TARGET_FILE
rm
$SOURCE_FILE
echo
"Mean Worst-Case"
>>
$TARGET_FILE
echo
"-------------------------------------------"
>>
$TARGET_FILE
echo
"Starting experiments!"
for
i
in
10 15 20
do
echo
"Snake Length: "
$i
for
j
in
{
10..30
}
do
echo
"Snake length: "
$i
" max_steps: "
$j
...
...
Shield/shield.py
View file @
795f84eb
...
...
@@ -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
.
process_time
()
shield_start
=
time
.
process_time
_ns
()
# master file name
master_filename
=
'master_'
+
str
(
uuid
.
uuid4
())
+
'.nm'
...
...
@@ -667,8 +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
.
process_time
()
shield_end
=
time
.
process_time
_ns
()
total_time
=
shield_end
-
shield_start
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