-
Notifications
You must be signed in to change notification settings - Fork 0
/
run.sh
executable file
·67 lines (61 loc) · 2.03 KB
/
run.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
SECONDS=0
GAME_MODE=${1:-play}
IP_ADDRESS=${2:-127.0.0.1}
DURATION=${3:-18000}
P1_STRATEGY=${4:-cpp-cgdk/versions/CesistaStrategy_v47}
P2_STRATEGY=${5:-cpp-cgdk/build/MyStrategy}
P1_NAME=${6:-"Cesista's Strategy"}
P2_NAME=${7:-"Current Strategy"}
P1_PORT=${8:-31001}
P2_PORT=${9:-31002}
P1_KEY=${10:-0000000000000000}
P2_KEY=${11:-0000000000000000}
echo $GAME_MODE
if [[ $GAME_MODE == "auto" ]]
then
codeball2018-linux/codeball2018 --p1-name "$P1_NAME" --p2-name "$P2_NAME" \
--p1 tcp-$P1_PORT --p2 tcp-$P2_PORT --results-file results/run_result.txt \
--duration $DURATION --no-countdown --nitro true &
sleep 1; $P1_STRATEGY $IP_ADDRESS $P1_PORT $P1_KEY &
sleep 1; $P2_STRATEGY $IP_ADDRESS $P2_PORT $P2_KEY
elif [[ $GAME_MODE == "play" ]]
then
codeball2018-linux/codeball2018 --p1-name "Player" --p2-name "$P1_NAME" \
--p1 keyboard --p2 tcp-$P1_PORT --results-file results/run_result.txt \
--duration $DURATION --nitro true &
sleep 1; $P1_STRATEGY $IP_ADDRESS $P1_PORT $P1_KEY
elif [[ $GAME_MODE == "helper" ]]
then
codeball2018-linux/codeball2018 --p1-name "Player" --p2-name "Helper" \
--p1 keyboard --p2 helper --results-file results/run_result.txt \
--duration $DURATION --nitro true
elif [[ $GAME_MODE == "empty" ]]
then
codeball2018-linux/codeball2018 --p1-name "Player" --p2-name "" \
--p1 keyboard --p2 empty --results-file results/run_result.txt \
--duration $DURATION --nitro true
else
echo "ERROR: Invalid game mode!"
exit 1
fi
wait
echo DONE!
echo "RESULTS:"
readarray -t RESFILE < codeball2018-linux/results/run_result.txt
IFS=':' read -ra P1_res <<< "${RESFILE[0]}"
IFS=':' read -ra P2_res <<< "${RESFILE[1]}"
let P1_scores=$((0 + P1_res[1]))
let P2_scores=$((0 + P2_res[1]))
if ((${RESFILE[0]:0:1} == "1" && ${RESFILE[1]:0:1} == "2"))
then
echo "$P1_NAME WINS!"
elif ((${RESFILE[0]:0:1} == "2" && ${RESFILE[1]:0:1} == "1"))
then
echo "$P2_NAME WINS!"
else
echo "DRAW!"
fi
echo "SCORES: $P1_NAME $P1_scores - $P2_NAME $P2_scores"
echo "time taken: $SECONDS secs"
# Cleanup
rm -- codeball2018-linux/results/run_result.txt