Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //--------------minimax pradzia----------------------
- void minimax(vector<Planet> planets, int depth, int &sim)
- {
- int bestMoveScore = 1000;
- Move bestMove;
- for(int i = 0; i < planets.size(); i++){
- if(planets[i].canAssign){
- planets[i].myUnits += 5;
- planets[i].myTolerance--;
- sim++;
- cerr << i << " - ";
- int tempMoveScore = maxSearch(planets, depth+1, sim);
- planets[i].myUnits -= 5;
- for(int j = 0; j < planets[i].near.size(); j++){
- int x = planets[i].near[j];
- planets[x].myUnits++;
- }
- int tempMoveScoreSpread = maxSearch(planets, depth+1, sim);
- cerr << tempMoveScore << " " << tempMoveScoreSpread << endl;
- if(tempMoveScore <= bestMoveScore){
- bestMoveScore = tempMoveScore;
- bestMove.target = i;
- }
- if(tempMoveScoreSpread >= bestMoveScore){
- bestMoveScore = tempMoveScoreSpread;
- bestMove.target = i;
- bestMove.spread = to_string(i);
- }
- planets[i].myTolerance++;
- for(int j = 0; j < planets[i].near.size(); j++){
- int x = planets[i].near[j];
- planets[x].myUnits--;
- }
- }
- }
- for(int i = 0; i < 5; i++){
- cout << bestMove.target << endl;
- }
- cout << bestMove.spread << endl;
- }
- //----------minimax max reiksme----------------------
- int maxSearch(vector<Planet> planets, int depth, int &sim)
- {
- if((clock()-t0)/1000 > 40 || depth >= Depth) return score(planets);
- Move bestMove;
- int bestMoveScore = -1000;
- for(int i = 0; i < planets.size(); i++){
- if(enemyAssign(planets, i)){
- planets[i].otherUnits += 5;
- planets[i].otherTolerance--;
- sim++;
- //cerr << " E " << i ;
- calculateMove(planets);
- int tempMoveScore = minSearch(planets, depth+1, sim);
- if(tempMoveScore >= bestMoveScore){
- bestMoveScore = tempMoveScore;
- bestMove.target = i;
- }
- planets[i].otherUnits -= 5;
- planets[i].otherTolerance++;
- }
- }
- return bestMoveScore;
- }
- //------------minimax min reiksme----------------------
- int minSearch(vector<Planet> planets, int depth, int &sim)
- {
- if((clock()-t0)/1000 > 40 || depth >= Depth) return score(planets);
- Move bestMove;
- int bestMoveScore = 1000;
- for(int i = 0; i < planets.size(); i++){
- if(myAssign(planets,i)){
- planets[i].myUnits += 5;
- planets[i].myTolerance--;
- sim++;
- //cerr << " M " << i;
- int tempMoveScore = maxSearch(planets, depth+1, sim);
- if(tempMoveScore <= bestMoveScore){
- bestMoveScore = tempMoveScore;
- bestMove.target = i;
- }
- planets[i].myUnits -= 5;
- planets[i].myTolerance++;
- }
- }
- return bestMoveScore;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement