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
9c45fe84
Commit
9c45fe84
authored
Nov 09, 2020
by
Julian Rudolf
Browse files
added run_experiments.sh to automatically run experiments
parent
63e9c4d8
Changes
3
Hide whitespace changes
Inline
Side-by-side
Agent/snake_logic.py
View file @
9c45fe84
...
...
@@ -473,8 +473,6 @@ def init_game(max_steps=15, length=15, experiment=False, filename=False):
startsnake2
[
"pos"
].
pop
()
startsnake2
[
"vel"
].
pop
()
print
(
len
(
startsnake1
[
"pos"
]))
print
(
length
)
# create snakes
snake1
=
Snake
(
startsnake1
[
"pos"
],
startsnake1
[
"vel"
],
startsnake1
[
"angle"
],
0
,
act_shield
=
experiment
,
length
=
length
)
snake2
=
Snake
(
startsnake2
[
"pos"
],
startsnake2
[
"vel"
],
startsnake2
[
"angle"
],
1
,
act_shield
=
False
,
length
=
length
,
dir
=
False
)
...
...
Experiments/experiment.py
View file @
9c45fe84
from
Agent.snake_logic
import
init_game
,
reset
,
step
import
os
import
sys
# calculates mean and worst case over 200 values
...
...
@@ -24,19 +26,18 @@ def calculate_times(filename):
# source_filename : filename of times file in which mean and worst case is calculated
# target_filename : filename of final times file in which all means and worst cases are saved
def
run_experiment
(
max_steps
,
length
,
source_filename
,
target_filename
):
init_game
(
max_steps
,
length
,
True
,
source_filename
)
for
i
in
range
(
1
0
):
init_game
(
int
(
max_steps
)
,
int
(
length
)
,
True
,
source_filename
)
for
i
in
range
(
20
0
):
game_over
=
step
(
"left"
,
True
)
if
game_over
:
reset
(
True
,
length
)
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
"
target_file
=
open
(
target_filename
,
"a"
)
target_file
.
write
(
string
)
os
.
remove
(
"../Experiments/"
+
source_filename
)
run_experiment
(
15
,
20
,
"test.txt"
,
"test_target.txt"
)
run_experiment
(
10
,
15
,
"test2.txt"
,
"test_target.txt"
)
# run_experiment(10, 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
0 → 100644
View file @
9c45fe84
# In this shell script, experiments are run and saved in TARGET_FILE
# in order to run this shell the PYTHONPATH needs to be set to 2psnake directory
# To run an experiment, the python function "run_experiment" in /Experiments/experiment.py is called
# run_experiment plays the snake game with one shield activated and random actions
# Parameters:
# max_steps : for how many steps the SHIELD calculates the corresponding crash probabilities
# length : the length of the snakes
# source_filename : file where the game saves calculated times
# target_filename : file where the experiment handler saves mean and worst_case
#
# Experiments:
# Time for SHIELD to calculate probabilities in process time (mean and worst case)
#
export
PYTHONPATH
=
'/home/julian/PycharmProjects/2psnake'
TARGET_FILE
=
"experiments.txt"
SOURCE_FILE
=
"times.txt"
# removing old experiment files
rm
$TARGET_FILE
rm
$SOURCE_FILE
echo
"Starting experiments!"
for
i
in
10 15 20
do
for
j
in
{
10..30
}
do
echo
"Snake length: "
$i
" max_steps: "
$j
python experiment.py run_experiment
$j
$i
$SOURCE_FILE
$TARGET_FILE
rm
$SOURCE_FILE
done
done
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