commit 67a1365af77adfceb6f075b66b458d3b1a3bec9a Author: Peter Babič Date: Thu Apr 23 09:16:10 2015 +0200 scaling of outputs working diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..4952350 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,2 @@ +*.pdf filter=lfs diff=lfs merge=lfs -text +*.png filter=lfs diff=lfs merge=lfs -text diff --git a/.results.data b/.results.data new file mode 100644 index 0000000..975dfa3 --- /dev/null +++ b/.results.data @@ -0,0 +1,10 @@ +2 1:316 2:151 +1 1:279 2:157 +1 1:144 2:157 +1 1:398 2:321 +1 1:315 2:37 +2 1:441 2:169 +1 1:181 2:281 +2 1:267 2:57 +1 1:292 2:138 +2 1:349 2:44 diff --git a/.settings.battle b/.settings.battle new file mode 100644 index 0000000..6041fe5 --- /dev/null +++ b/.settings.battle @@ -0,0 +1,8 @@ +#Battle Properties +robocode.battleField.width=500 +robocode.battleField.height=500 +robocode.battle.numRounds=1 +robocode.battle.gunCoolingRate=0.1 +robocode.battle.rules.inactivityTime=450 +robocode.battle.selectedRobots=sample.TrackFire,sample.TrackFire +robocode.battle.initialPositions=(250,250,0),(349,44,274) diff --git a/README.md b/README.md new file mode 100644 index 0000000..f7ae12b --- /dev/null +++ b/README.md @@ -0,0 +1 @@ +robocode-svm diff --git a/config/robocode.properties b/config/robocode.properties new file mode 100644 index 0000000..cb2075c --- /dev/null +++ b/config/robocode.properties @@ -0,0 +1,5 @@ +#Robocode Properties +#Wed Apr 22 18:10:36 CEST 2015 +robocode.cpu.constant=14014678 +robocode.options.battle.desiredTPS=10000 +robocode.version.lastrun=1.9.2.3 diff --git a/robocode-svm b/robocode-svm new file mode 100755 index 0000000..2362d98 --- /dev/null +++ b/robocode-svm @@ -0,0 +1,57 @@ +#!/usr/bin/env bash + +set -u +set -e + +# File locations +path="$HOME/dev/bash/robocode/svm" +settings="$path/.settings.battle" +results="$path/.results.data" +training="$path/training.data" +testing="$path/testing.data" + +# Battle parameters +rounds=10 +width=500 +height=500 + +# Make sure files are right +cd $path +rm -f "$results"; touch "$results" + +# Repeat the battle desired number of times +for i in `seq 1 $rounds`; +do + # Generate input parameters + number=$RANDOM; let "number %= $width"; x=$number + number=$RANDOM; let "number %= $height"; y=$number + number=$RANDOM; let "number %= 360"; alpha=$number + + # Write current settings to a file; first robot starts in the middle, with fixed gun angle; + # the other one start at random known position, with random known gun angle + echo "#Battle Properties +robocode.battleField.width=$width +robocode.battleField.height=$height +robocode.battle.numRounds=1 +robocode.battle.gunCoolingRate=0.1 +robocode.battle.rules.inactivityTime=450 +robocode.battle.selectedRobots=sample.TrackFire,sample.TrackFire +robocode.battle.initialPositions=($(($width/2)),$(($height/2)),0),($x,$y,$alpha)" > "$settings" + + # Extract the winner from battle + winner=$(robocode -nodisplay -battle "$settings" | tail -2 | awk 'NR==1 {print substr($3,2,1)}') + + # Inform user about the winner of current round and append the results to the file + echo "Round $i winner: $winner" + echo "$winner 1:$x 2:$y" >> "$results" + # echo "$winner 1:$x 2:$y 3:$alpha" >> "$results" +done + +# Calculate the lines needed to split the data to 90% and 10% +tr=$(bc <<< "scale=0; $rounds * 0.9 / 1"); +te=$(bc <<< "scale=0; ($rounds - $tr) / 1"); +echo "tr: $tr, te: $te" + +# Scale the results to interval <0, 1> and split them to training set and testing set; +# misuse tee for 'process substituion' and send its stdout do /dev/null +svm-scale -l 0 -u 1 "$results" | tee >(head -n $tr > "$training") >(tail -n $te > "$testing") > /dev/null diff --git a/testing.data b/testing.data new file mode 100644 index 0000000..522ee16 --- /dev/null +++ b/testing.data @@ -0,0 +1 @@ +2 1:0.690236 2:0.0246479 diff --git a/training.data b/training.data new file mode 100644 index 0000000..10e38b4 --- /dev/null +++ b/training.data @@ -0,0 +1,9 @@ +2 1:0.579125 2:0.401408 +1 1:0.454545 2:0.422535 +1 2:0.422535 +1 1:0.855219 2:1 +1 1:0.575758 +2 1:1 2:0.464789 +1 1:0.124579 2:0.859155 +2 1:0.414141 2:0.0704225 +1 1:0.498316 2:0.355634