Advertisement
Guest User

Untitled

a guest
Dec 29th, 2012
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.24 KB | None | 0 0
  1. int MaxMoveFirst(stateT state, moveT &bestMove)
  2. {
  3.   if(GameIsOver(state))
  4.     return EvaluateStaticPosition(state);
  5.  
  6.   vector<moveT> moveList;
  7.   GenerateMoveList(state, moveList);
  8.   int nMoves = moveList.size();
  9.   int v = -1000;
  10.  
  11.   #pragma omp parallel for
  12.   for(int i = 0 ;i<nMoves; i++) {
  13.     moveT move = moveList[i];
  14.     MakeMove(state, move);
  15.     moveT opponentsBestMove;
  16.     int curRating = -MaxMove(state,opponentsBestMove);
  17.     if (curRating > v)
  18.     {
  19.       v = curRating;
  20.       bestMove = move;
  21.     }
  22.     RetractMove(state, move);
  23.   }
  24.   return v;
  25. }
  26.  
  27.  
  28. int MaxMove(stateT state, moveT &bestMove)
  29. {
  30.   if(GameIsOver(state))
  31.     return EvaluateStaticPosition(state);
  32.  
  33.   vector<moveT> moveList;
  34.   GenerateMoveList(state, moveList);
  35.   int nMoves = moveList.size();
  36.   int v = -1000;
  37.  
  38.   for(int i = 0 ;i<nMoves; i++) {
  39.     moveT move = moveList[i];
  40.     MakeMove(state, move);
  41.     moveT opponentsBestMove;
  42.     int curRating = -MaxMove(state,opponentsBestMove);
  43.     if (curRating > v)
  44.     {
  45.       v = curRating;
  46.       bestMove = move;
  47.     }
  48.     RetractMove(state, move);
  49.   }
  50.   return v;
  51. }
  52.  
  53. moveT MiniMax(stateT state)
  54. {
  55.   moveT bestMove;
  56.   int i = 0;
  57.   i = MaxMoveFirst(state, bestMove);
  58.   return bestMove;
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement