Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Add Boost::Thread::Sleep

  • Loading branch information...
commit aa8da60cc9faf8192b37221aa32274efe8363134 1 parent 8f722f4
option0417 authored
45  src/Algorithms/AlphaBeta/AlphaBeta.cpp
@@ -11,9 +11,7 @@ namespace op {
11 11
 
12 12
 AlphaBeta::AlphaBeta() {}
13 13
 
14  
-AlphaBeta::~AlphaBeta() {
15  
-	// TODO Auto-generated destructor stub
16  
-}
  14
+AlphaBeta::~AlphaBeta() {}
17 15
 
18 16
 int AlphaBeta::process(ABNode *node, int &alpha, int &beta, int depth, bool flag) {
19 17
 	cout<<"At :"<<depth<<endl;
@@ -24,25 +22,38 @@ int AlphaBeta::process(ABNode *node, int &alpha, int &beta, int depth, bool flag
24 22
 
25 23
 	if (flag) {
26 24
 		cout<<"True"<<endl;
27  
-		alpha = max(alpha, process(node->getnode(), alpha, beta, depth - 1, !flag));
28  
-		cout<<"Alpha :"<<alpha<<endl;
29  
-		cout<<"Beta :"<<beta<<endl;
30  
-		if (alpha >= beta) {
31  
-			cout<<"Beta cut"<<endl;
32  
-			cout<<"A :"<<alpha<<endl;
33  
-			cout<<"B :"<<beta<<endl;
  25
+		int cnt = 1;
  26
+		while (cnt <= AlphaBeta::degree) {
  27
+			cout<<"Cnt :"<<cnt<<endl;
  28
+			alpha = max(alpha, process(node->getnode(), alpha, beta, depth - 1, !flag));
  29
+			if (alpha >= beta) {
  30
+				cout<<"Beta cut"<<endl;
  31
+				cout<<"A :"<<alpha<<endl;
  32
+				cout<<"B :"<<beta<<endl;
  33
+				cout<<"Depth "<<depth<<" Result "<<alpha<<endl;
  34
+				return alpha;
  35
+			}
  36
+			cnt++;
  37
+			boost::this_thread::sleep(boost::posix_time::seconds(2));
34 38
 		}
  39
+		cout<<"Depth "<<depth<<" Result "<<alpha<<endl;
35 40
 		return alpha;
36 41
 	} else {
37 42
 		cout<<"False"<<endl;
38  
-		beta = min(beta, process(node->getnode(), alpha, beta, depth - 1, !flag));
39  
-		cout<<"Alpha :"<<alpha<<endl;
40  
-		cout<<"Beta :"<<beta<<endl;
41  
-		if (alpha >= beta) {
42  
-			cout<<"Alpha cut"<<endl;
43  
-			cout<<"A :"<<alpha<<endl;
44  
-			cout<<"B :"<<beta<<endl;
  43
+		int cnt = 1;
  44
+		while (cnt < degree) {
  45
+			beta = min(beta, process(node->getnode(), alpha, beta, depth - 1, !flag));
  46
+			if (alpha >= beta) {
  47
+				cout<<"Alpha cut"<<endl;
  48
+				cout<<"A :"<<alpha<<endl;
  49
+				cout<<"B :"<<beta<<endl;
  50
+				cout<<"Depth "<<depth<<" Result "<<beta<<endl;
  51
+				return beta;
  52
+			}
  53
+			cnt++;
  54
+			boost::this_thread::sleep(boost::posix_time::seconds(2));
45 55
 		}
  56
+		cout<<"Depth "<<depth<<" Result "<<beta<<endl;
46 57
 		return beta;
47 58
 	}
48 59
 }
3  src/Algorithms/AlphaBeta/AlphaBeta.h
@@ -9,6 +9,8 @@
9 9
 #define ALPHABETA_H_
10 10
 
11 11
 #include "ABNode.h"
  12
+#include <boost/thread/thread.hpp>
  13
+#include <boost/thread/xtime.hpp>
12 14
 #include <iostream>
13 15
 using namespace std;
14 16
 
@@ -22,6 +24,7 @@ class AlphaBeta {
22 24
 	inline int max(int, int);
23 25
 	inline int min(int, int);
24 26
 private:
  27
+	static const int degree = 2;
25 28
 	int alpha;
26 29
 	int beta;
27 30
 	int depth;
4  src/main.cpp
@@ -45,11 +45,11 @@ int main(void) {
45 45
 
46 46
 	int alpha = -1000;
47 47
 	int beta = 1000;
48  
-	int depth = 5;
  48
+	int depth = 3;
49 49
 
50 50
 	op::AlphaBeta ab;
51 51
 	op::ABNode *startNode = new op::ABNode();
52  
-	ab.process(startNode, alpha, beta, depth, true);
  52
+	cout<<"Result : "<<ab.process(startNode, alpha, beta, depth, true)<<endl;
53 53
 
54 54
 	return 0;
55 55
 }

0 notes on commit aa8da60

Please sign in to comment.
Something went wrong with that request. Please try again.