Check out the Pastebin Gadgets Shop. We have thousands of fun, geeky & affordable gadgets on sale :-)Want more features on Pastebin? Sign Up, it's FREE!
tweet

# Untitled

By: a guest on Dec 29th, 2012  |  syntax: C++  |  size: 1.24 KB  |  views: 23  |  expires: Never
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
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. }
clone this paste RAW Paste Data
Top