-
Notifications
You must be signed in to change notification settings - Fork 3
/
run_werewolf.zsh
executable file
·117 lines (106 loc) · 2.46 KB
/
run_werewolf.zsh
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
set -ex
trap "exit" INT TERM
trap 'jobs -p | xargs -r kill' EXIT
cargo build --example bin-werewolf --release
BIN=./target/release/examples/bin-werewolf
PROCS=()
mode=$1
players=3
case $mode in
init)
for i in $(seq 0 $((players - 1))); do
mkdir -p ./werewolf_game/$i
done
RUST_BACKTRACE=1 $BIN init --num-players $players
wait
for i in $(seq 0 $((players - 1))); do
mkdir -p ./werewolf_game/$i
if [ $i == 0 ]; then
RUST_BACKTRACE=1 $BIN preprocessing $i ./data/3 &
pid=$!
PROCS[$i]=$pid
else
$BIN preprocessing $i ./data/3 >/dev/null &
pid=$!
PROCS[$i]=$pid
fi
done
for pid in ${PROCS[@]}; do
wait $pid
done
;;
night)
if [ ! -f "./werewolf_game/public.json" ]; then
echo "not found public.json"
exit 1
fi
for i in $(seq 0 $((players - 1))); do
if [ $i == 0 ]; then
RUST_BACKTRACE=1 $BIN night --target 1 $i ./data/3 &
pid=$!
PROCS[$i]=$pid
else
$BIN night $i ./data/3 >/dev/null &
pid=$!
PROCS[$i]=$pid
fi
done
for pid in ${PROCS[@]}; do
wait $pid
done
;;
role_assignment)
for i in $(seq 0 $((players - 1))); do
if [ $i == 0 ]; then
RUST_BACKTRACE=1 $BIN role_assignment $i ./data/3 &
pid=$!
PROCS[$i]=$pid
else
$BIN role_assignment $i ./data/3 >/dev/null &
pid=$!
PROCS[$i]=$pid
fi
done
for pid in ${PROCS[@]}; do
wait $pid
done
;;
vote)
for i in $(seq 0 $((players - 1))); do
if [ $i == 0 ]; then
RUST_BACKTRACE=1 $BIN vote $i ./data/3 &
pid=$!
PROCS[$i]=$pid
else
$BIN vote $i ./data/3 >/dev/null &
pid=$!
PROCS[$i]=$pid
fi
done
for pid in ${PROCS[@]}; do
wait $pid
done
;;
judgment)
for i in $(seq 0 $((players - 1))); do
if [ $i == 0 ]; then
RUST_BACKTRACE=1 $BIN judgment $i ./data/3 &
pid=$!
PROCS[$i]=$pid
else
$BIN judgment $i ./data/3 >/dev/null &
pid=$!
PROCS[$i]=$pid
fi
done
for pid in ${PROCS[@]}; do
wait $pid
done
;;
*)
echo "invalid mode: $mode"
echo "Usage: $0 [init|mode]"
exit 1
;;
esac
echo done