Commit 9c45fe84 authored by Julian Rudolf's avatar Julian Rudolf
Browse files

added to automatically run experiments

parent 63e9c4d8
......@@ -473,8 +473,6 @@ def init_game(max_steps=15, length=15, experiment=False, filename=False):
# 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)
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(10):
init_game(int(max_steps), int(length), True, source_filename)
for i in range(200):
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) + "\nWorst Case = " + str(worst_case) + "\n"
target_file = open(target_filename, "a")
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])
# 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/ 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'
# removing old experiment files
echo "Starting experiments!"
for i in 10 15 20
for j in {10..30}
echo "Snake length: " $i " max_steps: " $j
python run_experiment $j $i $SOURCE_FILE $TARGET_FILE
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