I'm trying to code minimax with alpha-beta for Othello. Unfortunately,   
   I must have done something wrong since the minimax computer usually   
   loses to the random choice computer. Any ideas what's wrong with the   
   following code:   
      
   Board performgoodblackmove(const Board &b, const int depthleft=5)   
   {   
   vector v = legalmoves(b);   
   if (v.size()==0) {cout << "no moves possible" << endl; return b;}   
      
   int maxheur = -9999999;   
   int maxmovenum;   
      
   for (int ctr = 0; ctr < v.size(); ctr++)   
   {   
   Board testboard = makemove(b, v[ctr]);   
   int curheur = min(testboard, -999999, 999999, depthleft-1);   
   if (curheur > maxheur) {maxheur=curheur; maxmovenum=v[ctr];}   
   }   
      
   return makemove(b, maxmovenum);   
   }   
      
      
      
   int min(const Board &b, int alpha, int beta, int depthleft)   
   {   
   vector v = legalwhitemoves(b);   
   if (!depthleft) return b.heuristic();   
      
   for (int ctr = 0; ctr < v.size(); ctr++)   
   {   
   Board testboard = makewhitemove(b, v[ctr]);   
   int curheur = max(testboard, alpha, beta, depthleft-1);   
   if (curheur < beta) beta = curheur;   
   if (beta >= alpha) return alpha;   
   }   
   return beta;   
   }   
      
      
   int max(const Board &b, int alpha, int beta, int depthleft)   
   {   
   vector v = legalmoves(b);   
   if (!depthleft) b.heuristic();   
      
   for (int ctr = 0; ctr < v.size(); ctr++)   
   {   
   Board testboard = makemove(b, v[ctr]);   
   int curheur = min(testboard, alpha, beta, depthleft-1);   
   if (curheur > alpha) alpha = curheur;   
   if (alpha >= beta) return beta;   
   }   
   return alpha;   
   }   
      
      
   Thanks.   
      
   bob   
   http://www.coolgroups.com/   
      
   [ comp.ai is moderated. To submit, just post and be patient, or if ]   
   [ that fails mail your article to , and ]   
   [ ask your news administrator to fix the problems with your system. ]   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   
|