master
Peter Babič 9 years ago
parent 41aa87707c
commit cc84e4faaa
  1. 33
      robocode-svm

@ -9,11 +9,19 @@ settings="$path/.settings.battle"
results="$path/.results.data" results="$path/.results.data"
training="$path/training.data" training="$path/training.data"
testing="$path/testing.data" testing="$path/testing.data"
# scaling="$path/scaling.data"
# Battle parameters # Battle parameters
rounds=10 rounds=1000
width=500 width=500
height=500 height=500
robot1="sample.SpinBot"
robot2="sample.VelociRobot"
# Run battle without GUI, following the settings file, and returning the lines containing winners
battle() {
echo $(robocode -nodisplay -battle "$settings" | tail -2);
}
# Make sure files are right # Make sure files are right
cd $path cd $path
@ -35,25 +43,34 @@ robocode.battleField.height=$height
robocode.battle.numRounds=1 robocode.battle.numRounds=1
robocode.battle.gunCoolingRate=0.1 robocode.battle.gunCoolingRate=0.1
robocode.battle.rules.inactivityTime=450 robocode.battle.rules.inactivityTime=450
robocode.battle.selectedRobots=sample.TrackFire,sample.TrackFire robocode.battle.selectedRobots=$robot1,$robot2
robocode.battle.initialPositions=($(($width/2)),$(($height/2)),0),($x,$y,$alpha)" > "$settings" robocode.battle.initialPositions=($(($width/2)),$(($height/2)),0),($x,$y,$alpha)" > "$settings"
# Extract the winner from battle # If the robots are of the same name
winner=$(robocode -nodisplay -battle "$settings" | tail -2 | awk 'NR==1 {print substr($3,2,1)}') if [ "$robot1" == "$robot2" ] ; then
# Their order number is in the bracket after the name
winner=$(battle | awk 'NR==1 {print substr($3,2,1)}')
else
# Otherwise we need to match the actual names
winner=$(battle | awk 'NR==1F {print $2}')
if [ "$winner" == "$robot1" ] ; then
winner=1
else
winner=2
fi
fi
# Inform user about the winner of current round and append the results to the file # Inform user about the winner of current round and append the results to the file
echo "Round $i winner: $winner" echo "Round $i winner: $winner"
echo "$winner 1:$x 2:$y" >> "$results" # echo "$winner 1:$x 2:$y" >> "$results"
# echo "$winner 1:$x 2:$y 3:$alpha" >> "$results" echo "$winner 1:$x 2:$y 3:$alpha" >> "$results"
done done
# Calculate the lines needed to split the data to 90% and 10% # Calculate the lines needed to split the data to 90% and 10%
tr=$(bc <<< "scale=0; $rounds * 0.9 / 1"); tr=$(bc <<< "scale=0; $rounds * 0.9 / 1");
te=$(bc <<< "scale=0; ($rounds - $tr) / 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; # 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 # 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 svm-scale -l 0 -u 1 "$results" | tee >(head -n $tr > "$training") >(tail -n $te > "$testing") > /dev/null

Loading…
Cancel
Save