-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathGameEnds.cpp
More file actions
200 lines (177 loc) · 6.71 KB
/
Copy pathGameEnds.cpp
File metadata and controls
200 lines (177 loc) · 6.71 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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
#include "stdafx.h"
#include "data.h"
#include "chess.h"
#include "Resource.h"
#include "pregen.h"
void //½áÊøµ±Ç°ÓÎÏ·
GameEnds(dispboard_t* pDis, ChessMove result,TCHAR *resultDetails,int whosays){
GameMode nextGameMode;
int isIcsGame;
TCHAR buf[MSG_SIZ];
#ifdef DEBUG_USE_DEBUG_FILE
//if (appData.debugMode) {
fprintf(appData.debugFP, "GameEnds(%d, %s, %d)\n",
result, resultDetails ? resultDetails : "(null)", whosays);
//}
#endif
// backend.cpp(261): if(cps->cps_stat == Cps_Thinking || cps->cps_stat == Cps_Pondering || cps->cps_stat == Cps_Analyse){
ChessProgramState *cps = &pDis->first;
if(cps->cps_stat == Cps_Thinking || cps->cps_stat == Cps_Pondering || cps->cps_stat == Cps_Analyse){
SendToProgram(L"stop\n", cps);
Sleep(100);
SendToProgram(L"stop\n", cps);
Sleep(100);
cps->playWhat = NEUTRAL;
ChangeGameMode(pDis, GameNoneMode);
SendMessage(hwndToolBar,TB_CHECKBUTTON,IDT_COM_RED, 0);
}
/* If we're loading the game from a file, stop */
if (whosays == GE_FILE) { //GAME END FROM FIE
(void) StopLoadGameTimer(pDis);
//MAIN.gameFileFP = NULL;
}
/* Cancel draw offers */
pDis->first.offeredDraw = 0;
/* If this is an ICS game, only ICS can really say it's done;
if not, anyone can. */
isIcsGame = (pDis->gameMode == IcsPlayingWhite || pDis->gameMode == IcsPlayingBlack ||
pDis->gameMode == IcsObserving || pDis->gameMode == IcsExamining);
if (!isIcsGame || whosays == GE_ICS) {
/* OK -- not an ICS game, or ICS said it was done */
StopClocks(pDis);
/* if (!isIcsGame && !pDis->noChessProgram){*/
if (!isIcsGame ){
SetUserThinkingEnables();
}
if (resultDetails != NULL) {
//gameInfo.result = result;
//DIS.pgn.cmresult = result;
//gameInfo.resultDetails = StrSave(resultDetails);
//StringCbPrintf(DIS.pgn.resultDetails,sizeof(DIS.pgn.resultDetails),resultDetails);
/* Tell program how game ended in case it is learning */
if (pDis->gameMode == MachinePlaysWhite ||
pDis->gameMode == MachinePlaysBlack ||
pDis->gameMode == IcsPlayingWhite ||
pDis->gameMode == IcsPlayingBlack ||
pDis->gameMode == BeginningOfGame)
{
//char buf[MSG_SIZ];
//sprintf(buf, "result %s {%s}\n", PGNResult(result),resultDetails);
//StringCbPrintf(buf,MSG_SIZ,"result %s {%s}\n", PGNResult(result),resultDetails);
//if (DIS.first.pr != NoProc) {
// SendToProgram(buf, &DIS.first);
//}
//if (DIS.second.pr != NoProc &&DIS.gameMode == TwoMachinesPlay) {
// SendToProgram(buf, &DIS.second);
//}
}
if (pDis->pos->gply != 0) {/*if (DIS.forwardMostMove != 0) {*/
if (pDis->gameMode != PlayFromGameFile && pDis->gameMode != EditGame ) { //&& ThStat.isLearn == FALSE
//if (*appData.saveGameFile != NULLCHAR) {
// SaveGameToFile(appData.saveGameFile, TRUE);
//}
//else if (appData.autoSaveGames) {
// AutoSaveGame();
//}
//if (*appData.savePositionFile != NULLCHAR) {
// SavePositionToFile(appData.savePositionFile);
//}
if(appData.autoSaveGames){
ThStat.isFillQk = TRUE;
AutoSaveGame(pDis);
ThStat.isFillQk = FALSE;
}
}
}
}
if (appData.icsActive) {
if (appData.quietPlay &&
(pDis->gameMode == IcsPlayingWhite ||
pDis->gameMode == IcsPlayingBlack)) {
//SendToICS(pDis->ics_prefix);
//SendToICS("set shout 1\n");
}
//nextGameMode = IcsIdle;
//pDis->ics_user_moved = FALSE;
/* clean up premove. It's ugly when the game has ended and the
* premove highlights are still on the board.
*/
if (pDis->gotPremove) {
pDis->gotPremove = FALSE;
ClearPremoveHighlights(pDis);
//DrawPosition(false,DIS.pos.B256dis[DIS.currentMove]);
DrawPosition(pDis,false,pDis->B256dis[pDis->pos->curStep]);
}
if (whosays == GE_ICS) {
switch (result) {
case WhiteWins:
if (pDis->gameMode == IcsPlayingWhite){
//PlayIcsWinSound();
}
else if (pDis->gameMode == IcsPlayingBlack){
//PlayIcsLossSound();
}
break;
case BlackWins:
if (pDis->gameMode == IcsPlayingBlack){
//PlayIcsWinSound();
}
else if (pDis->gameMode == IcsPlayingWhite){
//PlayIcsLossSound();
}
break;
case GameIsDrawn:
//PlayIcsDrawSound();
break;
default:{
//PlayIcsUnfinishedSound();
}
}
}
}
else if (pDis->gameMode == EditGame ||
pDis->gameMode == PlayFromGameFile ||
pDis->gameMode == AnalyzeMode ) {
nextGameMode = pDis->gameMode;
}
else {
nextGameMode = EndOfGame;
}
pDis->pausing = FALSE;
ModeHighlight();
}
else {
nextGameMode = pDis->gameMode;
}
if (pDis->first.reuse) {
/* Put first chess program into idle state */
if (pDis->first.pr != NoProc &&
( pDis->gameMode == MachinePlaysWhite || pDis->gameMode == MachinePlaysBlack
|| pDis->gameMode == IcsPlayingWhite
||pDis->gameMode == IcsPlayingBlack || pDis->gameMode == BeginningOfGame))
{
SendToProgram(L"force\n", &pDis->first);
if (pDis->first.usePing) {
swprintf_s(buf,128,(L"ping %d\n"), ++pDis->first.lastPing);
SendToProgram(buf, &pDis->first);
}
}
}
else if (result != GameUnfinished || nextGameMode == IcsIdle) {
/* Kill off first chess program */
if (pDis->first.isr != NULL){
RemoveInputSource(pDis->first.isr);
}
pDis->first.isr = NULL;
if (pDis->first.pr != NoProc) {
ExitAnalyzeMode();
SendToProgram(L"quit\n", &pDis->first);
DestroyChildProcess(pDis->first.pr, pDis->first.useSigterm);
}
pDis->first.pr = NoProc;
}
if (pDis->gameMode == AnalyzeMode)
ExitAnalyzeMode();
ChangeGameMode(pDis,nextGameMode);
ModeHighlight();
}