Guest User

Untitled

a guest
Jan 19th, 2016
196
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 30.52 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. #define rep(i, a, b) for(int i = (a); i < int(b); ++i)
  6. #define rrep(i, a, b) for(int i = (a) - 1; i >= int(b); --i)
  7. #define trav(it, v) for(typeof((v).begin()) it = (v).begin(); it != (v).end(); ++it)
  8. #define all(v) (v).begin(), (v).end()
  9.  
  10. typedef double fl;
  11. typedef long long ll;
  12. typedef pair<int, int> pii;
  13. typedef vector<int> vi;
  14. typedef vector<pii> vpi;
  15. typedef pair<ll, pair<ll, ll> > hashType;
  16.  
  17. clock_t startTime;
  18. bool aborted;
  19. int statesDone;
  20. int checkTime;
  21. int DX[8]={-1,-1,-1,0,1,1,1,0}, DY[8]={-1,0,1,1,1,0,-1,-1};
  22. int bufdis[2][10][10];
  23. int bufdis2[2][10][10];
  24. int bufneigh[10][10];
  25. float squareScore[10][10];
  26. int bufx[100];
  27. int bufy[100];
  28. float coeff;
  29. bool lateGame;
  30.  
  31. struct Bot{
  32.     bool useAlphaBeta;
  33.     bool useIterativeDeepening;
  34.     bool useMobilityEval;
  35.     bool useWeirdMobility;
  36.     bool useDistanceEval;
  37.     bool useExtraDistanceEval;
  38.     bool useTranspositionTable;
  39.     bool useKiller;
  40.     bool useHistory;
  41.     bool useFullHistory;
  42.     bool useLateGameEval;
  43.     bool updateCoeff;
  44.     //bool restrictMoves;
  45.     string name;
  46.     float eFilled0;
  47.     float eFilled1;
  48.     float eFilled2;
  49.     float eFilled3;
  50.     float eScore1_1;
  51.     float eScore1_2;
  52.     float eScore1_3;
  53.     float eScore1_4;
  54.     float eScore2_1;
  55.     float eScore2_2;
  56.     float eScore2_3;
  57.     float eScore2_4;
  58.     float eScore2_5;
  59.     float eScore2_6;
  60.     float eCoeffMax;
  61.     float eMobilityWeight;
  62.     float eMobilityFactor;
  63.     float timeLimit;
  64.  
  65.     Bot(){}
  66.  
  67.     Bot(string _name){
  68.         timeLimit=0.85;
  69.         name = _name;
  70.         useAlphaBeta = true;
  71.         useIterativeDeepening = true;
  72.         useWeirdMobility = false;
  73.         useMobilityEval = true;
  74.         useDistanceEval = false;
  75.         useExtraDistanceEval = false;
  76.         useTranspositionTable = false;
  77.         useLateGameEval = false;
  78.         useKiller = false;
  79.         useHistory = false;
  80.         updateCoeff = true;
  81.         /*eFilled0=1;
  82.         eFilled1=0.5;
  83.         eFilled2=0.3;
  84.         eFilled3=0.1;
  85.         eScore1_1=60;
  86.         eScore1_2=80;
  87.         eScore1_3=90;
  88.         eScore1_4=100;
  89.         eScore2_1=24;
  90.         eScore2_2=40;
  91.         eScore2_3=60;
  92.         eScore2_4=80;
  93.         eScore2_5=90;
  94.         eScore2_6=100;
  95.         eCoeffMax=70;*/
  96.         eFilled0=0.98;
  97.         eFilled1=0.51;
  98.         eFilled2=0.29;
  99.         eFilled3=0.09;
  100.         eScore1_1=62;
  101.         eScore1_2=82;
  102.         eScore1_3=90;
  103.         eScore1_4=96;
  104.         eScore2_1=20;
  105.         eScore2_2=40;
  106.         eScore2_3=60;
  107.         eScore2_4=80;
  108.         eScore2_5=90;
  109.         eScore2_6=100;
  110.         eCoeffMax=72;
  111.         eMobilityWeight=1000;
  112.         eMobilityFactor=0.1;
  113.         //restrictMoves = false;
  114.     }
  115.  
  116.     void setFinal(){
  117.         eFilled0=0.86;
  118.         eFilled1=0.5;
  119.         eFilled2=0.38;
  120.         eFilled3=0.15;
  121.         eScore1_1=65;
  122.         eScore1_2=72;
  123.         eScore1_3=77;
  124.         eScore1_4=82;
  125.         eScore2_1=14;
  126.         eScore2_2=26;
  127.         eScore2_3=38;
  128.         eScore2_4=52;
  129.         eScore2_5=75;
  130.         eScore2_6=105;
  131.         eCoeffMax=62;
  132.         eMobilityWeight=1000;
  133.         eMobilityFactor=0.095;
  134.     }
  135.    
  136.     void load(string fileName){
  137.         FILE* fin = fopen(fileName.c_str(), "r");
  138.         fscanf(fin, "%f", &eFilled0);
  139.         fscanf(fin, "%f", &eFilled1);
  140.         fscanf(fin, "%f", &eFilled2);
  141.         fscanf(fin, "%f", &eFilled3);
  142.         fscanf(fin, "%f", &eScore1_1);
  143.         fscanf(fin, "%f", &eScore1_2);
  144.         fscanf(fin, "%f", &eScore1_3);
  145.         fscanf(fin, "%f", &eScore1_4);
  146.         fscanf(fin, "%f", &eScore2_1);
  147.         fscanf(fin, "%f", &eScore2_2);
  148.         fscanf(fin, "%f", &eScore2_3);
  149.         fscanf(fin, "%f", &eScore2_4);
  150.         fscanf(fin, "%f", &eScore2_5);
  151.         fscanf(fin, "%f", &eScore2_6);
  152.         fscanf(fin, "%f", &eCoeffMax);
  153.         fscanf(fin, "%f", &eMobilityWeight);
  154.         fscanf(fin, "%f", &eMobilityFactor);
  155.         fclose(fin);
  156.     }
  157.  
  158.     void save(string fileName){
  159.         FILE* fout = fopen(fileName.c_str(), "w");
  160.         fprintf(fout, "%f\n", eFilled0);
  161.         fprintf(fout, "%f\n", eFilled1);
  162.         fprintf(fout, "%f\n", eFilled2);
  163.         fprintf(fout, "%f\n", eFilled3);
  164.         fprintf(fout, "%f\n", eScore1_1);
  165.         fprintf(fout, "%f\n", eScore1_2);
  166.         fprintf(fout, "%f\n", eScore1_3);
  167.         fprintf(fout, "%f\n", eScore1_4);
  168.         fprintf(fout, "%f\n", eScore2_1);
  169.         fprintf(fout, "%f\n", eScore2_2);
  170.         fprintf(fout, "%f\n", eScore2_3);
  171.         fprintf(fout, "%f\n", eScore2_4);
  172.         fprintf(fout, "%f\n", eScore2_5);
  173.         fprintf(fout, "%f\n", eScore2_6);
  174.         fprintf(fout, "%f\n", eCoeffMax);
  175.         fprintf(fout, "%f\n", eMobilityWeight);
  176.         fprintf(fout, "%f\n", eMobilityFactor);
  177.         fclose(fout);
  178.     }
  179.  
  180.     void printParams(){
  181.         cout << eFilled0 << " = " << eFilled0 << endl;
  182.         cout << eFilled1 << " = " << eFilled1 << endl;
  183.         cout << eFilled2 << " = " << eFilled2 << endl;
  184.         cout << eFilled3 << " = " << eFilled3 << endl;
  185.         cout << eScore1_1 << " = " << eScore1_1 << endl;
  186.         cout << eScore1_2 << " = " << eScore1_2 << endl;
  187.         cout << eScore1_3 << " = " << eScore1_3 << endl;
  188.         cout << eScore1_4 << " = " << eScore1_4 << endl;
  189.         cout << eScore2_1 << " = " << eScore2_1 << endl;
  190.         cout << eScore2_2 << " = " << eScore2_2 << endl;
  191.         cout << eScore2_3 << " = " << eScore2_3 << endl;
  192.         cout << eScore2_4 << " = " << eScore2_4 << endl;
  193.         cout << eScore2_5 << " = " << eScore2_5 << endl;
  194.         cout << eScore2_6 << " = " << eScore2_6 << endl;
  195.         cout << eCoeffMax << " = " << eCoeffMax << endl;
  196.     }
  197. } bot;
  198.  
  199. void printPos(int x, int y){
  200.     printf("%c%d", 'a'+y, x+1);
  201. }
  202.  
  203. struct Move{
  204.     int fx, fy;
  205.     int tx, ty;
  206.     int ax, ay;
  207.  
  208.     Move(){
  209.     }
  210.  
  211.     Move(int _fx, int _fy, int _tx, int _ty, int _ax, int _ay){
  212.         fx=_fx;
  213.         fy=_fy;
  214.         tx=_tx;
  215.         ty=_ty;
  216.         ax=_ax;
  217.         ay=_ay;
  218.     }
  219.  
  220.     bool operator<(const Move &other) const{
  221.         if(fx != other.fx)
  222.             return fx < other.fx;
  223.         if(tx != other.tx)
  224.             return tx < other.tx;
  225.         if(ax != other.ax)
  226.             return ax < other.ax;
  227.         if(fy != other.fy)
  228.             return fy < other.fy;
  229.         if(ty != other.ty)
  230.             return ty < other.ty;
  231.         if(ay != other.ay)
  232.             return ay < other.ay;
  233.         return 0;
  234.     }
  235.  
  236.     bool operator==(const Move &other) const{
  237.         if(fx != other.fx)
  238.             return 0;
  239.         if(fy != other.fy)
  240.             return 0;
  241.         if(tx != other.tx)
  242.             return 0;
  243.         if(ty != other.ty)
  244.             return 0;
  245.         if(ax != other.ax)
  246.             return 0;
  247.         if(ay != other.ay)
  248.             return 0;
  249.         return 1;
  250.     }
  251.  
  252.     void print(){
  253.         printPos(fx, fy);
  254.         printf(" - ");
  255.         printPos(tx, ty);
  256.         printf(" : ");
  257.         printPos(ax, ay);
  258.         printf("\n");
  259.     }
  260.  
  261.     void printUgly(){
  262.         printf("%d %d\n%d %d\n%d %d\n", fx, fy, tx, ty, ax, ay);
  263.     }
  264. };
  265.  
  266. map<hashType, int> lowerBound[125];
  267. map<hashType, int> upperBound[125];
  268. map<hashType, int> scoreMap;
  269.  
  270. struct State{
  271.     char f[10][10];
  272.     //char region[10][10];
  273.     int turn;
  274.     //int regionN;
  275.     //vector<int> regionSize;
  276.     //vector<int> amazonN[2];
  277.    
  278.     hashType toHash(){
  279.         ll h1=0, h2=0, h3=0;
  280.         int k=0;
  281.         rep(i,0,6){
  282.             rep(j,0,10){
  283.                 if(f[i][j] != 0)
  284.                     h1 |= (1LL<<k);
  285.                 ++k;
  286.             }
  287.         }
  288.         k=0;
  289.         rep(i,6,10){
  290.             rep(j,0,10){
  291.                 if(f[i][j] != 0)
  292.                     h2 |= (1LL<<k);
  293.                 ++k;
  294.             }
  295.         }
  296.         ll mul=1;
  297.         rep(i,0,10)
  298.         rep(j,0,10){
  299.             if(f[i][j] == 1){
  300.                 h3 |= mul*(10*i+j);
  301.                 mul *= 100;
  302.             }
  303.         }
  304.         rep(i,0,10)
  305.         rep(j,0,10){
  306.             if(f[i][j] == 2){
  307.                 h3 |= mul*(10*i+j);
  308.                 mul *= 100;
  309.             }
  310.         }
  311.         return make_pair(h1, make_pair(h2, h3));
  312.     }
  313.  
  314.     State performMove(Move move){
  315.         State ret=*this;
  316.         ret.f[move.tx][move.ty]=ret.f[move.fx][move.fy];
  317.         ret.f[move.fx][move.fy]=0;
  318.         ret.f[move.ax][move.ay]=-1;
  319.         ret.turn^=1;
  320.         return ret;
  321.     }
  322.  
  323.     bool lineFree(int fx, int fy, int tx, int ty, int ix, int iy){
  324.         int dx, dy;
  325.         if(tx > fx)dx=1;
  326.         else if(tx < fx)dx=-1;
  327.         else dx=0;
  328.         if(ty > fy)dy=1;
  329.         else if(ty < fy)dy=-1;
  330.         else dy=0;
  331.         fx += dx;
  332.         fy += dy;
  333.         while(fx != tx && fy != ty){
  334.             if(f[fx][fy] != 0 && !(fx == ix && fy == iy))
  335.                 return 0;
  336.             fx += dx;
  337.             fy += dy;
  338.         }
  339.         return 1;
  340.     }
  341.  
  342.     bool okMove(Move move){
  343.         if(move.fx < 0 || move.fy < 0 || move.fx >= 10 || move.fy >= 10)
  344.             return 0;
  345.         if(f[move.fx][move.fy]-1 != turn)
  346.             return 0;
  347.         if(f[move.tx][move.ty] != 0)
  348.             return 0;
  349.         if(!lineFree(move.fx, move.fy, move.tx, move.ty, -1, -1))
  350.             return 0;
  351.         if(!lineFree(move.tx, move.ty, move.ax, move.ay, move.fx, move.fy))
  352.             return 0;
  353.         if(f[move.ax][move.ay] != 0 && !(move.ax == move.fx && move.ay == move.fy))
  354.             return 0;
  355.         return 1;
  356.     }
  357.    
  358.     void print(int indent){
  359.         rep(i,0,10){
  360.             rep(j,0,indent)
  361.                 printf("  ");
  362.             rep(j,0,10){
  363.                 if(f[i][j] == 0)
  364.                     printf(".");
  365.                 else if(f[i][j] == -1)
  366.                     printf("#");
  367.                 else
  368.                     printf("%c", '0'+f[i][j]);
  369.             }
  370.             printf("\n");
  371.         }
  372.         printf("\n");
  373.     }
  374.    
  375.     void print(){
  376.         print(0);
  377.     }
  378.  
  379.     int eval(){
  380.         hashType h;
  381.         if(bot.useTranspositionTable){
  382.             h=toHash();
  383.             if(scoreMap.count(h)){
  384.                 return scoreMap[h];
  385.             }
  386.         }
  387.         int ret=0;
  388.         if(!bot.useDistanceEval && bot.useMobilityEval){
  389.             rep(i,0,10)
  390.             rep(j,0,10){
  391.                 if(f[i][j] <= 0)
  392.                     continue;
  393.                 int mobility=0;
  394.                 rep(k,0,8){
  395.                     int x=i+DX[k];
  396.                     int y=j+DY[k];
  397.                     if(x < 0 || y < 0 || x >= 10 || y >= 10)
  398.                         continue;
  399.                     if(f[x][y] == 0)
  400.                         mobility++;
  401.                 }
  402.                 if(f[i][j]-1 == turn)
  403.                     ret += mobility;
  404.                 else
  405.                     ret -= mobility;
  406.             }
  407.         }
  408.             rep(i,0,10)
  409.             rep(j,0,10){
  410.                 if(f[i][j] == -1)
  411.                     continue;
  412.                 bufneigh[i][j]=0;
  413.                 rep(k,0,8){
  414.                     int tx=i+DX[k];
  415.                     int ty=j+DY[k];
  416.                     if(tx < 0 || tx >= 10)
  417.                         continue;
  418.                     if(ty < 0 || ty >= 10)
  419.                         continue;
  420.                     if(f[tx][ty] != 0)
  421.                         continue;
  422.                     bufneigh[i][j]++;
  423.                 }
  424.             }
  425.             rep(i,0,10)
  426.             rep(j,0,10){
  427.                 squareScore[i][j]=1;
  428.             }
  429.             if(lateGame && bot.useLateGameEval){
  430.                 rep(i,0,10)
  431.                 rep(j,0,10){
  432.                     if(f[i][j] == -1)
  433.                         continue;
  434.                     squareScore[i][j]=1+bufneigh[i][j]*0.005;
  435.                     /*if(bufneigh[i][j] <= 3){
  436.                         bool ok=0;
  437.                         rep(k,0,8){
  438.                             int tx=i+DX[k];
  439.                             int ty=j+DY[k];
  440.                             if(tx < 0 || tx >= 10)
  441.                                 continue;
  442.                             if(ty < 0 || ty >= 10)
  443.                                 continue;
  444.                             if(f[tx][ty] == -1)
  445.                                 continue;
  446.                             if(bufneigh[tx][ty] > 1){
  447.                                 ok=1;
  448.                                 break;
  449.                             }
  450.                         }
  451.                         if(!ok)
  452.                             squareScore[i][j]=0.5;
  453.                     }*/
  454.                     //squareScore[i][j]=1;
  455.                 }
  456.             }
  457.         if(bot.useDistanceEval){
  458.             //print();
  459.         for(int player=0; player <= 1; ++player){
  460.             int qfront=0;
  461.             int qend=0;
  462.             rep(i,0,10)
  463.             rep(j,0,10){
  464.                 bufdis[player][i][j]=120;
  465.                 bufdis2[player][i][j]=120;
  466.                 if(f[i][j] == player+1){
  467.                     bufx[qend]=i;
  468.                     bufy[qend]=j;
  469.                     bufdis[player][i][j]=0;
  470.                     ++qend;
  471.                 }
  472.             }
  473.             while(qfront < qend){
  474.                 int i=bufx[qfront];
  475.                 int j=bufy[qfront];
  476.                 int D=bufdis[player][i][j];
  477.                 ++qfront;
  478.                 for(int dir=0; dir < 8; ++dir)
  479.                 for(int len=1; true; ++len){
  480.                     int tx=i+DX[dir]*len;
  481.                     int ty=j+DY[dir]*len;
  482.                     if(tx < 0 || tx >= 10)
  483.                         break;
  484.                     if(ty < 0 || ty >= 10)
  485.                         break;
  486.                     if(f[tx][ty] != 0)
  487.                         break;
  488.                     if(bufdis[player][tx][ty] <= D+1)
  489.                         continue;
  490.                     bufdis[player][tx][ty]=D+1;
  491.                     bufx[qend]=tx;
  492.                     bufy[qend]=ty;
  493.                     ++qend;
  494.                 }
  495.             }
  496.             qfront=0;
  497.             qend=0;
  498.             rep(i,0,10)
  499.             rep(j,0,10){
  500.                 if(f[i][j] == player+1){
  501.                     bufx[qend]=i;
  502.                     bufy[qend]=j;
  503.                     bufdis2[player][i][j]=0;
  504.                     ++qend;
  505.                 }
  506.             }
  507.             while(qfront < qend){
  508.                 int i=bufx[qfront];
  509.                 int j=bufy[qfront];
  510.                 int D=bufdis2[player][i][j];
  511.                 ++qfront;
  512.                 for(int dir=0; dir < 8; ++dir){
  513.                     int tx=i+DX[dir];
  514.                     int ty=j+DY[dir];
  515.                     if(tx < 0 || tx >= 10)
  516.                         continue;
  517.                     if(ty < 0 || ty >= 10)
  518.                         continue;
  519.                     if(f[tx][ty] != 0)
  520.                         continue;
  521.                     if(bufdis2[player][tx][ty] <= D+1)
  522.                         continue;
  523.                     bufdis2[player][tx][ty]=D+1;
  524.                     bufx[qend]=tx;
  525.                     bufy[qend]=ty;
  526.                     ++qend;
  527.                 }
  528.             }
  529.         }
  530.         float ret1=0, ret2=0;
  531.         if(bot.updateCoeff)
  532.             coeff=0;
  533.         rep(i,0,10)
  534.         rep(j,0,10){
  535.             int diff=bufdis[turn][i][j]-bufdis[!turn][i][j];
  536.             if(bot.updateCoeff){
  537.             if(diff == 0){
  538.                 if(bufdis[turn][i][j] < 10)
  539.                     coeff += bot.eFilled0;
  540.                 continue;
  541.             }
  542.             if(abs(diff) == 1)
  543.                 coeff += bot.eFilled1;
  544.             else if(abs(diff) == 2)
  545.                 coeff += bot.eFilled2;
  546.             else if(abs(diff) <= 5){
  547.                 coeff += bot.eFilled3;
  548.             }
  549.             }
  550.             if(diff < 0){
  551.                 if(diff == -1)
  552.                     ret1 += bot.eScore1_1*squareScore[i][j];
  553.                 else if(diff == -2)
  554.                     ret1 += bot.eScore1_2*squareScore[i][j];
  555.                 else if(diff == -3)
  556.                     ret1 += bot.eScore1_3*squareScore[i][j];
  557.                 else
  558.                     ret1 += bot.eScore1_4*squareScore[i][j];
  559.                 continue;
  560.             }
  561.             if(diff > 0){
  562.                 if(diff == 1)
  563.                     ret1 -= bot.eScore1_1*squareScore[i][j];
  564.                 else if(diff == 2)
  565.                     ret1 -= bot.eScore1_2*squareScore[i][j];
  566.                 else if(diff == 3)
  567.                     ret1 -= bot.eScore1_3*squareScore[i][j];
  568.                 else
  569.                     ret1 -= bot.eScore1_4*squareScore[i][j];
  570.                 continue;
  571.             }
  572.         }
  573.         if(!bot.useExtraDistanceEval){
  574.             return ret1;
  575.         }
  576.         rep(i,0,10)
  577.         rep(j,0,10){
  578.             int diff=bufdis2[turn][i][j]-bufdis2[!turn][i][j];
  579.             if(diff == 0)
  580.                 continue;
  581.             int adiff=abs(diff);
  582.             int change;
  583.             switch(adiff){
  584.                 case 1:change=bot.eScore2_1;break;
  585.                 case 2:change=bot.eScore2_2;break;
  586.                 case 3:change=bot.eScore2_3;break;
  587.                 case 4:change=bot.eScore2_4;break;
  588.                 case 5:change=bot.eScore2_5;break;
  589.                 default:change=bot.eScore2_6;break;
  590.             }
  591.             if(diff < 0){
  592.                 ret2 += change*squareScore[i][j];
  593.                 continue;
  594.             }
  595.             if(diff > 0){
  596.                 ret2 -= change*squareScore[i][j];
  597.                 continue;
  598.             }
  599.         }
  600.         if(bot.updateCoeff)
  601.             coeff /= bot.eCoeffMax;
  602.         if(bot.useMobilityEval){
  603.             //print();
  604.             rep(i,0,10)
  605.             rep(j,0,10){
  606.                 if(f[i][j] <= 0)
  607.                     continue;
  608.                 int p=f[i][j];
  609.                 float m=0;
  610.                 for(int dir=0; dir < 8; ++dir){
  611.                 float mult=1;
  612.                 for(int len=1; true; ++len){
  613.                     int tx=i+DX[dir]*len;
  614.                     int ty=j+DY[dir]*len;
  615.                     if(tx < 0 || tx >= 10)
  616.                         break;
  617.                     if(ty < 0 || ty >= 10)
  618.                         break;
  619.                     if(f[tx][ty] != 0)
  620.                         break;
  621.                     if(bufdis2[2-p][tx][ty] > 50)
  622.                         break;
  623.                     m += mult*bufneigh[tx][ty];
  624.                     mult*=0.5;
  625.                 }
  626.                 }
  627.                 float change=bot.eMobilityWeight*coeff*(1-exp(-m*bot.eMobilityFactor));
  628.                 if(bot.useWeirdMobility)
  629.                     change=5000*coeff/(5+bot.eMobilityFactor);
  630.                 if(p-1 == turn)
  631.                     ret += change;
  632.                 else
  633.                     ret -= change;
  634.             }
  635.         }
  636.         ret += ret2*coeff+ret1*(1-coeff);
  637.         }
  638.         /*if(!regionN)
  639.             regionify();
  640.         rep(i,0,regionN){
  641.             if(amazonN[0][i] == amazonN[1][i])
  642.                 continue;
  643.             if(!amazonN[turn][i]){
  644.                 ret -= regionSize[i];
  645.                 continue;
  646.             }
  647.             if(!amazonN[!turn][i]){
  648.                 ret += regionSize[i];
  649.                 continue;
  650.             }
  651.             ret += regionSize[i]*(amazonN[turn][i]-amazonN[!turn][i]);
  652.         }*/
  653.         if(bot.useTranspositionTable){
  654.             scoreMap[h]=ret;
  655.         }
  656.         return ret;
  657.     }
  658.  
  659.     bool operator<(const State &other) const{
  660.         return 0;
  661.     }
  662.  
  663.     /*void regionify(){
  664.         queue<pair<int, int> > q;
  665.         rep(i,0,10)
  666.             rep(j,0,10)
  667.                 region[i][j]=-1;
  668.         regionN=0;
  669.         rep(i,0,10)
  670.         rep(j,0,10){
  671.             if(f[i][j] == -1 || region[i][j] != -1)
  672.                 continue;
  673.             q.push(make_pair(i, j));
  674.             while(!q.empty()){
  675.                 int x=q.front().first;
  676.                 int y=q.front().second;
  677.                 q.pop();
  678.                 rep(d,0,8){
  679.                     int nx=x+DX[d];
  680.                     int ny=y+DY[d];
  681.                     if(nx < 0 || ny < 0 || nx >= 10 || ny >= 10)
  682.                         continue;
  683.                     if(f[nx][ny] == -1 || region[nx][ny] != -1)
  684.                         continue;
  685.                     region[nx][ny]=regionN;
  686.                     q.push(make_pair(nx, ny));
  687.                 }
  688.             }
  689.             ++regionN;
  690.         }
  691.         regionSize=vector<int>(regionN);
  692.         amazonN[0]=vector<int>(regionN);
  693.         amazonN[1]=vector<int>(regionN);
  694.         rep(i,0,10)
  695.         rep(j,0,10){
  696.             if(region[i][j] != -1){
  697.                 ++regionSize[region[i][j]];
  698.                 if(f[i][j] != 0)
  699.                     ++amazonN[f[i][j]-1][region[i][j]];
  700.             }
  701.         }
  702.     }*/
  703. };
  704.  
  705.  
  706. /*unordered_map<ll, int> lowerBound[70];
  707. unordered_map<ll, int> upperBound[70];
  708. unordered_map<ll, int> scoreMap[70];*/
  709.  
  710. State parseState(){
  711.     State ret;
  712.     for(int i=0; i < 10; ++i)
  713.         for(int j=0; j < 10; ++j){
  714.             int f;
  715.             scanf("%d", &f);
  716.             ret.f[i][j]=f;
  717.         }
  718.     scanf("%d", &ret.turn);
  719.     ret.turn -= 1;
  720.     return ret;
  721. }
  722.  
  723. bool doFullSearch=false;
  724. int statesChecked;
  725. int startD=0;
  726. bool printStuff;
  727. Move killerMoves[125];
  728. map<Move, int> historyScore;
  729.  
  730. int alphabeta(State s, int d, int alpha, int beta){
  731.     ++statesChecked;
  732.     if(aborted)
  733.         return 0;
  734.     //s.regionify();
  735.     statesDone += 100;
  736.     if(statesDone > checkTime && startD){
  737.         checkTime += 10000;
  738.         if(!doFullSearch && (float(clock()-startTime))/CLOCKS_PER_SEC > bot.timeLimit){
  739.             aborted=1;
  740.             return 0;
  741.         }
  742.     }
  743.     if(!d){
  744.         return s.eval();
  745.     }
  746.     int sc=-1000000000;
  747.     bool existsDisputed=false;
  748.     //s.print();
  749.     vector<pair<int, pair<State, Move> > > v;
  750.     Move killerMove = killerMoves[d];
  751.     if(bot.useKiller){
  752.     if(s.okMove(killerMove)){
  753.         State newState=s.performMove(killerMove);
  754.         v.push_back(make_pair(-1500000000, make_pair(newState, killerMove)));
  755.     }
  756.     }
  757.     rep(fx,0,10)
  758.     rep(fy,0,10){
  759.         if(s.f[fx][fy]-1 != s.turn)
  760.             continue;
  761.         for(int dir=0; dir < 8; ++dir)
  762.         for(int len=1; true; ++len){
  763.             int tx=fx+DX[dir]*len;
  764.             int ty=fy+DY[dir]*len;
  765.             if(tx < 0 || tx >= 10)
  766.                 break;
  767.             if(ty < 0 || ty >= 10)
  768.                 break;
  769.             if(s.f[tx][ty] != 0)
  770.                 break;
  771.         for(int adir=0; adir < 8; ++adir)
  772.         for(int alen=1; true; ++alen){
  773.             int ax=tx+DX[adir]*alen;
  774.             int ay=ty+DY[adir]*alen;
  775.             Move move(fx, fy, tx, ty, ax, ay);
  776.             if(ax < 0 || ax >= 10)
  777.                 break;
  778.             if(ay < 0 || ay >= 10)
  779.                 break;
  780.             if(s.f[ax][ay] != 0 && !(ax == fx && ay == fy))
  781.                 break;
  782.             if(move == killerMove)
  783.                 continue;
  784.             //if(!s.okMove(move))
  785.             //  assert(0);
  786.             /*if(bot.restrictMoves){
  787.             if(s.amazonN[!s.turn][s.region[fx][fy]]){
  788.                 if(!existsDisputed){
  789.                     existsDisputed=true;
  790.                     v.clear();
  791.                 }
  792.             }
  793.             else{
  794.                 if(existsDisputed)
  795.                     continue;
  796.             }
  797.             }*/
  798.             State newState=s.performMove(move);
  799.             if(bot.useIterativeDeepening){
  800.                 if(d > 1 && !bot.useFullHistory)
  801.                     v.push_back(make_pair(newState.eval(), make_pair(newState, move)));
  802.                 else if(bot.useHistory)
  803.                     v.push_back(make_pair(-historyScore[move], make_pair(newState, move)));
  804.                 else
  805.                     v.push_back(make_pair(0, make_pair(newState, move)));
  806.             }
  807.             else{
  808.                 v.push_back(make_pair(0, make_pair(newState, move)));
  809.             }
  810.         }
  811.         }
  812.     }
  813.     if((d > 1 || bot.useHistory) && bot.useIterativeDeepening)sort(v.begin(), v.end());
  814.     rep(i,0,v.size()){
  815.         int score;
  816.         score=-alphabeta(v[i].second.first, d-1, -beta, -alpha);
  817.         if(score > alpha){
  818.             //scoreMap[d][sLL]=score;
  819.             alpha=score;
  820.         }
  821.         if(score > sc){
  822.             sc=score;
  823.         }
  824.         if(sc >= beta && bot.useAlphaBeta){
  825.             killerMoves[d]=v[i].second.second;
  826.             if(bot.useHistory)
  827.                 historyScore[v[i].second.second] += d*d;
  828.             return sc;
  829.         }
  830.     }
  831.     if(v.empty())
  832.         sc=-1000000000;
  833.     return sc;
  834. }
  835.  
  836.  
  837. Move findMove(State s){
  838.     historyScore.clear();
  839.     statesChecked=0;
  840.     Move bestMove(-1,-1,-1,-1,-1,-1);
  841.     Move lastBestMove=bestMove;
  842.     bool lastBestMoveExists=0;
  843.     bool anyMove=false;
  844.     int bestScore=-1000000001;
  845.     int numMoves=0;
  846.     rep(i,0,10)
  847.     rep(j,0,10){
  848.         numMoves += (s.f[i][j] == -1);
  849.     }
  850.     int randSize;
  851.     if(numMoves < 6)
  852.         randSize=30;
  853.     else if(numMoves < 10)
  854.         randSize=10;
  855.     else if(numMoves < 20)
  856.         randSize=5;
  857.     else if(numMoves < 40)
  858.         randSize=1;
  859.     else
  860.         randSize=1;
  861.     lateGame = (numMoves > 50);
  862.     vector<pair<int, Move> > perm;
  863.     srand(time(0));
  864.     rep(fx,0,10)
  865.     rep(fy,0,10){
  866.         if(s.f[fx][fy]-1 != s.turn)
  867.             continue;
  868.         for(int dir=0; dir < 8; ++dir)
  869.         for(int len=1; true; ++len){
  870.             int tx=fx+DX[dir]*len;
  871.             int ty=fy+DY[dir]*len;
  872.             if(tx < 0 || tx >= 10)
  873.                 break;
  874.             if(ty < 0 || ty >= 10)
  875.                 break;
  876.             if(s.f[tx][ty] != 0)
  877.                 break;
  878.         for(int adir=0; adir < 8; ++adir)
  879.         for(int alen=1; true; ++alen){
  880.             int ax=tx+DX[adir]*alen;
  881.             int ay=ty+DY[adir]*alen;
  882.             Move move(fx, fy, tx, ty, ax, ay);
  883.             if(ax < 0 || ax >= 10)
  884.                 break;
  885.             if(ay < 0 || ay >= 10)
  886.                 break;
  887.             if(s.f[ax][ay] != 0 && !(ax == fx && ay == fy))
  888.                 break;
  889.             if(!s.okMove(move))
  890.                 assert(0);
  891.             State newState=s.performMove(move);
  892.             if(bot.useIterativeDeepening){
  893.                 int add=rand()%randSize;
  894.                 perm.push_back(make_pair(newState.eval()+add, move));
  895.             }
  896.             else
  897.                 perm.push_back(make_pair(0, move));
  898.         }
  899.         }
  900.     }
  901.     if(bot.useIterativeDeepening)
  902.         sort(all(perm));
  903.     else
  904.         random_shuffle(all(perm));
  905.     vector<int> scores;
  906.     bool updateCoeff= bot.updateCoeff;
  907.     if(!updateCoeff){
  908.         bot.updateCoeff=true;
  909.         s.eval();
  910.         bot.updateCoeff=false;
  911.     }
  912.     rep(d,0,105){
  913.     startD=d;
  914.     bestScore=-1000000001;
  915.     bestMove=lastBestMove;
  916.     if(lastBestMove.fx != -1){
  917.         Move move=lastBestMove;
  918.         State newState=s.performMove(move);
  919.         int score;
  920.         int add=rand()%randSize;
  921.         score=-alphabeta(newState, d, -1000000000, 1000000000)+add;
  922.         if(score > bestScore){
  923.             bestScore = score;
  924.             bestMove=move;
  925. #ifdef DEBUG_PRINT
  926.             printf("d = %d, bestScore = %d : ", d, bestScore);
  927.             bestMove.print();
  928. #endif
  929.         }
  930.     }
  931.     rep(i,0,perm.size()){
  932.         Move move=perm[i].second;
  933.         if(d && lastBestMove == move)
  934.             continue;
  935.         State newState=s.performMove(move);
  936.         int score;
  937.         score=-alphabeta(newState, d, -1000000000, -bestScore);
  938.         if(score > bestScore && !aborted){
  939.             int add=rand()%randSize;
  940.             score += add;
  941.             bestScore = score;
  942.             bestMove=move;
  943.             anyMove=true;
  944. #ifdef DEBUG_PRINT
  945.             printf("d = %d, bestScore = %d : ", d, bestScore);
  946.             bestMove.print();
  947.             //newState.print();
  948. #endif
  949.         }
  950.     }
  951.     if(!anyMove)
  952.         return Move(-2,-2,-2,-2,-2,-2);
  953.     lastBestMove=bestMove;
  954.     if(aborted){
  955.         break;
  956.     }
  957.     scores.push_back(bestScore);
  958.     }
  959. #ifdef DEBUG_PRINT
  960.     cout << bot.name << " ";
  961.     printf("%d (%d)\n", scores.back(), scores.size());
  962.     printf("States checked: %d\n", statesChecked);
  963. #endif
  964.     bestMove=lastBestMove;
  965.     assert(s.okMove(bestMove));
  966.     return bestMove;
  967. }
  968.  
  969. vector<Bot> bots;
  970.  
  971. pair<int, int> playGames(){
  972.     vector<int> totScore(bots.size(), 0);
  973.     vector<vector<int> > stats(bots.size(), vector<int>(bots.size(), -1));
  974.     for(int b1=0; b1 < bots.size(); ++b1)
  975.     for(int b2=0; b2 < bots.size(); ++b2){
  976.     if(b1 == b2)
  977.         continue;
  978.     string fileName = "game_" + bots[b1].name + "_" + bots[b2].name + ".txt";
  979.     FILE *file;
  980.         if(file = fopen(fileName.c_str(), "r")){
  981.         int result;
  982.         fscanf(file, "%d", &result);
  983.         fclose(file);
  984.         stats[b1][b2]=result;
  985.         continue;
  986.     }
  987.     }
  988.     for(int b1=0; b1 < bots.size(); ++b1)
  989.     for(int b2=0; b2 < bots.size(); ++b2){
  990.     if(b1 == b2)
  991.         continue;
  992.     string fileName = "game_" + bots[b1].name + "_" + bots[b2].name + ".txt";
  993.     FILE *file;
  994.         if(file = fopen(fileName.c_str(), "r")){
  995.         int result;
  996.         fscanf(file, "%d", &result);
  997.         fclose(file);
  998.         stats[b1][b2]=result;
  999.         continue;
  1000.     }
  1001.     file = fopen(fileName.c_str(), "w");
  1002.     State s;
  1003.     rep(i,0,10)
  1004.         rep(j,0,10)
  1005.             s.f[i][j]=0;
  1006.     s.f[3][0]=2;
  1007.     s.f[0][3]=2;
  1008.     s.f[0][6]=2;
  1009.     s.f[3][9]=2;
  1010.     s.f[6][0]=1;
  1011.     s.f[9][3]=1;
  1012.     s.f[9][6]=1;
  1013.     s.f[6][9]=1;
  1014.     s.turn=0;
  1015.     int turn=0;
  1016.     while(true){
  1017.         scoreMap.clear();
  1018.         startTime=clock();
  1019.         statesDone=0;
  1020.         aborted=0;
  1021.         checkTime=0;
  1022.         if(turn == 0)
  1023.             bot=bots[b1];
  1024.         else
  1025.             bot=bots[b2];
  1026.         Move bestMove = findMove(s);
  1027.         if(bestMove.fx == -2){
  1028.             stats[b1][b2]=s.turn;
  1029.             fprintf(file, "%d", stats[b1][b2]);
  1030.             fclose(file);
  1031.             break;
  1032.         }
  1033.         s=s.performMove(bestMove);
  1034.         turn=!turn;
  1035. #ifdef DEBUG_PRINT
  1036.         s.print();
  1037. #endif
  1038.         bestMove.print();
  1039.         //getch();
  1040.     }
  1041.     #ifdef DEBUG_PRINT
  1042.         s.print();
  1043.     #endif
  1044.     rep(a,0,bots.size()){
  1045.         totScore[a]=0;
  1046.     printf("%s", bots[a].name.c_str());
  1047.     rep(k,bots[a].name.size(), 14)printf(" ");
  1048.     int sum=0;
  1049.     rep(b,0,bots.size()){
  1050.         if(stats[a][b] == -1)printf(" ");
  1051.         else{
  1052.             printf("%d", stats[a][b]);
  1053.             sum += stats[a][b];
  1054.         }
  1055.         if(stats[b][a] == -1)printf(" ");
  1056.         else{
  1057.             printf("%d", !stats[b][a]);
  1058.             sum += !stats[b][a];
  1059.         }
  1060.     }
  1061.     totScore[a]=sum;
  1062.     printf("  %d\n", sum);
  1063.     }
  1064.     }
  1065.     return make_pair(totScore[bots.size()-2], totScore[bots.size()-1]);
  1066. }
  1067.  
  1068. int main(){
  1069.     startTime = clock();
  1070.     /*Bot bot1("mob");
  1071.     bot1.useAlphaBeta=false;
  1072.     bot1.useIterativeDeepening=false;
  1073.     bot1.useMobilityEval=true;
  1074.     bots.push_back(bot1);
  1075.     Bot bot2("default");
  1076.     bots.push_back(bot2);*/
  1077.     /*Bot bot3("Ni");
  1078.     bot3.useIterativeDeepening=false;
  1079.     bot3.useMobilityEval=false;
  1080.     bot3.useDistanceEval=true;
  1081.     bots.push_back(bot3);
  1082.     Bot bot4("NiRm");
  1083.     bot4.useIterativeDeepening=false;
  1084.     bot4.useMobilityEval=false;
  1085.     bot4.useDistanceEval=true;
  1086.     bots.push_back(bot4);*/
  1087.     /*Bot bot5("MbDi");
  1088.     bot5.useMobilityEval=false;
  1089.     bot5.useDistanceEval=true;
  1090.     bots.push_back(bot5);*/
  1091.     /*Bot bot6("NiEf");
  1092.     bot6.useIterativeDeepening=false;
  1093.     bot6.useMobilityEval=false;
  1094.     bot6.useDistanceEval=true;
  1095.     bot6.useExtraDistanceEval=true;
  1096.     bots.push_back(bot6);
  1097.     Bot bot7("Ef");
  1098.     bot7.useMobilityEval=false;
  1099.     bot7.useDistanceEval=true;
  1100.     bot7.useExtraDistanceEval=true;
  1101.     bots.push_back(bot7);*/
  1102.     /*Bot bot8("NiEfMo");
  1103.     bot8.useIterativeDeepening=false;
  1104.     bot8.useMobilityEval=true;
  1105.     bot8.useDistanceEval=true;
  1106.     bot8.useExtraDistanceEval=true;
  1107.     bots.push_back(bot8);*/
  1108.     Bot bot9("EfMo");
  1109.     bot9.useMobilityEval=true;
  1110.     bot9.useDistanceEval=true;
  1111.     bot9.useExtraDistanceEval=true;
  1112.     bots.push_back(bot9);
  1113.     /*Bot bot10("NiEfMoK");
  1114.     bot10.useIterativeDeepening=false;
  1115.     bot10.useMobilityEval=true;
  1116.     bot10.useDistanceEval=true;
  1117.     bot10.useExtraDistanceEval=true;
  1118.     bot10.useKiller=true;
  1119.     bots.push_back(bot10);*/
  1120.     Bot bot11("EfMoK");
  1121.     bot11.useMobilityEval=true;
  1122.     bot11.useDistanceEval=true;
  1123.     bot11.useExtraDistanceEval=true;
  1124.     bot11.useKiller=true;
  1125.     bots.push_back(bot11);
  1126.     Bot bot12("EfMoHi");
  1127.     bot12.useMobilityEval=true;
  1128.     bot12.useDistanceEval=true;
  1129.     bot12.useExtraDistanceEval=true;
  1130.     bot12.useHistory=true;
  1131.     bots.push_back(bot12);
  1132.     /*Bot bot13("NiEfMoTr");
  1133.     bot13.useIterativeDeepening=false;
  1134.     bot13.useMobilityEval=true;
  1135.     bot13.useDistanceEval=true;
  1136.     bot13.useExtraDistanceEval=true;
  1137.     bot13.useTranspositionTable=true;
  1138.     bots.push_back(bot13);*/
  1139.     Bot bot14("EfMoTr");
  1140.     bot14.useMobilityEval=true;
  1141.     bot14.useDistanceEval=true;
  1142.     bot14.useExtraDistanceEval=true;
  1143.     bot14.useTranspositionTable=true;
  1144.     bots.push_back(bot14);
  1145.     /*Bot bot15("NiEfMoKTr");
  1146.     bot15.useIterativeDeepening=false;
  1147.     bot15.useMobilityEval=true;
  1148.     bot15.useDistanceEval=true;
  1149.     bot15.useExtraDistanceEval=true;
  1150.     bot15.useKiller=true;
  1151.     bot15.useTranspositionTable=true;
  1152.     bots.push_back(bot15);*/
  1153.     Bot bot16("EfMoKTr");
  1154.     bot16.useMobilityEval=true;
  1155.     bot16.useDistanceEval=true;
  1156.     bot16.useExtraDistanceEval=true;
  1157.     bot16.useKiller=true;
  1158.     bot16.useTranspositionTable=true;
  1159.     bots.push_back(bot16);
  1160.     Bot bot17("EfMoHiTr");
  1161.     bot17.useMobilityEval=true;
  1162.     bot17.useDistanceEval=true;
  1163.     bot17.useExtraDistanceEval=true;
  1164.     bot17.useHistory=true;
  1165.     bot17.useTranspositionTable=true;
  1166.     bots.push_back(bot17);
  1167.     Bot bot18("EfMoFHi");
  1168.     bot18.useMobilityEval=true;
  1169.     bot18.useDistanceEval=true;
  1170.     bot18.useExtraDistanceEval=true;
  1171.     bot18.useHistory=true;
  1172.     bot18.useFullHistory=true;
  1173.     bots.push_back(bot18);
  1174.     Bot bot19("EfMoFHiTr");
  1175.     bot19.useMobilityEval=true;
  1176.     bot19.useDistanceEval=true;
  1177.     bot19.useExtraDistanceEval=true;
  1178.     bot19.useHistory=true;
  1179.     bot19.useFullHistory=true;
  1180.     bot19.useTranspositionTable=true;
  1181.     bots.push_back(bot19);
  1182.     Bot botFinal=bot16;
  1183.     botFinal.name="Final";
  1184.     botFinal.setFinal();
  1185.     bots.push_back(botFinal);
  1186.     Bot botFinal2=botFinal;
  1187.     botFinal2.name="Final2";
  1188.     bots.push_back(botFinal2);
  1189.     Bot botFinal3=botFinal2;
  1190.     botFinal3.name="Final3";
  1191.     botFinal3.updateCoeff=false;
  1192.     bots.push_back(botFinal3);
  1193.     Bot botFinal4=botFinal3;
  1194.     botFinal4.name="Final3_50_";
  1195.     botFinal4.updateCoeff=false;
  1196.     botFinal4.eCoeffMax=50;
  1197.     bots.push_back(botFinal4);
  1198.     Bot botFinal5=botFinal3;
  1199.     botFinal5.name="Final3_55_";
  1200.     botFinal5.updateCoeff=false;
  1201.     botFinal5.eCoeffMax=55;
  1202.     bots.push_back(botFinal5);
  1203.     Bot botFinal6=botFinal3;
  1204.     botFinal6.name="Final3_57_";
  1205.     botFinal6.updateCoeff=false;
  1206.     botFinal6.eCoeffMax=57;
  1207.     bots.push_back(botFinal6);
  1208.     Bot botFinal9=botFinal3;
  1209.     botFinal9.name="Final3_58_";
  1210.     botFinal9.updateCoeff=false;
  1211.     botFinal9.eCoeffMax=58;
  1212.     bots.push_back(botFinal9);
  1213.     Bot botFinal10=botFinal3;
  1214.     botFinal10.name="Final3_60_";
  1215.     botFinal10.updateCoeff=false;
  1216.     botFinal10.eCoeffMax=60;
  1217.     bots.push_back(botFinal10);
  1218.     Bot botFinal7=botFinal3;
  1219.     botFinal7.name="Final3_61_";
  1220.     botFinal7.updateCoeff=false;
  1221.     botFinal7.eCoeffMax=61;
  1222.     bots.push_back(botFinal7);
  1223.     Bot botFinal8=botFinal3;
  1224.     botFinal8.name="Final3_63_";
  1225.     botFinal8.updateCoeff=false;
  1226.     botFinal8.eCoeffMax=63;
  1227.     bots.push_back(botFinal8);
  1228.     Bot botFinalEG=botFinal;
  1229.     botFinalEG.name="FinalEG";
  1230.     botFinalEG.useLateGameEval=true;
  1231.     bots.push_back(botFinalEG);
  1232.     Bot botFinal3EG=botFinal3;
  1233.     botFinal3EG.name="Final3EG";
  1234.     botFinal3EG.useLateGameEval=true;
  1235.     bots.push_back(botFinal3EG);
  1236.     bot=botFinal3EG;
  1237.     /*State start = parseState();
  1238.     while(true){
  1239.         getch();
  1240.     State s;
  1241.     rep(i,0,5)
  1242.         rep(j,0,5)
  1243.             s.f[i][j]=0;
  1244.     //start=s;
  1245.     int movesDone=0;
  1246.     int prevScore=0;
  1247.     while(true){
  1248.         rep(i,0,70){
  1249.             scoreMap[i].clear();
  1250.         }
  1251.         startTime=clock();
  1252.         statesDone=0;
  1253.         checkTime=100000;
  1254.         aborted=0;
  1255.     Move bestMove = findMove(start);
  1256.     if(bestMove.mx == -2)
  1257.         break;
  1258.     bestMove.print();
  1259.     start=start.performMove(bestMove);
  1260.     start.print();
  1261.     if(movesDone > 45 && abs(abs(newScore)-abs(prevScore)) > 2000){
  1262.         assert(0);
  1263.     }
  1264.     prevScore=newScore;
  1265.     ++movesDone;
  1266.     getch();
  1267.     }
  1268.     }*/
  1269.     State start = parseState();
  1270.     Move bestMove = findMove(start);
  1271.     bestMove.printUgly();
  1272.     return 0;
  1273.     playGames();   
  1274.     return 0;
  1275.     playGames();
  1276.     Bot improveBot=botFinal3;
  1277.     improveBot.load("improve.bot");
  1278.     int botN=10;
  1279.     float alpha=0.04;
  1280.     while(true){
  1281.         alpha *= 0.993;
  1282.         float* changeVal;
  1283.         srand(time(0));
  1284.         int r=rand()%17;
  1285.         switch(r){
  1286.             case 0: changeVal=&improveBot.eFilled0;break;
  1287.             case 1: changeVal=&improveBot.eFilled1;break;
  1288.             case 2: changeVal=&improveBot.eFilled2;break;
  1289.             case 3: changeVal=&improveBot.eFilled3;break;
  1290.             case 4: changeVal=&improveBot.eScore1_1;break;
  1291.             case 5: changeVal=&improveBot.eScore1_2;break;
  1292.             case 6: changeVal=&improveBot.eScore1_3;break;
  1293.             case 7: changeVal=&improveBot.eScore1_4;break;
  1294.             case 8: changeVal=&improveBot.eScore2_1;break;
  1295.             case 9: changeVal=&improveBot.eScore2_2;break;
  1296.             case 10: changeVal=&improveBot.eScore2_3;break;
  1297.             case 11: changeVal=&improveBot.eScore2_4;break;
  1298.             case 12: changeVal=&improveBot.eScore2_5;break;
  1299.             case 13: changeVal=&improveBot.eScore2_6;break;
  1300.             case 14: changeVal=&improveBot.eMobilityWeight;break;
  1301.             case 15: changeVal=&improveBot.eMobilityFactor;break;
  1302.             default: changeVal=&improveBot.eCoeffMax;break;
  1303.         }
  1304.         float initVal=*changeVal;
  1305.         *changeVal=initVal*(1-alpha);
  1306.         Bot botL=improveBot;
  1307.         *changeVal=initVal*(1+alpha);
  1308.         Bot botH=improveBot;
  1309.         stringstream ss;
  1310.         string name=improveBot.name;
  1311.         while(name.back() >= '0' && name.back() <= '9')
  1312.             name.pop_back();
  1313.         ss << name << botN;
  1314.         botL.name=ss.str();
  1315.         botL.name.push_back('L');
  1316.         botH.name=ss.str();
  1317.         botH.name.push_back('H');
  1318.         *changeVal=initVal;
  1319.         bots.push_back(botL);
  1320.         bots.push_back(botH);
  1321.         pair<int, int> result = playGames();
  1322.         float w1=result.first;
  1323.         float w2=result.second;
  1324.         bots.pop_back();
  1325.         bots.pop_back();
  1326.         //changeVal=initVal*(1+alpha*(w2-w1)/(1+w2+w1));
  1327.         Bot newBot;
  1328.         if(w2 > w1)
  1329.             newBot=botH;
  1330.         else if(w2 < w1)
  1331.             newBot=botL;
  1332.         else
  1333.             newBot=improveBot;
  1334.         //Bot newBot=improveBot;
  1335.         *changeVal=initVal;
  1336.         newBot.name=ss.str();
  1337.         newBot.printParams();
  1338.         if(rand()%10 == 0)
  1339.             bots.push_back(newBot);
  1340.         improveBot=newBot;
  1341.         improveBot.save("improve.bot");
  1342.         ++botN;
  1343.     }
  1344. }
Add Comment
Please, Sign In to add comment