-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathPos.cpp
More file actions
268 lines (215 loc) · 4.94 KB
/
Copy pathPos.cpp
File metadata and controls
268 lines (215 loc) · 4.94 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
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
// Pos.cpp: implementation of the Pdb class.
//
//////////////////////////////////////////////////////////////////////
#include <stdio.h>
#include "stdafx.h"
#include "RenLib.h"
#include "Pos.h"
#include "MoveList.h"
#include "MoveNode.h"
#include "Utils.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//--------------------------------------------------------------------
// const
//--------------------------------------------------------------------
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
Pos::Pos()
{
}
//------------------------------------------------------------------------
Pos::~Pos()
{
}
//------------------------------------------------------------------------
Game& Pos::getGame()
{
return m_Game;
}
//------------------------------------------------------------------------
CString Pos::getFilePath()
{
return m_strFilePath;
}
//------------------------------------------------------------------------
bool Pos::Open(const CString& strFile)
{
CFileException e;
if (m_file.Open( strFile, CFile::modeRead, &e) == 0)
{
return false;
}
m_strFilePath = m_file.GetFilePath();
return true;
}
//------------------------------------------------------------------------
bool Pos::Read()
{
m_Game.clear();
UINT nBytesRead = m_file.Read(m_buffer, BUFFERSIZE);
if (nBytesRead == 0 || m_buffer[0] == 0 || m_buffer[0] > 225)
{
return false;
}
for (int i = 1; i <= m_buffer[0]; i++)
{
int index = (m_buffer[i] / 15) * 16 + m_buffer[i] % 15 + 1;
m_Game.addPos(BYTE(index));
}
addZjrenjuComments();
return true;
}
//------------------------------------------------------------------------
void Pos::addZjrenjuComments()
{
CString fileName(m_file.GetFileTitle());
int index[6];
int last = 0;
int NoOfDelimiters = 0;
for (int i=0; i<5; i++)
{
index[i] = fileName.Find('#', last);
last = index[i] + 1;
if (index[i] != -1)
{
NoOfDelimiters++;
}
else
{
break;
}
}
int first = 0;
if (NoOfDelimiters == 5)
{
index[5] = fileName.ReverseFind('.');
CString info[6];
for (i=0; i<6; i++)
{
last = index[i];
info[i] = fileName.Mid(first, last-first);
first = last + 1;
}
CString strTableNumber("Table: " + info[0]);
CString strRule("Rule: ");
if (info[1] == "0")
{
strRule += "Sakata";
}
else if (info[1] == "1")
{
strRule += "RIF";
}
else if (info[1] == "2")
{
strRule += "Two swap";
}
CString strBlack(info[2]);
CString strWhite(info[3]);
CString strSwap("Swap: ");
if (info[1] == "0" || info[1] == "1")
{
if (info[4] == "0")
{
strSwap += "No swap";
}
else if (info[4] == "1")
{
strSwap += "Swap";
}
}
else if (info[1] == "2")
{
if (info[4] == "0")
{
strSwap += "No swap | No swap";
}
else if (info[4] == "1")
{
strSwap += "Swap | No swap";
}
else if (info[4] == "2")
{
strSwap += "No swap | Swap";
}
else if (info[4] == "3")
{
strSwap += "Swap | Swap";
}
}
CString strResult(strBlack + " - " + strWhite + " ");
CString strState("State: ");
if (info[5] == "0")
{
strState += "Active";
}
else if (info[5] == "1")
{
strState += "Forbidden point";
strResult += "0-1";
}
else if (info[5] == "2")
{
strState += "Draw";
strResult += "0.5-0.5";
}
else if (info[5] == "3")
{
strState += "Black won";
strResult += "1-0";
}
else if (info[5] == "4")
{
strState += "White won";
strResult += "0-1";
}
else if (info[5] == "5")
{
strState += "White resign";
strResult += "1-0";
}
else if (info[5] == "6")
{
strState += "Black resign";
strResult += "0-1";
}
else if (info[5] == "7")
{
strState += "White untime";
}
else if (info[5] == "8")
{
strState += "Black untime";
}
m_Game.addOneLineComment(m_Game.numberOfMoves(), strResult);
m_Game.addMultiLineComment(m_Game.numberOfMoves(), strTableNumber);
m_Game.addMultiLineComment(m_Game.numberOfMoves(), strRule);
m_Game.addMultiLineComment(m_Game.numberOfMoves(), strSwap);
m_Game.addMultiLineComment(m_Game.numberOfMoves(), strState);
}
}
//------------------------------------------------------------------------
bool Pos::Save(const CString& fileName, const MoveList& aMoveList)
{
if (!m_file.Open(fileName, CFile::modeCreate | CFile::modeWrite | CFile::typeBinary))
{
CString strMessage(Utils::GetString(IDS_MSG_OPEN_FILE, fileName));
Utils::ShowMessage(strMessage, Utils::GetString(IDS_CAP_CREATE_POS), MB_ICONERROR);
return false;
}
m_buffer[0] = 0;
for(int i= 1; i <= aMoveList.Index(); i++)
{
CPoint Coord(aMoveList.Get(i)->getPos());
m_buffer[++m_buffer[0]] = BYTE((Coord.y - 1) * 15 + Coord.x - 1);
}
m_file.Write(m_buffer, m_buffer[0] + 1);
m_file.Close();
return(true);
}
//------------------------------------------------------------------------