Skip to content

Instantly share code, notes, and snippets.

@tscmoo
Created June 7, 2017 19:32
Show Gist options
  • Save tscmoo/724038a645296422b26055b342cdda8d to your computer and use it in GitHub Desktop.
Save tscmoo/724038a645296422b26055b342cdda8d to your computer and use it in GitHub Desktop.
#!/bin/sh
#
# This script plays a 1v1 with the bots and settings specified below.
# It spawns two instances of BWAPILauncher and communicates using pipes.
# No bwapi.ini is necessary; all settings are set using environment variables.
#
bot1="${bot1:-$1}"
race1="${race1:-$2}"
name1="${name1:-$(basename $bot1 .so)}"
bot2="${bot2:-$3}"
race2="${race2:-$4}"
name2="${name2:-$(basename $bot2 .so)}"
map="${map:-${BWAPI_CONFIG_AUTO_MENU__MAP:-$5}}"
launcher=BWAPILauncher
enable_ui="${enable_ui:-${OPENBW_ENABLE_UI:-1}}"
auto_restart="${auto_restart:-0}"
####
fail() {
echo $1
exit
}
check() {
eval tmp="\$$1"
test "$tmp" = "" && fail "required argument $1 not specified"
}
check bot1
check race1
check name1
check bot2
check race2
check name2
check map
test -e "$bot1" || fail "$bot1 does not exist"
test -e "$bot2" || fail "$bot2 does not exist"
pipe1_fn=$(mktemp -u)
pipe2_fn=$(mktemp -u)
mkfifo $pipe1_fn || exit
mkfifo $pipe2_fn || exit
exec 3<>$pipe1_fn
exec 4<>$pipe2_fn
pipe1=3
pipe2=4
rm $pipe1_fn
rm $pipe2_fn
test "$auto_restart" = "0" && auto_restart=OFF
pids=""
ui=$enable_ui
spawn() {
OPENBW_ENABLE_UI=$ui OPENBW_LAN_MODE=FD OPENBW_FD_READ=$pipe1 OPENBW_FD_WRITE=$pipe2 BWAPI_CONFIG_AI__AI="$ai" BWAPI_CONFIG_AUTO_MENU__RACE="$race" BWAPI_CONFIG_AUTO_MENU__CHARACTER_NAME="$name" BWAPI_CONFIG_AUTO_MENU__AUTO_MENU=LAN BWAPI_CONFIG_AUTO_MENU__MAP="$map" BWAPI_CONFIG_AUTO_MENU__GAME_TYPE=MELEE BWAPI_CONFIG_AUTO_MENU__AUTO_RESTART=$auto_restart $launcher &
ui=0
pids="$pids $!"
tmp=$pipe1
pipe1=$pipe2
pipe2=$tmp
}
ai=$bot1 race=$race1 name=$name1 spawn
ai=$bot2 race=$race2 name=$name2 spawn
trap "kill -9 $pids" INT TERM
wait
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment