Skip to content

Commit 76f7637

Browse files
committed
Provide error message and exit() if game environment is launched with incomplete or bad command line args. Also, if map dimensions are unspecified, randomly choose dimensions from same distribution as used by the Halite servers.
1 parent 99229ac commit 76f7637

File tree

1 file changed

+11
-73
lines changed

1 file changed

+11
-73
lines changed

environment/main.cpp

Lines changed: 11 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -75,13 +75,15 @@ int main(int argc, char ** argv) {
7575
}
7676

7777
if(mapWidth == 0 && mapHeight == 0) {
78-
promptDimensions(mapWidth, mapHeight);
78+
std::vector<unsigned short> mapSizeChoices = {20, 25, 25, 30, 30, 30, 35, 35, 35, 35, 40, 40, 40, 45, 45, 50};
79+
mapWidth = mapSizeChoices[rand() % mapSizeChoices.size()];
80+
mapHeight = mapWidth;
7981
}
8082

8183
if(override_names) {
8284
if(unlabeledArgs.size() < 4 || unlabeledArgs.size() % 2 != 0) {
83-
std::cout << "Invalid player parameters from argv. Prompting instead (override disabled):" << std::endl;
84-
networking = promptNetworking();
85+
std::cout << "Invalid number of player parameters with override switch enabled. Override intended for server use only." << std::endl;
86+
exit(1);
8587
}
8688
else {
8789
try {
@@ -94,17 +96,17 @@ int main(int argc, char ** argv) {
9496
}
9597
}
9698
catch(...) {
97-
std::cout << "Invalid player parameters from argv. Prompting instead (override disabled):" << std::endl;
98-
networking = promptNetworking();
99+
std::cout << "Invalid player parameters with override switch enabled. Override intended for server use only." << std::endl;
99100
delete names;
100101
names = NULL;
102+
exit(1);
101103
}
102104
}
103105
}
104106
else {
105107
if(unlabeledArgs.size() < 1) {
106-
std::cout << "Invalid player parameters from argv. Prompting instead:" << std::endl;
107-
networking = promptNetworking();
108+
std::cout << "Please provide the launch command string for at least one bot." << std::endl;
109+
exit(1);
108110
}
109111
try {
110112
while(!unlabeledArgs.empty()) {
@@ -114,8 +116,8 @@ int main(int argc, char ** argv) {
114116
}
115117
}
116118
catch(...) {
117-
std::cout << "Invalid player parameters from argv. Prompting instead:" << std::endl;
118-
networking = promptNetworking();
119+
std::cout << "One or more of your bot launch command strings failed. Please check for correctness and try again." << std::endl;
120+
exit(1);
119121
}
120122
}
121123

@@ -137,67 +139,3 @@ int main(int argc, char ** argv) {
137139

138140
return 0;
139141
}
140-
141-
Networking promptNetworking() {
142-
Networking n;
143-
std::string in;
144-
bool done = false;
145-
for(int np = 0; !done; np++) {
146-
//If less than 2, bypass this step: Ask if the user like to add another AI
147-
if (np >= 1) {
148-
std::cout << "Would you like to add another player? Please enter Yes or No: ";
149-
while (true) {
150-
std::getline(std::cin, in);
151-
std::transform(in.begin(), in.end(), in.begin(), ::tolower);
152-
if (in == "n" || in == "no" || in == "nope" || in == "y" || in == "yes" || in == "yep") break;
153-
std::cout << "That isn't a valid input. Please enter Yes or No: ";
154-
}
155-
if (in == "n" || in == "no" || in == "nope") break;
156-
}
157-
158-
while (true) {
159-
std::string startCommand;
160-
std::cout << "What is the start command for this bot: ";
161-
std::getline(std::cin, startCommand);
162-
163-
try{
164-
n.startAndConnectBot(startCommand);
165-
break;
166-
}
167-
catch (int e) {
168-
std::cout << "There was a problem with that start command. Please enter another one.\n";
169-
}
170-
}
171-
172-
std::cout << "Connected to player #" << int(np + 1) << std::endl;
173-
}
174-
return n;
175-
}
176-
177-
void promptDimensions(unsigned short & w, unsigned short & h) {
178-
std::string in;
179-
std::cout << "Please enter the width of the map: ";
180-
std::getline(std::cin, in);
181-
while(true) {
182-
try{
183-
w = std::stoi(in);
184-
break;
185-
}
186-
catch(std::exception e) {
187-
std::cout << "That isn't a valid input. Please enter a positive integer width of the map: ";
188-
std::getline(std::cin, in);
189-
}
190-
}
191-
std::cout << "Please enter the height of the map: ";
192-
std::getline(std::cin, in);
193-
while(true) {
194-
try{
195-
h = std::stoi(in);
196-
break;
197-
}
198-
catch(std::exception e) {
199-
std::cout << "That isn't a valid input. Please enter a positive integer height of the map: ";
200-
std::getline(std::cin, in);
201-
}
202-
}
203-
}

0 commit comments

Comments
 (0)