• R/O
  • SSH
  • HTTPS

rc-oz: Commit


Commit MetaInfo

Revision77 (tree)
Time2009-05-18 16:00:10
Authorozkubo

Log Message

add 3DSpark support.

Change Summary

Incremental Difference

--- rclm2/base/trunk/share/rclm2/types/3DSpark/local_func.bash (nonexistent)
+++ rclm2/base/trunk/share/rclm2/types/3DSpark/local_func.bash (revision 77)
@@ -0,0 +1,164 @@
1+# By Hedayat Vatankhah <hedayat@grad.com>, 2008
2+# Based on 3D local_func.bash
3+
4+# Servers Settings
5+SERVER=172.16.7.194
6+CLIENT1=root@172.16.7.181
7+CLIENT2=root@172.16.7.182
8+
9+# Simspark Settings
10+SERVER_PREFIX_DIR="/usr/local/"
11+SOCCERSIM_CONF=naosoccersim.rb
12+TOTAL_GAME_TIME=600
13+
14+ARCHIVE_DIR=archives
15+RESULTPRINTER="${PREFIX}/bin/rclmresultprinter.3d"
16+RESULTFILE=./var/results
17+HALF_TIME=$((TOTAL_GAME_TIME/2))
18+
19+# load user setting.
20+#[ -f ${RCLM_USER_DIR}/3DSpark ] && source ${RCLM_USER_DIR}/3DSpark ]
21+test -f ./var/3DSpark ] && source ./var/3DSpark
22+
23+function _countdown {
24+ countdown $1 $2
25+}
26+
27+## __before_match(team1, team2)
28+function __before_match {
29+ rm -f sparkmonitor.log
30+ echo 0 > gametime
31+ rm -f scoresswitched
32+ cp $SERVER_PREFIX_DIR/share/rcssserver3d/$SOCCERSIM_CONF .
33+ return 0
34+}
35+
36+## __run_match(team1, team2)
37+function __run_match {
38+ local TEAM1=$1
39+ local TEAM2=$2
40+
41+ echo "$TEAM1 vs $TEAM2"
42+
43+ NAME1=${TEAM1#*:}
44+ NAME2=${TEAM2#*:}
45+ DIR1=${TEAM1%:*}
46+ DIR2=${TEAM2%:*}
47+
48+
49+ simspark &> console.log &
50+ PID=$!
51+ sleep 2
52+
53+ ssh ${CLIENT1} "su - $NAME1 -c './start.sh $SERVER &> play.log'" &
54+
55+ sleep 5
56+ ssh ${CLIENT2} "su - $NAME2 -c './start.sh $SERVER &> play.log'" &
57+
58+ wait $PID
59+
60+ _countdown 5 ': if you want to stop league(CANCEL THIS GAME), press Ctrl+C.'
61+ return 0
62+}
63+
64+## __after_match(team1, team2)
65+function __after_match {
66+ local TEAM1=$1
67+ local TEAM2=$2
68+
69+ NAME1=${TEAM1#*:}
70+ NAME2=${TEAM2#*:}
71+ DIR1=${TEAM1%:*}
72+ DIR2=${TEAM2%:*}
73+
74+ ssh ${CLIENT1} "su - $NAME1 -c './kill.sh &> kill.log'" &
75+
76+ sleep 1
77+ ssh ${CLIENT2} "su - $NAME2 -c './kill.sh &> kill.log'" &
78+
79+ GAMEDATE=`date +%Y%m%d%H%M`
80+ [ -d ${ARCHIVE_DIR} ] || mkdir ${ARCHIVE_DIR}
81+ local GAME=`${RESULTPRINTER} sparkmonitor.log`
82+
83+ LOGNAME="${GAMEDATE}_${NAME1}_vs_${NAME2}"
84+ if [ -n "${GAME}" ]; then
85+ echo $GAME >> ${RESULTFILE}
86+ set ${GAME}
87+ LOGNAME="${GAMEDATE}_$1_$3_vs_$2_$4"
88+ SCORE_LEFT=$3
89+ SCORE_RIGHT=$4
90+ fi
91+
92+ GAME_TIME=`tail -n1 sparkmonitor.log | sed "s/.*time \([0-9]*\).*/\1/"`
93+
94+ LOGDIR="archives/${LOGNAME}"
95+ mkdir $LOGDIR
96+ mv {sparkmonitor,console}.log $LOGDIR
97+
98+ # Check to see if the game was complete
99+# TOTAL_PLAYED=$((GAME_TIME+`cat gametime`))
100+ TOTAL_PLAYED=$GAME_TIME
101+ if [ $TOTAL_PLAYED -lt $TOTAL_GAME_TIME ]; then
102+ echo $TOTAL_PLAYED > gametime
103+ echo "Game finished at time(rounded): $GAME_TIME"
104+ echo "Total played time is: $TOTAL_PLAYED"
105+ echo "Total game time is: $TOTAL_GAME_TIME"
106+ echo -n "Run complementary match? [y/N]:"
107+ read ans
108+ case $ans in
109+ [yY]*)
110+ _countdown 15 ": wait complementary match."
111+# sed -i "s/addSoccerVar('RuleHalfTime',.*)/addSoccerVar('RuleHalfTime',$TOTAL_GAME_TIME - $TOTAL_PLAYED)/" $SOCCERSIM_CONF
112+ sed -i "s/setTime(.*)/setTime($TOTAL_PLAYED)/" $SOCCERSIM_CONF
113+ if [ ! $TOTAL_PLAYED -lt $HALF_TIME ] && [ ! -f scoresswitched ]; then
114+ sed -i "s/setScores(.*)/setScores($SCORE_RIGHT,$SCORE_LEFT)/" $SOCCERSIM_CONF
115+ else
116+ sed -i "s/setScores(.*)/setScores($SCORE_LEFT,$SCORE_RIGHT)/" $SOCCERSIM_CONF
117+ fi
118+
119+ if [ $TOTAL_PLAYED -lt $HALF_TIME ] || [ -f scoresswitched ]; then
120+ __run_match $TEAM1 $TEAM2
121+ __after_match $TEAM1 $TEAM2
122+ else
123+ touch scoresswitched
124+ __run_match $TEAM2 $TEAM1
125+ __after_match $TEAM2 $TEAM1
126+ fi
127+ return 0
128+ ;;
129+ esac
130+ fi
131+
132+ TIE=""
133+ if [ -z "${GAME}" ]; then
134+ echo -n "Tie game? [y/N]:"
135+ read ans
136+ case $ans in
137+ [yY]*)
138+ TIE=y
139+ ;;
140+ esac
141+ else
142+ set ${GAME}
143+ echo
144+ [ "x$3" = "x$4" ] && TIE=y
145+ fi
146+ if [ "x$TIE" = 'xy' ]; then
147+ echo -n "Tie break, Run match again? [y/N]:"
148+ read ans
149+ case $ans in
150+ [yY]*)
151+ _countdown 15 ": wait extend match."
152+ __run_match $TEAM1 $TEAM2
153+ __after_match $TEAM1 $TEAM2
154+ ;;
155+ esac
156+ fi
157+ rm gametime
158+ return 0
159+}
160+
161+## __wait_next_match
162+function __wait_next_match {
163+ _countdown 15 ': wait next match.'
164+}
--- rclm2/base/trunk/share/rclm2/Makefile.am (revision 76)
+++ rclm2/base/trunk/share/rclm2/Makefile.am (revision 77)
@@ -80,6 +80,15 @@
8080 types/2D_Tournament/start \
8181 types/2D_Tournament/stop
8282
83+rclmtype_3DSparkdir=$(pkgdatadir)/types/3DSpark
84+rclmtype_3DSpark_SCRIPTS= \
85+ types/3DSpark/local_func.bash \
86+ types/3DSpark/clearup \
87+ types/3DSpark/record \
88+ types/3DSpark/setup \
89+ types/3DSpark/start \
90+ types/3DSpark/stop
91+
8392 # rclm2 roundrobin scheduler scripts
8493 rclmschedulers_roundrobindir=$(pkgdatadir)/schedulers/roundrobin
8594 rclmschedulers_roundrobin_SCRIPTS= \
@@ -139,6 +148,12 @@
139148 types/2D_Tournament/setup \
140149 types/2D_Tournament/start \
141150 types/2D_Tournament/stop \
151+ types/3DSpark/local_func.bash \
152+ types/3DSpark/clearup \
153+ types/3DSpark/record \
154+ types/3DSpark/setup \
155+ types/3DSpark/start \
156+ types/3DSpark/stop \
142157 schedulers/roundrobin/init \
143158 schedulers/roundrobin/update \
144159 schedulers/tournament/init \
Show on old repository browser