-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
71 lines (66 loc) · 2.11 KB
/
main.cpp
File metadata and controls
71 lines (66 loc) · 2.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#include "functions.h"
#include "parallel_alpha_beta.h"
#include <iostream>
#include <cstdlib>
#include <climits>
#include <sys/time.h>
#include <ctime>
using namespace std;
int main(int argc, char** argv){
//struct timeval tv1, tv2, tv3;
clock_t t1;
int type = atoi(argv[1]), depth = atoi(argv[1]), b_factor = atoi(argv[2]), value;
node *root = NULL;
srand(time(NULL));
//cout << "Input search type, search tree depth, and branching factor respectively\n";
//cin >> type >> depth >> b_factor;
//gettimeofday(&tv1, NULL);
t1 = clock();
//param* var = new param(depth, b_factor, root, true);
//paragenerateSearchTree(var);
//root = var->root;
root = generateSearchTree(depth, b_factor, root);
//gettimeofday(&tv2, NULL);
t1 = clock()-t1;
cout << "Generate search tree:" <<(double) t1<<endl;
t1 = clock();
value = MinMax(root, INT_MIN+1, INT_MAX);
/*switch(type){
case 0:
value = MinMax(root, INT_MIN+1, INT_MAX);
break;
case 1:
value = AlphaBeta(root, INT_MIN, INT_MAX, true);
break;
case 2:
value = paraAlphaBeta(root, b_factor);
break;
default:
break;
}*/
//gettimeofday(&tv3, NULL);
t1 = clock()-t1;
cout<<"Run time:"<<(double)t1<<' '<<"value:"<<value<<endl;
t1 = clock();
value = AlphaBeta(root, INT_MIN, INT_MAX, true);
t1 = clock()-t1;
cout<<"AlphaBeta runtime:"<<(double)t1<<' '<<"value:"<<value<<endl;
t1 = clock();
value = paraAlphaBeta(root, b_factor);
t1 = clock()-t1;
cout<<"paraAlphaBeta runtime:"<<(double)t1<<' '<<"value:"<<value<<endl;
node* idx = root->children;
if (root->children == 0)
return root->min_or_max ? root->value : root->value * (-1);
int num_of_thread = 2;//b_factor <= 5 ? b_factor-1 : 4;
int* result = new int[num_of_thread];
pthread_t thr[num_of_thread];
alphabeta* t[num_of_thread];
for (int i = 0; i < num_of_thread; i++)
t[i] = new alphabeta(idx, result, b_factor, num_of_thread, i);
t1 = clock();
value = newparaAlphaBeta(root, b_factor, num_of_thread, result, thr, t);
t1 = clock()-t1;
cout<<"paraAlphaBeta2 runtime:"<<(double)t1<<' '<<"value:"<<value<<endl;
return 0;
}