added parameters and help

master
Peter Babič 9 years ago
parent 1ea99d64bd
commit 9bfa5598f5
  1. 0
      backup_96/testing.data.2
  2. 0
      backup_96/training.data.2
  3. 0
      backup_96/visualize.png
  4. 67
      robocode-svm

@ -4,12 +4,11 @@ set -u
# set -x
# File locations
path="$HOME/dev/bash/robocode/svm"
settings="$path/.settings.battle"
results="$path/.results.data"
training="$path/training.data"
testing="$path/testing.data"
# scaling="$path/scaling.data"
datadir="data"
results="$datadir/battle.data"
settings="$datadir/settings.last.battle"
training="$datadir/training.scale.data"
testing="$datadir/testing.scale.data"
# Battle parameters
rounds=1000
@ -18,14 +17,58 @@ height=500
robot1="sample.Corners"
robot2="sample.Fire"
# Delete the battle data so the will get freshly generated
flush_battle_data() {
rm -f "$datadir/*"
touch "$results"
}
# Help function
show_help() {
echo "USAGE: robocode-svm OPTIONS"
echo " -v, --visualize Shows visual run of the battle"
echo " -x The x coordinate of the second robot, used with -v"
echo " -y The y coordinate of the second robot, used with -v"
echo " -a, --accuracy Only show the accuracy of the SVM prediction"
echo " -c, --clean Clean run (deletes everything inside data folder)"
echo " -h, --help Show this help"
}
# Run battle without GUI, following the settings file, and returning the lines containing winners
battle() {
run_battle() {
robocode -nodisplay -battle "$settings" | tail -2;
}
# Make sure files are right
cd "$path";
rm -f "$results"; touch "$results"
# Prepare the data directory
mkdir -p "$datadir/";
while :; do
case $1 in
# Regenerate data files
-c|--clean)
flush_battle_data
;;
# Call a "show_help" function to display a synopsis, then exit.
-h|-\?|--help)
show_help
exit
;;
# Unrecognized parameter
-?*)
printf 'WARNING: Unknown option (ignored): %s\n' "$1" >&2
;;
# Default case: If no more options then break out of the loop.
*)
break
esac
# "command" reduces the chance of fatal errors in many shells.
command shift
done
# Repeat the battle desired number of times
for i in $(seq 1 $rounds);
@ -49,10 +92,10 @@ robocode.battle.initialPositions=($((width/2)),$((height/2)),0),($x,$y,$alpha)"
# If the robots are of the same name
if [ "$robot1" == "$robot2" ] ; then
# Their order number is in the bracket after the name
winner=$(battle | awk 'NR==1 {print substr($3,2,1)}')
winner=$(run_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}')
winner=$(run_battle | awk 'NR==1F {print $2}')
if [ "$winner" == "$robot1" ] ; then
winner=1
else

Loading…
Cancel
Save