: # intimate: bourne shell script to help run Intimate Diplomacy games. # #---------------------------------------------------------------------- standard_power() { power=unknown reserve=0 case $1 in a* | A* ) power=Austria; reserve=21 ;; e* | E* ) power=England reserve=17 ;; f* | F* ) power=France; reserve=17 ;; g* | G* ) power=Germany; reserve=19 ;; i* | I* ) power=Italy; reserve=21 ;; r* | R* ) power=Russia; reserve=16 ;; t* | T* ) power=Turkey; reserve=17 ;; esac if [ "a$CarryOver" = "anoCarryOver" ]; then reserve=0; fi } #---------------------------------------------------------------------- process_usage() { cat << eoprocess Usage: intimate [-r] [-s] game game is the name of a game previously created with the -n option. The -r flag indicates that the preceding season should be reprocessed. The -s flag indicates that the game is in a stalemate condition. eoprocess } #---------------------------------------------------------------------- create_usage() { cat << eocreate Usage: $0 [-d] -n game judge password power1 power2 The -d flag specifies duel-dip rules (default is intimate). game is the name of the game (1-8 alpha-numeric characters). judge is the e-mail address of the judge on which the game is run. power1/2 is the name of one of the seven Diplomacy powers (Austria, England, France, Italy, Germany, Russia, or Turkey). The power name may be in upper or lower case, and may be abbreviated to the first character. power1 may not be the same as power2. eocreate } # #---------------------------------------------------------------------- # create_game() { # if we don't have the right number of arguments, display a message and exit if [ "a$5" = "a" ]; then echo "Not enough arguments" create_usage exit 1 fi game=$1 judge=$2 password=$3 # convert the powers to standard strings, and get their starting reserves standard_power $4 power1=$power reserve1=$reserve standard_power $5 power2=$power reserve2=$reserve # if unknown power unknown="n" if [ "$power1" = "unknown" ]; then unknown=1 fi if [ "$power2" = "unknown" ]; then unknown=2 fi if [ "$unknown" != "n" ]; then echo "Power $unknown not recognized" create_usage exit 1 fi # if the powers aren't different if [ "$power1" = "$power2" ]; then echo "Use two different powers." create_usage exit 1 fi # already got one? if [ -d $game ]; then echo "$game already exists. Choose a different game name" exit 1 fi # create the directories gameDir=$game/1901/spring mkdir $game mkdir $game/1901 mkdir $gameDir if [ ! -d $gameDir ]; then echo "Couldn't create $gameDir." exit 1 fi touch $gameDir/$bfname # create the master file pass1=`date +%M$power1%S` cat <$game/$mfname GAME $game JUDGE $judge PASSWORD $password YEAR 1901 SEASON thaw $CarryOver $OverBidding IncomeType $IncomeType Income $Income NonMovement $NonMovement Retreat $Retreat VictoryCond $VictoryCond eomfile # create the game file sleep 1; pass2=`date +%S$power2%M` cat <$gameDir/$gfname POWER $power1 $pass1 $reserve1 POWER $power2 $pass2 $reserve2 eogamefile # create the game centers=18 if [ "$VictoryCond" = "Intimate" ]; then centers=34 fi cat << eom | dipmail $judge $game create ?$game $password become master set players 1 set proxy set comment 2-player Diplomacy: $victoryCond set normal press set access any set centers $centers set level any eom } # #---------------------------------------------------------------------- # process_game() { # check argument if [ "a$1" = "a" ]; then process_usage exit 1 fi # get game name and check if the game exists game=$1 if [ ! -d $game ]; then echo "Can not find $game"; process_usage exit 1 fi againFile=$game/$afname if [ ! -f $game/$mfname ]; then echo "Can not find $mfname" exit 2 fi # if stalemate, append that fact to master file if [ "a$stalemate" != "afalse" ]; then echo "STALEMATE" >> $game/$mfname fi # get year/season year=`nawk '/^YEAR/ { print $2; }' $game/$mfname` season=`nawk '/^SEASON/ { print $2; }' $game/$mfname` # check for repeat if [ -f $againFile ]; then rm $againFile fi if [ "a$again" != "afalse" ]; then case $season in thaw ) season="fall" ; year=`expr $year - 1` ;; spring ) season="thaw" ;; fall ) season="spring" ;; * ) echo "OOPS! Unknown season: $season" ; exit 3 ;; esac echo "YEAR $year" >> $againFile echo "SEASON $season" >> $againFile fi newYear=$year oldDir=$game/$year/$season case $season in thaw ) oldDir=$game/$year/spring ; newDir=$game/$year/spring ;; spring ) newDir=$game/$year/fall ;; fall ) newYear=`expr $year + 1` ; newDir=$game/$newYear/spring ;; * ) echo "OOPS! Unknown season: $season" ; exit 3 ;; esac # check for existance of required files if [ ! -f $oldDir/$gfname ]; then echo "Missing $oldDir/$gfname" exit 1 fi # create next season's dir(s) if [ ! -d $game/$newYear ]; then mkdir $game/$newYear fi if [ ! -d $newDir ]; then mkdir $newDir fi touch $newDir/$bfname touch $againFile # concat all the files, and turn loose the nawk. cat $game/$mfname $oldDir/$gfname $oldDir/$jfname $oldDir/$bfname \ $againFile | $0.nawk # execute the adjudicator commands sh $oldDir/commands } checkArgs() { if [ "a$1" = "a" ]; then echo $2 process_usage echo " " echo "-or-" create_usage exit 1 fi } # #====================================================================== # afname=again.file mfname=master.file gfname=game.file bfname=bid.file jfname=judge.list again="false" stalemate="false" CarryOver=CarryOver OverBidding=OverBidding IncomeType=Rent Income=1 NonMovement=Ordered Retreat=NMR VictoryCond=Intimate checkArgs "$1" if [ "a$1" = "a-d" ]; then CarryOver=noCarryOver OverBidding=noOverBidding IncomeType=Fixed Income=12 ### NonMovement=NMR NonMovement=Ordered ### Retreat=Random Retreat=Greedy VictoryCond=Standard shift fi if [ "a$1" = "a-r" ]; then again="true" shift fi if [ "a$1" = "a-s" ]; then stalemate="true" shift fi if [ "a$1" = "a-n" ]; then echo creating... checkArgs "$2" "Missing game name" checkArgs "$3" "Missing judge" checkArgs "$4" "Missing password" checkArgs "$5" "Missing power" create_game $2 $3 $4 $5 $6 else checkArgs "$1" "Missing game name" process_game $1 fi #