-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathengine.cpp
More file actions
136 lines (109 loc) · 3.05 KB
/
Copy pathengine.cpp
File metadata and controls
136 lines (109 loc) · 3.05 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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
/*
#include <vector>
#include <ctime>
#include <iomanip>
#include <algorithm>
#include <list>
#include "engine.h"
#include "bitboards.h"
#include "board.h"
#include "move.h"
using namespace std;
/*
void AddToList(list<MOVE> *l, MOVE m) {
for (list<MOVE>::iterator it=l->begin() ; it != l->end(); ++it) {
if(m.static_value > it->static_value ) {
l->insert(it, m);
return;
}
}
list<MOVE>::iterator it=l->end();
l->insert(it, m);
}
*/
/*
MOVE UCI_NegaMaxInit(int depth, CHESSBOARD game) {
// TODO:
// -By only checking legal moves at the root, the search can go down a psuedo-legal path and think it can do something that it can't.
//for record keeping:
double timer = clock()/(CLOCKS_PER_SEC/1000);
NODES = 0;
list<MOVE> move_list = MoveGen(&game);
MOVE best_move;
int max = -INFINITY;
//Only consider legal moves:
vector<MOVE> legal_move_list;
bool inCheck = isInCheck(game); // <---- this is a problem because the search will think that castling is legal and then later be told that it is not.
for (int i=0; i < move_list.size(); i++) {
if( isMoveLegal(game, move_list.at(i), inCheck) ) {
best_move = move_list.at(i); //to prevent no move being chosen.
legal_move_list.push_back( move_list.at(i) );
}
}
for (int i=0; i < legal_move_list.size(); i++) {
//Go through everything on the movelist:
CHESSBOARD subgame = game;
subgame.makemove(legal_move_list.at(i));
NODES++;
int score = -UCI_NegaMax (depth - 1, subgame);
if (score > max) {
max = score;
best_move = legal_move_list.at(i);
}
}
//UCI Info:
game.makemove(best_move);
int score = relative_eval(game);
timer = clock()/(CLOCKS_PER_SEC/1000) - timer;
int nps = (int)(NODES/timer)*1000;
cout << "info depth " << depth << " nodes " << NODES << " score cp " << score << " time " << timer << " nps " << nps << "\n";
return best_move;
}
int UCI_NegaMax(int depth, CHESSBOARD game) {
if(depth == 0) {
return relative_eval(game); }
vector<MOVE> move_list = MoveGen(&game);
int max = -INFINITY;
//Go through the legal move list:
for (int i=0; i < move_list.size(); i++) {
CHESSBOARD subgame = game;
subgame.makemove(move_list.at(i));
NODES++;
int score = -UCI_NegaMax(depth -1, subgame);
if(score > max) {
max = score;
}
}
return max;
}
*/
/*
int AlphaBeta(int depth, CHESSBOARD game, int alpha, int beta) {
if(depth == 0) {
int eval = relative_eval(game);
//cout << "player: " << game.getActivePlayer() << " d0: " << eval << endl;
return eval; }
vector<MOVE> move_list = MoveGen(&game);
bool foundPV = false;
for (int i=0; i < move_list.size(); i++) {
CHESSBOARD subgame = game;
subgame.makemove(move_list.at(i));
NODES++;
int score =0;
//PVS Addition:
if(foundPV) {
score = -UCI_AlphaBeta(depth -1, subgame, -alpha-1, -alpha);
if ( (score > alpha) && (score < beta) ) {
score = -UCI_AlphaBeta(depth-1, subgame, -beta, -alpha); }
}
else {
score = -UCI_AlphaBeta(depth -1, subgame, -beta, -alpha); }
if( score >= beta ) {
return beta; }
if(score > alpha) {
alpha = score;
}
}
return alpha;
}
*/