class World {
void DFS(int depth) const {
size_t hash = calcHash();
if (!hashes.insert(hash).second) // we have already seen this state
return;
if (we are already working more than 90ms since the start of the step)
throw TLException();
if (depth == 0) {
int score = calcScore();
if (score > bestScore) {
bestScore = score;
bestActions = currentActions;
}
return;
}
for (const Action& action : all valid actions) {
World w = *this;
w.performAction(action);
w.DFS(depth - 1);
}
}
};
int main() {
...
vector<Action> actions;
try {
for (int depth=6; ; ++depth) {
DFS(depth);
actions = bestActions;
}
} catch (const TLException&) {}
print out *actions.begin();
}