-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
126 lines (105 loc) · 2.87 KB
/
main.cpp
File metadata and controls
126 lines (105 loc) · 2.87 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
#include <cstdio>
#include <cstdlib>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
#include "board.h"
#include "magic.h"
#include "pieces.h"
#include "opendb.h"
#include "evaluation.h"
#include "engine.h"
#include "acn.h"
#include "xboard.h"
char* getCmdOption(char **begin, char **end, const std::string &option)
{
char **itr = find(begin, end, option);
if (itr != end && ++itr != end) {
return *itr;
}
return 0;
}
void terminal_or_xboard(int normal_max_depth)
{
Board board;
board.InitChessboard();
int opponent = 0;
char com[128];
printf("Choose a color (0 - white, 1 - black)\n"); // '\n' must exist for xboard
gets(com);
// if we don't recieve a color, then turn to xboard mode!
if (!sscanf(com, "%d", &opponent)) {
XPlay(normal_max_depth, board);
return;
}
printf("Enter the move in ACN format:\n");
printf("You can exit the program with \"quit\"\n");
board.PrintBoard();
Openings Op;
Op.InitOpenings("openings.bk");
int moveNr = 1;
while (board.check != MATE) {
Move m;
if (board.player == opponent) {
gets(com);
if (strcmp(com, "quit") == 0) break;
if (strcmp(com, "q") == 0) break;
m = DecodeACN(com, board);
}
else {
moveNr += 2;
m = Op.GetMoveFromDB(board);
if (m.flags != ERROR) {
#ifdef DEBUG
printf("Mutarea a fost gasita in baza de date\n");
printf("%c%d -> %c%d\n", 'h'-m.source%8, m.source/8+1, 'h'-m.destination%8, m.destination/8+1);
#endif
}
else {
int tstart = clock();
int score = 0;
int max_depth = normal_max_depth;
if (moveNr < 8) {
max_depth = max_depth + 1;
}
if (board.GetPieceCount() < 11) {
max_depth = max_depth + 1;
}
//vector<Move> moves;
//score = NegaMaxD(moves, board, max_depth, 0);
//score = NegaMax(board, max_depth);
//score = AlphaBeta(board, max_depth);
score = IDDFS(board, max_depth);
//score = AlphaBetaD(moves, board);
printf("BestMove has score %d - calc in %.3fs\n", score, (double)(clock() - tstart) / CLOCKS_PER_SEC);
m = BestMove;
//for (int i=0; i<moves.size(); ++i)
// printf("%c%d -> %c%d\n", 'h'-moves[i].source%8, moves[i].source/8+1, 'h'-moves[i].destination%8, moves[i].destination/8+1);
}
string enc = EncodeACN(m, board);
printf("move %s\n", enc.c_str());
}
if (!(m.flags & ERROR)) {
board.MakeMove(m);
board.player = !board.player;
}
board.PrintBoard();
}
}
int main(int argc, char* argv[])
{
#ifndef NORAND
srand(time(NULL));
#endif
initmagicmoves();
initPieces();
InitHash();
int default_max_depth = 7;
char *default_max_depth_char = getCmdOption(argv, argv + argc, "--depth");
if (default_max_depth_char) {
default_max_depth = std::atoi(default_max_depth_char);
}
terminal_or_xboard(default_max_depth);
return 0;
}