-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
97 lines (78 loc) · 2.47 KB
/
Copy pathmain.cpp
File metadata and controls
97 lines (78 loc) · 2.47 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
//
// main.cpp
// Chess
//
// Created by mustafa tok on 26.11.2011.
//
#include <iostream>
#include "Board.h"
#include "Iterators.h"
#include "Component.h"
#include "AlphaBeta.h"
#include "MiniMax.h"
int main (int argc, const char * argv[])
{
int choice,level;
cout << "1. Minimax Algorithm" << endl;
cout << "2. Alpha-Beta Pruning" << endl;
cout << "3. Exit" << endl;
cin >> choice;
cout << "Enter a level : ";
cin >> level;
if(choice == 3){
exit(0);
}
Board* chessboard = new Board();
int turn = WHITE;
chessboard->draw();
while(1){
if(chessboard->isFinished()) break;
int x, y, z, t;
Point p1,p2;
cin >> x >> y >> z >> t;
if(x == -1 || y == -1 || z == -1 || t == -1) break;
if(x >=0 && y >= 0 && z >= 0 && t >= 0){
p1.setX(x);
p1.setY(y);
p2.setX(z);
p2.setY(t);
if(chessboard->getComponent(x, y)->isWhite() && turn == WHITE){
if(chessboard->controlAndMoveComponent(p1,p2))
turn = BLACK;
}else if(chessboard->getComponent(x, y)->isBlack() && turn == BLACK){
if(chessboard->controlAndMoveComponent(p1,p2))
turn = WHITE;
}
}
if(turn == BLACK){
Board* tmp = chessboard;
clock_t t1,t2;
chessboard->draw();
t1 = clock();
if(choice == 1){
chessboard = MinimaxDecision(chessboard, BLACK, t1);
}else if(choice == 2){
chessboard = PruningDecision(chessboard, BLACK, level, t1);
}
t2 = clock();
cout << ((float)t2 - (float)t1) / 1000000.0F << "Seconds" << endl;
/*
while (!chessboard->isFinished()) {
chessboard = PruningDecision(chessboard, BLACK, t1);
chessboard->draw();
if(chessboard->isFinished()){
cout<<"Black Wins"<<endl;
break;
}
chessboard = PruningDecisionW(chessboard, WHITE , t1);
chessboard->draw();
if(chessboard->isFinished())
cout<<"White Wins"<<endl;
}*/
delete tmp;
turn = WHITE;
}
chessboard->draw();
}
return 0;
}