mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2024-12-26 09:58:20 +01:00
configure by passing params rather than setting ENV variables
This commit is contained in:
parent
c39487e0cc
commit
32f1dfa5da
1 changed files with 163 additions and 96 deletions
|
@ -1,66 +1,27 @@
|
|||
#!/bin/bash
|
||||
set -u -e
|
||||
|
||||
NGAMES=${NGAMES:-1}
|
||||
NROOMS=${NROOMS:-$NGAMES}
|
||||
HOST=${HOST:-localhost}
|
||||
PORT=${PORT:-10997}
|
||||
TIMEOUT=${TIMEOUT:-$((NGAMES*60+500))}
|
||||
DICTS=${DICTS:-dict.xwd}
|
||||
SAVE_GOOD=${SAVE_GOOD:-YES}
|
||||
MINDEVS=${MINDEVS:-2}
|
||||
MAXDEVS=${MAXDEVS:-4}
|
||||
RESIGN_RATIO=${RESIGN_RATIO:-1000}
|
||||
DROP_N=${DROP_N:-0}
|
||||
APP_NEW=""
|
||||
NGAMES=""
|
||||
NROOMS=""
|
||||
HOST=""
|
||||
PORT=""
|
||||
TIMEOUT=""
|
||||
SAVE_GOOD=""
|
||||
MINDEVS=""
|
||||
MAXDEVS=""
|
||||
RESIGN_RATIO=""
|
||||
DROP_N=""
|
||||
MINRUN=2
|
||||
ONE_PER_ROOM=""
|
||||
USE_GTK=""
|
||||
ALL_VIA_RQ=${ALL_VIA_RQ:-FALSE}
|
||||
SEED=${SEED:-""}
|
||||
|
||||
APP_NEW=${APP_NEW:-"./obj_linux_memdbg/xwords"}
|
||||
APP_OLD=${APP_OLD:-""}
|
||||
|
||||
SEED=""
|
||||
BOARD_SIZES_OLD=(15)
|
||||
BOARD_SIZES_NEW=(15 17)
|
||||
|
||||
declare -a DICTS_ARR
|
||||
for DICT in $DICTS; do
|
||||
DICTS_ARR[${#DICTS_ARR[*]}]=$DICT
|
||||
done
|
||||
|
||||
NAMES=(UNUSED Brynn Ariela Kati Eric)
|
||||
[ -n "$SEED" ] && RANDOM=$SEED
|
||||
|
||||
LOGDIR=$(basename $0)_logs
|
||||
RESUME=""
|
||||
for FILE in $(ls $LOGDIR/*.{xwg,txt} 2>/dev/null); do
|
||||
if [ -e $FILE ]; then
|
||||
echo "Unfinished games found in $LOGDIR; continue with them (or discard)?"
|
||||
read -p "<yes/no> " ANSWER
|
||||
case "$ANSWER" in
|
||||
y|yes|Y|YES)
|
||||
RESUME=1
|
||||
;;
|
||||
*)
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
break
|
||||
done
|
||||
|
||||
if [ -z "$RESUME" -a -d $LOGDIR ];then
|
||||
mv $LOGDIR /tmp/${LOGDIR}_$$
|
||||
fi
|
||||
mkdir -p $LOGDIR
|
||||
|
||||
if [ "$SAVE_GOOD" = YES ]; then
|
||||
DONEDIR=$LOGDIR/done
|
||||
mkdir -p $DONEDIR
|
||||
fi
|
||||
DEADDIR=$LOGDIR/dead
|
||||
mkdir -p $DEADDIR
|
||||
|
||||
USE_GTK=${USE_GTK:-FALSE}
|
||||
|
||||
declare -A PIDS
|
||||
declare -A APPS
|
||||
|
@ -70,43 +31,17 @@ declare -A FILES
|
|||
declare -A LOGS
|
||||
declare -A MINEND
|
||||
declare -A ROOM_PIDS
|
||||
# if [ TRUE = "$ALL_VIA_RQ" ]; then
|
||||
# declare -A PIPES
|
||||
# fi
|
||||
declare -a APPS_OLD
|
||||
declare -A CHECKED_ROOMS
|
||||
|
||||
PLAT_PARMS=""
|
||||
if [ $USE_GTK = FALSE ]; then
|
||||
PLAT_PARMS="--curses --close-stdin"
|
||||
fi
|
||||
|
||||
usage() {
|
||||
echo "usage: [env=val *] $0" 1>&2
|
||||
echo " current env variables and their values: " 1>&2
|
||||
for VAR in NGAMES NROOMS USE_GTK TIMEOUT HOST PORT DICTS SAVE_GOOD \
|
||||
MINDEVS MAXDEVS RESIGN_RATIO DROP_N ALL_VIA_RQ SEED \
|
||||
APP_NEW APP_OLD; do
|
||||
echo "$VAR:" $(eval "echo \$${VAR}") 1>&2
|
||||
done
|
||||
exit 1
|
||||
}
|
||||
|
||||
connName() {
|
||||
function connName() {
|
||||
LOG=$1
|
||||
grep 'got_connect_cmd: connName' $LOG | \
|
||||
tail -n 1 | \
|
||||
sed 's,^.*connName: \"\(.*\)\"$,\1,'
|
||||
}
|
||||
|
||||
while [ "$#" -gt 0 ]; do
|
||||
case $1 in
|
||||
*) usage
|
||||
;;
|
||||
esac
|
||||
shift
|
||||
done
|
||||
|
||||
declare -A CHECKED_ROOMS
|
||||
check_room() {
|
||||
function check_room() {
|
||||
ROOM=$1
|
||||
if [ -z ${CHECKED_ROOMS[$ROOM]:-""} ]; then
|
||||
NUM=$(echo "SELECT COUNT(*) FROM games "\
|
||||
|
@ -133,13 +68,18 @@ print_cmdline() {
|
|||
|
||||
build_cmds() {
|
||||
COUNTER=0
|
||||
PLAT_PARMS=""
|
||||
if [ $USE_GTK = FALSE ]; then
|
||||
PLAT_PARMS="--curses --close-stdin"
|
||||
fi
|
||||
|
||||
for GAME in $(seq 1 $NGAMES); do
|
||||
ROOM=$(printf "ROOM_%.3d" $((GAME % NROOMS)))
|
||||
ROOM_PIDS[$ROOM]=0
|
||||
check_room $ROOM
|
||||
NDEVS=$(( $RANDOM % ($MAXDEVS-1) + 2 ))
|
||||
[ $NDEVS -lt $MINDEVS ] && NDEVS=$MINDEVS
|
||||
DICT=${DICTS_ARR[$((GAME%${#DICTS_ARR[*]}))]}
|
||||
DICT=${DICTS[$((GAME%${#DICTS[*]}))]}
|
||||
# make one in three games public
|
||||
PUBLIC=""
|
||||
[ $((RANDOM%3)) -eq 0 ] && PUBLIC="--make-public --join-public"
|
||||
|
@ -154,24 +94,22 @@ build_cmds() {
|
|||
LOG=${LOGDIR}/${GAME}_${DEV}_LOG.txt
|
||||
> $LOG # clear the log
|
||||
touch $LOG # so greps won't show errors
|
||||
PARAMS=""
|
||||
APPS[$COUNTER]="$APP_NEW"
|
||||
if [ -n "$APP_OLD" ]; then
|
||||
BOARD_SIZE="--board-size ${BOARD_SIZES_NEW[$((RANDOM%${#BOARD_SIZES_NEW[*]}))]}"
|
||||
if [ xx = "${APPS_OLD+xx}" ]; then
|
||||
# 50% chance of starting out with old app
|
||||
if [ 0 -eq $((RANDOM%2)) ]; then
|
||||
APPS[$COUNTER]="$APP_OLD"
|
||||
APPS[$COUNTER]=${APPS_OLD[$((RANDOM%${#APPS_OLD[*]}))]}
|
||||
BOARD_SIZE="--board-size ${BOARD_SIZES_OLD[$((RANDOM%${#BOARD_SIZES_OLD[*]}))]}"
|
||||
fi
|
||||
fi
|
||||
PARAMS="--room $ROOM"
|
||||
PARAMS="$PARAMS $BOARD_SIZE --room $ROOM"
|
||||
PARAMS="$PARAMS --robot ${NAMES[$DEV]} --robot-iq $((1 + (RANDOM%100))) "
|
||||
PARAMS="$PARAMS $OTHERS --game-dict $DICT --port $PORT --host $HOST "
|
||||
PARAMS="$PARAMS --file $FILE --slow-robot 1:3 --skip-confirm"
|
||||
PARAMS="$PARAMS --drop-nth-packet $DROP_N $PLAT_PARMS"
|
||||
[ -n "$SEED" ] && PARAMS="$PARAMS --seed $RANDOM"
|
||||
if [ -n "$APP_OLD" -a "${APPS[$COUNTER]}" = "$APP_OLD" ]; then
|
||||
PARAMS="$PARAMS --board-size ${BOARD_SIZES_OLD[$((RANDOM%${#BOARD_SIZES_OLD[*]}))]}"
|
||||
else
|
||||
PARAMS="$PARAMS --board-size ${BOARD_SIZES_NEW[$((RANDOM%${#BOARD_SIZES_NEW[*]}))]}"
|
||||
fi
|
||||
PARAMS="$PARAMS $PUBLIC"
|
||||
ARGS[$COUNTER]=$PARAMS
|
||||
ROOMS[$COUNTER]=$ROOM
|
||||
|
@ -292,8 +230,8 @@ maybe_resign() {
|
|||
|
||||
try_upgrade() {
|
||||
KEY=$1
|
||||
if [ -n "$APP_OLD" ]; then
|
||||
if [ $APP_OLD = ${APPS[$KEY]} ]; then
|
||||
if [ xx = "${APPS_OLD+xx}" ]; then
|
||||
if [ $APP_NEW != ${APPS[$KEY]} ]; then
|
||||
# one in five chance of upgrading
|
||||
if [ 0 -eq $((RANDOM%5)) ]; then
|
||||
APPS[$KEY]=$APP_NEW
|
||||
|
@ -443,10 +381,140 @@ run_via_rq() {
|
|||
done
|
||||
} # run_via_rq
|
||||
|
||||
print_stats() {
|
||||
:
|
||||
function getArg() {
|
||||
echo $* >&2
|
||||
[ 1 -lt "$#" ] || usage "$1 requires an argument"
|
||||
echo $2
|
||||
}
|
||||
|
||||
function usage() {
|
||||
[ $# -gt 0 ] && echo "Error: $1" >&2
|
||||
echo "Usage: $(basename $0) \\" >&2
|
||||
echo " [--dict <path/to/dict>]* \\" >&2
|
||||
echo " [--old-app <path/to/app]* \\" >&2
|
||||
echo " [--new-app <path/to/app] \\" >&2
|
||||
echo " [--min-devs <int>] \\" >&2
|
||||
echo " [--max-devs <int>] \\" >&2
|
||||
echo " [--help] \\" >&2
|
||||
echo " [--num-games <int>] \\" >&2
|
||||
echo " [--num-rooms <int>] \\" >&2
|
||||
echo " [--host <hostname>] \\" >&2
|
||||
echo " [--port <int>] \\" >&2
|
||||
echo " [--seed <int>] \\" >&2
|
||||
echo " [--help] \\" >&2
|
||||
|
||||
exit 1
|
||||
}
|
||||
|
||||
#######################################################
|
||||
##################### MAIN begins #####################
|
||||
#######################################################
|
||||
|
||||
while [ "$#" -gt 0 ]; do
|
||||
case $1 in
|
||||
--num-games)
|
||||
NGAMES=$(getArg $*)
|
||||
shift
|
||||
;;
|
||||
--num-rooms)
|
||||
NROOMS=$(getArg $*)
|
||||
shift
|
||||
;;
|
||||
--old-app)
|
||||
APPS_OLD[${#APPS_OLD[@]}]=$(getArg $*)
|
||||
shift
|
||||
;;
|
||||
--new-app)
|
||||
APP_NEW=$(getArg $*)
|
||||
shift
|
||||
;;
|
||||
--dict)
|
||||
DICTS[${#DICTS[@]}]=$(getArg $*)
|
||||
shift
|
||||
;;
|
||||
--min-devs)
|
||||
MINDEVS=$(getArg $*)
|
||||
shift
|
||||
;;
|
||||
--max-devs)
|
||||
MAXDEVS=$(getArg $*)
|
||||
shift
|
||||
;;
|
||||
--host)
|
||||
HOST=$(getArg $*)
|
||||
shift
|
||||
;;
|
||||
--port)
|
||||
PORT=$(getArg $*)
|
||||
shift
|
||||
;;
|
||||
--seed)
|
||||
SEED=$(getArg $*)
|
||||
shift
|
||||
;;
|
||||
--help)
|
||||
usage
|
||||
;;
|
||||
*) usage "unrecognized option $1"
|
||||
;;
|
||||
esac
|
||||
shift
|
||||
done
|
||||
|
||||
# Assign defaults
|
||||
#[ 0 -eq ${#DICTS[@]} ] && DICTS=(dict.xwd)
|
||||
[ xx = "${DICTS+xx}" ] || DICTS=(dict.xwd)
|
||||
[ -z "$APP_NEW" ] && APP_NEW=./obj_linux_memdbg/xwords
|
||||
[ -z "$MINDEVS" ] && MINDEVS=2
|
||||
[ -z "$MAXDEVS" ] && MAXDEVS=4
|
||||
[ -z "$NGAMES" ] && NGAMES=1
|
||||
[ -z "$NROOMS" ] && NROOMS=$NGAMES
|
||||
[ -z "$HOST" ] && HOST=localhost
|
||||
[ -z "$PORT" ] && PORT=10997
|
||||
[ -z "$TIMEOUT" ] && TIMEOUT=$((NGAMES*60+500))
|
||||
[ -z "$SAVE_GOOD" ] && SAVE_GOOD=YES
|
||||
[ -z "$RESIGN_RATIO" ] && RESIGN_RATIO=1000
|
||||
[ -z "$DROP_N" ] && DROP_N=0
|
||||
[ -z "$USE_GTK" ] && USE_GTK=FALSE
|
||||
|
||||
|
||||
LOGDIR=$(basename $0)_logs
|
||||
RESUME=""
|
||||
for FILE in $(ls $LOGDIR/*.{xwg,txt} 2>/dev/null); do
|
||||
if [ -e $FILE ]; then
|
||||
echo "Unfinished games found in $LOGDIR; continue with them (or discard)?"
|
||||
read -p "<yes/no> " ANSWER
|
||||
case "$ANSWER" in
|
||||
y|yes|Y|YES)
|
||||
RESUME=1
|
||||
;;
|
||||
*)
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
break
|
||||
done
|
||||
|
||||
if [ -z "$RESUME" -a -d $LOGDIR ];then
|
||||
mv $LOGDIR /tmp/${LOGDIR}_$$
|
||||
fi
|
||||
mkdir -p $LOGDIR
|
||||
|
||||
if [ "$SAVE_GOOD" = YES ]; then
|
||||
DONEDIR=$LOGDIR/done
|
||||
mkdir -p $DONEDIR
|
||||
fi
|
||||
DEADDIR=$LOGDIR/dead
|
||||
mkdir -p $DEADDIR
|
||||
|
||||
for VAR in NGAMES NROOMS USE_GTK TIMEOUT HOST PORT SAVE_GOOD \
|
||||
MINDEVS MAXDEVS RESIGN_RATIO DROP_N ALL_VIA_RQ SEED \
|
||||
APP_NEW; do
|
||||
echo "$VAR:" $(eval "echo \$${VAR}") 1>&2
|
||||
done
|
||||
echo "DICTS: ${DICTS[*]}"
|
||||
echo -n "APPS_OLD: "; [ xx = "${APPS_OLD[*]+xx}" ] && echo "APPS_OLD: ${APPS_OLD[*]}" || echo ""
|
||||
|
||||
echo "*********$0 starting: $(date)**************"
|
||||
STARTTIME=$(date +%s)
|
||||
[ -z "$RESUME" ] && build_cmds || read_resume_cmds
|
||||
|
@ -455,7 +523,6 @@ if [ TRUE = "$ALL_VIA_RQ" ]; then
|
|||
else
|
||||
run_cmds
|
||||
fi
|
||||
print_stats
|
||||
|
||||
wait
|
||||
|
||||
|
|
Loading…
Reference in a new issue