-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun.sh
More file actions
executable file
·181 lines (153 loc) · 5.77 KB
/
run.sh
File metadata and controls
executable file
·181 lines (153 loc) · 5.77 KB
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
#!/bin/bash
# save argument
ARGC="$#"
ARGV=("$0" "$1" "$2" "$3")
BOT_NAME="$(cat ./Makefile | grep 'TARGET := ' | grep -oE '([a-zA-Z0-9_]+.exe)')"
function error {
echo "usage: "
echo " ./run.sh <command> [ bot_race [ other_race ] ] "
echo " "
echo "commands: "
echo " single Play against the computer in single player using bots "
echo " you've written. "
echo " versus Bots in the bin directory compete against each other. "
echo " self You will compete directly against the bot you created."
echo " "
echo "options: "
echo " random (default) "
echo " protoss "
echo " terran "
echo " zerg "
echo " "
echo " [bot_race] Select the race of the bot you created. "
echo " [other_race] Select computer/opponent bot/your race. "
echo " "
exit 1
}
function initial {
# no argument
if [ "$ARGC" -lt 1 ]; then
error
fi
# check compiler version
MINGW32_VERSION="$(i686-w64-mingw32-g++ --version | grep -o '..-win32')"
# check installed
if [ -z "$MINGW32_VERSION" ]; then
echo "Check the README.md file:"
echo " Install Mingw-w64 using: `sudo apt install build-essential mingw-w64`."
exit 1
fi
if [ ! -d "./bin" ]; then
mkdir bin
fi
# check runtime library: libstdc++-6.dll
if [ ! -f "./bin/libstdc++-6.dll" ]; then
cp "/usr/lib/gcc/i686-w64-mingw32/$MINGW32_VERSION/libstdc++-6.dll" "./bin/"
fi
# check runtime library: libgcc_s_dw2-1.dll
if [ ! -f "./bin/libgcc_s_dw2-1.dll" ]; then
cp "/usr/lib/gcc/i686-w64-mingw32/$MINGW32_VERSION/libgcc_s_dw2-1.dll" "./bin/"
fi
# compile replacer
if [ ! -f "./tools/repl" ]; then
g++ -Wall -Wextra -Werror --std=c++20 -O2 -o ./tools/repl ./tools/replacer/replacer.cpp
fi
# copy default bwapi.ini
cp -rf ./tools/bwapi.ini ./starcraft/bwapi-data/bwapi.ini
}
# correction character cases in word
function correction {
if [ "$#" -ne 1 ]; then
echo "invalid argument: correction <word>"
return 1
fi
local word="$1"
local prefix="$(echo ${word:0:1} | tr 'a-z' 'A-Z')"
local suffix="$(echo ${word:1} | tr 'A-Z' 'a-z')"
echo "$prefix$suffix"
}
# edit options in bwapi.ini
function replace {
if [ "$#" -lt 1 ]; then
echo "invalid argument: replace '<variable> = <value>' [ ... ]"
return 1
fi
./tools/repl "$@" < ./starcraft/bwapi-data/bwapi.ini > ./starcraft/bwapi-data/bwapi.ini.new
rm ./starcraft/bwapi-data/bwapi.ini
mv ./starcraft/bwapi-data/bwapi.ini.new ./starcraft/bwapi-data/bwapi.ini
}
function single_mode {
if [ "$ARGC" -ge 2 ]; then
replace "race = $(correction ${ARGV[2]})"
fi
if [ "$ARGC" -ge 3 ]; then
replace "enemy_race = $(correction ${ARGV[3]})"
fi
wine cmd /c ./tools/run_bot.bat "./bin/$BOT_NAME"
wine cmd /c ./tools/run_scbw.bat
}
function versus_mode {
local bot_list="$(ls -al bin | grep '.exe' | grep -oE '([a-zA-Z0-9_]+.exe)')"
local old_ifs="$IFS"
IFS="
"
local i=0
for bot in $bot_list; do
BOTS[$i]="$bot";
i=$(expr "$i" + 1)
done
IFS="$old_ifs"
if [[ "${#BOTS[@]}" -lt 1 || "${#BOTS[@]}" -gt 2 ]]; then
echo "versus mode: "
echo " ./bin/*.exe There should be one or two bot executables in the "
echo " ./bin/ directory. "
echo " "
exit 1
fi
local other_bot="${BOTS[0]}"
if [ "${#BOTS[@]}" -eq 2 ]; then
if [ "$BOT_NAME" = "${BOTS[0]}" ]; then
other_bot="${BOTS[1]}"
fi
fi
replace "auto_menu = LAN"
if [ "$ARGC" -ge 2 ]; then
replace "race = $(correction ${ARGV[2]})"
fi
wine cmd /c ./tools/run_bot.bat "./bin/$BOT_NAME"
wine cmd /c ./tools/run_scbw.bat
sleep 3
local other_race="Random"
if [ "$ARGC" -ge 3 ]; then
other_race="$(correction ${ARGV[3]})"
fi
replace "race = $other_race" "character_name = other-bot" "game = JOIN_FIRST"
wine cmd /c ./tools/run_bot.bat "./bin/$other_bot"
wine cmd /c ./tools/run_scbw.bat
}
function self_mode {
replace "auto_menu = LAN" "sound = OFF"
if [ "$ARGC" -ge 2 ]; then
replace "race = $(correction ${ARGV[2]})"
fi
wine cmd /c ./tools/run_bot.bat "./bin/$BOT_NAME"
wine cmd /c ./tools/run_scbw.bat
sleep 3
local other_race="Random"
if [ "$ARGC" -ge 3 ]; then
other_race="$(correction ${ARGV[3]})"
fi
replace "race = $other_race" "character_name = player" "game = JOIN_FIRST" "sound = ON"
wine cmd /c ./tools/run_scbw.bat
}
########## begin process ##########
initial
if [ "${ARGV[1]}" = "single" ]; then
single_mode
elif [ "${ARGV[1]}" = "versus" ]; then
versus_mode
elif [ "${ARGV[1]}" = "self" ]; then
self_mode
else # wrong argument
error
fi