moved mc_player::step(game_state& currentState) { list<moved> actions = GameGetLegalMoves(currentState); if (actions.size() == 0) return moved::SE; moved action = actions.front(); if (actions.size() == 1) return action; vector<moved> vactions(begin(actions), end(actions)); auto startTime = system_clock::now(); auto finishBy = startTime + duration<int, milli>(400); vector<double> totalPoints(vactions.size()); vector<int> totalAttempts(vactions.size()); for (int i = 0; true; i = (i + 1) % vactions.size()) { if (system_clock::now() > finishBy) break; double score = depth_charge_random(GameGetNextState(currentState, vactions[i])); totalPoints[i] += score; if ((totalAttempts[i] += 1) > 1000) break; } vector<double> expectedPoints(vactions.size()); for (int i = 0; i < vactions.size(); i++) expectedPoints[i] = totalPoints[i] / totalAttempts[i]; int best = 0; double bestScore = expectedPoints[0]; for (int i = 1; i < vactions.size(); i++) { double score = expectedPoints[i]; if (score > bestScore) { bestScore = score; best = i; } } return vactions[best]; }
float Vuur::_fraction() { return (float)totalPoints() / (float)maxPoints; }