-
Notifications
You must be signed in to change notification settings - Fork 0
/
run_game.sh
executable file
·100 lines (88 loc) · 2.06 KB
/
run_game.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#!/bin/bash
set -e
trap finish INT
PROGS=()
finish() {
kill -9 ${PROGS[*]}
}
MAP=$1
MODEL=$2
BASE_MODEL=$3
MAX_PLAYERS=2
SEED=$4
declare -A map_to_players
map_to_players["s1"]=1
map_to_players["s3"]=1
map_to_players["d1"]=2
map_to_players["d2"]=2
map_to_players["c1"]=4
map_to_players["c2"]=4
map_to_players["c3"]=6
map_to_players["c1_wo_coop"]=4
map_to_players["c2_wo_coop"]=4
map_to_players["c3_wo_coop"]=6
if [[ -v "map_to_players[$MAP]" ]]; then
MAX_PLAYERS=${map_to_players[$MAP]}
fi
echo "MAX_PLAYERS: $MAX_PLAYERS"
SERVER_CMD="python -m battle_city.server_sync --turn-off-after-end --hidden-window --map $MAP --seed $SEED"
CMD_A="python -m battle_city.examples.client --sync --model $MODEL"
CMD_B="python -m battle_city.examples.client --sync --model $BASE_MODEL"
CMDS=(- "$CMD_A" "$CMD_B" "$CMD_B" "$CMD_B" "$CMD_B" "$CMD_B")
# decide CMDS acoording to MAP, s1, s3; d1, d2; c1, c2, c3
case $MAP in
"s1")
CMDS=(- "$CMD_A")
;;
"s3")
CMDS=(- "$CMD_A")
;;
"d1")
CMDS=(- "$CMD_A" "$CMD_A")
;;
"d2")
CMDS=(- "$CMD_A" "$CMD_B")
;;
"c1")
CMDS=(- "$CMD_A" "$CMD_B" "$CMD_A" "$CMD_B")
;;
"c2")
CMDS=(- "$CMD_A" "$CMD_B" "$CMD_B" "$CMD_B")
;;
"c3")
CMDS=(- "$CMD_A" "$CMD_B" "$CMD_B" "$CMD_A" "$CMD_B" "$CMD_B")
;;
"c1_wo_coop")
CMDS=(- "$CMD_A" "$CMD_B" "$CMD_A" "$CMD_B")
;;
"c2_wo_coop")
CMDS=(- "$CMD_A" "$CMD_B" "$CMD_B" "$CMD_B")
;;
"c3_wo_coop")
CMDS=(- "$CMD_A" "$CMD_B" "$CMD_B" "$CMD_A" "$CMD_B" "$CMD_B")
;;
*)
echo "Unknown MAP value: $MAP"
exit 1
;;
esac
# print the cmds array to verify the result
echo "Commands for MAP=$MAP:"
printf '%s\n' "${cmds[@]}"
echo "^C to cancel..."
echo $SERVER_CMD
$SERVER_CMD&
PROGS+=($!)
sleep 1.75
i=1
while [ $i -le $MAX_PLAYERS ]; do
sleep 1.2
echo ${CMDS[$i]}
${CMDS[$i]} | sed "s/^/CLIENT $i: /"&
PROGS+=($!)
((i++))
done
echo pids: $PROGS
for pid in ${PROGS[*]}; do
wait $pid
done