forked from JayfonLin/chessserver
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsearch_engine.cpp
More file actions
110 lines (92 loc) · 2.13 KB
/
Copy pathsearch_engine.cpp
File metadata and controls
110 lines (92 loc) · 2.13 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
/*
Created on 2015-09-04
@author:jeff
*/
#include "search_engine.h"
int CSearchEngine::MakeMove(CHESS_MOVE move){
int chess_id;
int sq_src = CChessUtil::Src(move.m_move);
int sq_dst = CChessUtil::Dst(move.m_move);
chess_id = m_cur_position[sq_dst];
if (m_cur_position[sq_src] == 0){
cout << "source should have chess!" << endl;
}
m_cur_position[sq_dst] = m_cur_position[sq_src];
m_cur_position[sq_src] = 0;
move.m_chess_id = chess_id;
return chess_id;
}
void CSearchEngine::SetBestMove(CHESS_MOVE move){
m_best_move = move;
}
CHESS_MOVE CSearchEngine::GetBestMove(){
return m_best_move;
}
void CSearchEngine::SetSearchDepth(int depth){
m_search_depth = depth;
}
void CSearchEngine::SetEvaluator(CEvaluator* evaluator){
m_evaluator = evaluator;
}
void CSearchEngine::SetMoveGenerator(CMoveGenerator* generator){
m_move_generator = generator;
}
CSearchEngine::CSearchEngine(){
m_search_depth = DEFAULT_SEARCH_DEPTH;
m_evaluator = new CEvaluator();
m_move_generator = new CMoveGenerator();
InitMoveList();
}
CSearchEngine::~CSearchEngine(){
delete m_move_generator;
delete m_evaluator;
/*
for (int i = 0; i < 10; ++i){
for (int j = 0; j < 80; ++j){
delete m_move_list[i][j];
}
}
*/
}
void CSearchEngine::InitMoveList(){
/*
for (int i = 0; i < 10; ++i){
for (int j = 0; j < 80; ++j){
m_move_list[i][j] = new CHESS_MOVE();
}
}
*/
}
void CSearchEngine::UnmakeMove(CHESS_MOVE move, int chess_id){
int sq_src = CChessUtil::Src(move.m_move);
int sq_dst = CChessUtil::Dst(move.m_move);
m_cur_position[sq_src] = m_cur_position[sq_dst];
m_cur_position[sq_dst] = chess_id;
}
int CSearchEngine::IsGameOver(int squares[], int depth){
int i;
bool red_live = false, black_live = false;
for (i = 0; i < BOARD_NUMBER; ++i){
if (!CChessUtil::InFort(i)){
continue;
}
if (squares[i] == R_KING){
red_live = true;
}
if (squares[i] == B_KING){
black_live = true;
}
}
i = (m_max_depth - depth + 1) % 2;
if (!red_live)
if (i != 0)
return LOSS_SCORE + depth;
else
return -LOSS_SCORE - depth;
if (!black_live)
if (i != 0)
return -LOSS_SCORE - depth;
else
return LOSS_SCORE + depth;
return 0;
}