mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-01-27 07:58:49 +01:00
Merge remote branch 'origin/android_branch' into android_branch
This commit is contained in:
commit
1272ed3bf5
1 changed files with 163 additions and 96 deletions
|
@ -1,66 +1,27 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
set -u -e
|
set -u -e
|
||||||
|
|
||||||
NGAMES=${NGAMES:-1}
|
APP_NEW=""
|
||||||
NROOMS=${NROOMS:-$NGAMES}
|
NGAMES=""
|
||||||
HOST=${HOST:-localhost}
|
NROOMS=""
|
||||||
PORT=${PORT:-10997}
|
HOST=""
|
||||||
TIMEOUT=${TIMEOUT:-$((NGAMES*60+500))}
|
PORT=""
|
||||||
DICTS=${DICTS:-dict.xwd}
|
TIMEOUT=""
|
||||||
SAVE_GOOD=${SAVE_GOOD:-YES}
|
SAVE_GOOD=""
|
||||||
MINDEVS=${MINDEVS:-2}
|
MINDEVS=""
|
||||||
MAXDEVS=${MAXDEVS:-4}
|
MAXDEVS=""
|
||||||
RESIGN_RATIO=${RESIGN_RATIO:-1000}
|
RESIGN_RATIO=""
|
||||||
DROP_N=${DROP_N:-0}
|
DROP_N=""
|
||||||
MINRUN=2
|
MINRUN=2
|
||||||
ONE_PER_ROOM=""
|
ONE_PER_ROOM=""
|
||||||
|
USE_GTK=""
|
||||||
ALL_VIA_RQ=${ALL_VIA_RQ:-FALSE}
|
ALL_VIA_RQ=${ALL_VIA_RQ:-FALSE}
|
||||||
SEED=${SEED:-""}
|
SEED=""
|
||||||
|
|
||||||
APP_NEW=${APP_NEW:-"./obj_linux_memdbg/xwords"}
|
|
||||||
APP_OLD=${APP_OLD:-""}
|
|
||||||
|
|
||||||
BOARD_SIZES_OLD=(15)
|
BOARD_SIZES_OLD=(15)
|
||||||
BOARD_SIZES_NEW=(15 17)
|
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)
|
NAMES=(UNUSED Brynn Ariela Kati Eric)
|
||||||
[ -n "$SEED" ] && RANDOM=$SEED
|
[ -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 PIDS
|
||||||
declare -A APPS
|
declare -A APPS
|
||||||
|
@ -70,43 +31,17 @@ declare -A FILES
|
||||||
declare -A LOGS
|
declare -A LOGS
|
||||||
declare -A MINEND
|
declare -A MINEND
|
||||||
declare -A ROOM_PIDS
|
declare -A ROOM_PIDS
|
||||||
# if [ TRUE = "$ALL_VIA_RQ" ]; then
|
declare -a APPS_OLD
|
||||||
# declare -A PIPES
|
declare -A CHECKED_ROOMS
|
||||||
# fi
|
|
||||||
|
|
||||||
PLAT_PARMS=""
|
function connName() {
|
||||||
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() {
|
|
||||||
LOG=$1
|
LOG=$1
|
||||||
grep 'got_connect_cmd: connName' $LOG | \
|
grep 'got_connect_cmd: connName' $LOG | \
|
||||||
tail -n 1 | \
|
tail -n 1 | \
|
||||||
sed 's,^.*connName: \"\(.*\)\"$,\1,'
|
sed 's,^.*connName: \"\(.*\)\"$,\1,'
|
||||||
}
|
}
|
||||||
|
|
||||||
while [ "$#" -gt 0 ]; do
|
function check_room() {
|
||||||
case $1 in
|
|
||||||
*) usage
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
shift
|
|
||||||
done
|
|
||||||
|
|
||||||
declare -A CHECKED_ROOMS
|
|
||||||
check_room() {
|
|
||||||
ROOM=$1
|
ROOM=$1
|
||||||
if [ -z ${CHECKED_ROOMS[$ROOM]:-""} ]; then
|
if [ -z ${CHECKED_ROOMS[$ROOM]:-""} ]; then
|
||||||
NUM=$(echo "SELECT COUNT(*) FROM games "\
|
NUM=$(echo "SELECT COUNT(*) FROM games "\
|
||||||
|
@ -133,13 +68,18 @@ print_cmdline() {
|
||||||
|
|
||||||
build_cmds() {
|
build_cmds() {
|
||||||
COUNTER=0
|
COUNTER=0
|
||||||
|
PLAT_PARMS=""
|
||||||
|
if [ $USE_GTK = FALSE ]; then
|
||||||
|
PLAT_PARMS="--curses --close-stdin"
|
||||||
|
fi
|
||||||
|
|
||||||
for GAME in $(seq 1 $NGAMES); do
|
for GAME in $(seq 1 $NGAMES); do
|
||||||
ROOM=$(printf "ROOM_%.3d" $((GAME % NROOMS)))
|
ROOM=$(printf "ROOM_%.3d" $((GAME % NROOMS)))
|
||||||
ROOM_PIDS[$ROOM]=0
|
ROOM_PIDS[$ROOM]=0
|
||||||
check_room $ROOM
|
check_room $ROOM
|
||||||
NDEVS=$(( $RANDOM % ($MAXDEVS-1) + 2 ))
|
NDEVS=$(( $RANDOM % ($MAXDEVS-1) + 2 ))
|
||||||
[ $NDEVS -lt $MINDEVS ] && NDEVS=$MINDEVS
|
[ $NDEVS -lt $MINDEVS ] && NDEVS=$MINDEVS
|
||||||
DICT=${DICTS_ARR[$((GAME%${#DICTS_ARR[*]}))]}
|
DICT=${DICTS[$((GAME%${#DICTS[*]}))]}
|
||||||
# make one in three games public
|
# make one in three games public
|
||||||
PUBLIC=""
|
PUBLIC=""
|
||||||
[ $((RANDOM%3)) -eq 0 ] && PUBLIC="--make-public --join-public"
|
[ $((RANDOM%3)) -eq 0 ] && PUBLIC="--make-public --join-public"
|
||||||
|
@ -154,24 +94,22 @@ build_cmds() {
|
||||||
LOG=${LOGDIR}/${GAME}_${DEV}_LOG.txt
|
LOG=${LOGDIR}/${GAME}_${DEV}_LOG.txt
|
||||||
> $LOG # clear the log
|
> $LOG # clear the log
|
||||||
touch $LOG # so greps won't show errors
|
touch $LOG # so greps won't show errors
|
||||||
|
PARAMS=""
|
||||||
APPS[$COUNTER]="$APP_NEW"
|
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
|
# 50% chance of starting out with old app
|
||||||
if [ 0 -eq $((RANDOM%2)) ]; then
|
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
|
||||||
fi
|
fi
|
||||||
PARAMS="--room $ROOM"
|
PARAMS="$PARAMS $BOARD_SIZE --room $ROOM"
|
||||||
PARAMS="$PARAMS --robot ${NAMES[$DEV]} --robot-iq $((1 + (RANDOM%100))) "
|
PARAMS="$PARAMS --robot ${NAMES[$DEV]} --robot-iq $((1 + (RANDOM%100))) "
|
||||||
PARAMS="$PARAMS $OTHERS --game-dict $DICT --port $PORT --host $HOST "
|
PARAMS="$PARAMS $OTHERS --game-dict $DICT --port $PORT --host $HOST "
|
||||||
PARAMS="$PARAMS --file $FILE --slow-robot 1:3 --skip-confirm"
|
PARAMS="$PARAMS --file $FILE --slow-robot 1:3 --skip-confirm"
|
||||||
PARAMS="$PARAMS --drop-nth-packet $DROP_N $PLAT_PARMS"
|
PARAMS="$PARAMS --drop-nth-packet $DROP_N $PLAT_PARMS"
|
||||||
[ -n "$SEED" ] && PARAMS="$PARAMS --seed $RANDOM"
|
[ -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"
|
PARAMS="$PARAMS $PUBLIC"
|
||||||
ARGS[$COUNTER]=$PARAMS
|
ARGS[$COUNTER]=$PARAMS
|
||||||
ROOMS[$COUNTER]=$ROOM
|
ROOMS[$COUNTER]=$ROOM
|
||||||
|
@ -292,8 +230,8 @@ maybe_resign() {
|
||||||
|
|
||||||
try_upgrade() {
|
try_upgrade() {
|
||||||
KEY=$1
|
KEY=$1
|
||||||
if [ -n "$APP_OLD" ]; then
|
if [ xx = "${APPS_OLD+xx}" ]; then
|
||||||
if [ $APP_OLD = ${APPS[$KEY]} ]; then
|
if [ $APP_NEW != ${APPS[$KEY]} ]; then
|
||||||
# one in five chance of upgrading
|
# one in five chance of upgrading
|
||||||
if [ 0 -eq $((RANDOM%5)) ]; then
|
if [ 0 -eq $((RANDOM%5)) ]; then
|
||||||
APPS[$KEY]=$APP_NEW
|
APPS[$KEY]=$APP_NEW
|
||||||
|
@ -443,10 +381,140 @@ run_via_rq() {
|
||||||
done
|
done
|
||||||
} # run_via_rq
|
} # 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)**************"
|
echo "*********$0 starting: $(date)**************"
|
||||||
STARTTIME=$(date +%s)
|
STARTTIME=$(date +%s)
|
||||||
[ -z "$RESUME" ] && build_cmds || read_resume_cmds
|
[ -z "$RESUME" ] && build_cmds || read_resume_cmds
|
||||||
|
@ -455,7 +523,6 @@ if [ TRUE = "$ALL_VIA_RQ" ]; then
|
||||||
else
|
else
|
||||||
run_cmds
|
run_cmds
|
||||||
fi
|
fi
|
||||||
print_stats
|
|
||||||
|
|
||||||
wait
|
wait
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue