-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsolverab.h
72 lines (58 loc) · 1.34 KB
/
solverab.h
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
#pragma once
//An Alpha-beta solver, single threaded with an optional transposition table.
#include "solver.h"
class SolverAB : public Solver {
struct ABTTNode {
hash_t hash;
char value;
ABTTNode(hash_t h = 0, char v = 0) : hash(h), value(v) { }
};
public:
bool scout;
int startdepth;
ABTTNode * TT;
uint64_t maxnodes, memlimit;
SolverAB(bool Scout = false) {
scout = Scout;
startdepth = 2;
TT = NULL;
set_memlimit(100*1024*1024);
}
~SolverAB() { }
void set_board(const Board & board, bool clear = true){
rootboard = board;
reset();
}
void move(const Move & m){
rootboard.move(m);
reset();
}
void set_memlimit(uint64_t lim){
memlimit = lim;
maxnodes = memlimit/sizeof(ABTTNode);
clear_mem();
}
void clear_mem(){
reset();
if(TT){
delete[] TT;
TT = NULL;
}
}
void reset(){
outcome = -3;
maxdepth = 0;
nodes_seen = 0;
time_used = 0;
bestmove = Move(M_UNKNOWN);
timeout = false;
}
void solve(double time);
//return -2 for loss, -1,1 for tie, 0 for unknown, 2 for win, all from toplay's perspective
int negamax(const Board & board, const int depth, int alpha, int beta);
int negamax_outcome(const Board & board, const int depth);
int tt_get(const hash_t & hash);
int tt_get(const Board & board);
void tt_set(const hash_t & hash, int val);
void tt_set(const Board & board, int val);
};