void RTSSearch::search() { // create the initial state GameStateNode g(true, this, data); LOOP_BITS (g.getLegalActions(), action) { printf("%s\n", data->action_strings[action].c_str()); } open_list.push_back(g); int nodes = 0; bool solutionFound = false; int winningFrame = 1000000; GameStateNode * winner; while (true) { if (++nodes % 1000 == 0) printf("Nodes searched: %d\n", nodes); // if we have met the goal, we're good if (g.meetsGoal()) { solutionFound = true; //printf("\n\nGOAL MET!\n\n"); //g.printData(); if (g.currentFrame < winningFrame) { winningFrame = g.currentFrame; winner = &g; g.printData(); } } if (g.currentFrame < winningFrame) { // otherwise, generate the children and add them to the open list // for each of the bits in the bitmask LOOP_BITS(g.getLegalActions(), nextAction) { // copy the current state to a child state GameStateNode child(g); child.parent = &g; // perform the current action child.doAction((ZergData::zerg_action)nextAction); // search the child state open_list.push_back(child); } } if (++search_index < open_list.size()) g = open_list[search_index]; else break; } if (solutionFound) { winner->printData(); } }