3 AIDaniel::AIDaniel(Position
*p
) : position(p
), isInterrupted(false), cutoffDepth(DEFAULT_CUTOFF_DEPTH
) {
6 inline int AIDaniel::alphaBeta(Position
*pos
, int depth
, int alpha
, int beta
, bool max
) {
11 if ((depth
>= cutoffDepth
&& pos
->getNoisiness() < 50)
12 || depth
>= cutoffDepth
+ QUIESCENCE_SEARCH_MAX_ADDITIONAL_DEPTH
13 || pos
->isGameOver()) {
14 return pos
->evaluate();
17 for (unsigned int i
= 0; i
< pos
->getLegalMoves()->size(); ++i
) {
18 Position
child(pos
, i
);
19 beta
= std::min(beta
, alphaBeta(&child
, depth
+ 1, alpha
, beta
, !max
));
27 for (unsigned int i
= 0; i
< pos
->getLegalMoves()->size(); ++i
) {
28 Position
child(pos
, i
);
29 alpha
= std::max(alpha
, alphaBeta(&child
, depth
+ 1, alpha
, beta
, !max
));
38 int AIDaniel::getNextMove() {
39 isInterrupted
= false;
40 std::vector
<int> values
;
42 if (position
->isWhiteToMove()) {
43 for (unsigned int i
= 0; i
< position
->getLegalMoves()->size(); ++i
) {
44 Position
child(position
, i
);
45 values
.push_back(alphaBeta(&child
, 1, std::numeric_limits
<int>::min(),std::numeric_limits
<int>::max(),true));
46 //std::cout << "white: " << i << " " << values.at(i) << " " << position->getLegalMoves()->at(i) << std::endl;
48 int max
= std::numeric_limits
<int>::min();
49 for (unsigned int i
= 0; i
< values
.size(); ++i
) {
50 if (max
< values
.at(i
)) {
57 for (unsigned int i
= 0; i
< position
->getLegalMoves()->size(); ++i
) {
58 Position
child(position
, i
);
59 values
.push_back(alphaBeta(&child
, 1, std::numeric_limits
<int>::min(),std::numeric_limits
<int>::max(),false));
60 //std::cout << "black: " << i << " " << values.at(i) << " " << position->getLegalMoves()->at(i) << std::endl;
62 int min
= std::numeric_limits
<int>::max();
63 for (unsigned int i
= 0; i
< values
.size(); ++i
) {
64 if (min
> values
.at(i
)) {
70 bestMove
= position
->getLegalMoves()->at(best
);
71 position
->move(bestMove
, 0);
75 void AIDaniel::setPosition(Position
*p
) {
80 void AIDaniel::interrupt()
85 void AIDaniel::setCutoffDepth(int cutoffDepth
)
87 this->cutoffDepth
= cutoffDepth
;
90 AIDaniel::~AIDaniel() {