Skip to content

Commit 59d1f06

Browse files
authored
Merge pull request #114 from kobanium/ver-9.0
Refactoring
2 parents 55b2b54 + 8391ed7 commit 59d1f06

File tree

1 file changed

+31
-24
lines changed

1 file changed

+31
-24
lines changed

src/SgfExtractor.cpp

+31-24
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,21 @@
1010
// SGFの座標を数値に変換
1111
static int ParsePosition( const char c );
1212
// 盤の大きさの抽出
13-
static int GetSize( SGF_record_t *kifu, char *sgf_text, int cursor );
13+
static int GetSize( SGF_record_t *kifu, const char *sgf_text, const int cursor );
1414
// 結果の抽出
15-
static int GetResult( SGF_record_t *kifu, char *sgf_text, int cursor );
15+
static int GetResult( SGF_record_t *kifu, const char *sgf_text, const int cursor );
1616
// 着手の抽出
17-
static int GetMove( SGF_record_t *kifu, char *sgf_text, int cursor );
17+
static int GetMove( SGF_record_t *kifu, const char *sgf_text, const int cursor );
1818
// 置き石の数の抽出
19-
static int GetHandicaps( SGF_record_t *kifu, char *sgf_text, int cursor );
19+
static int GetHandicaps( SGF_record_t *kifu, const char *sgf_text, const int cursor );
2020
// 置き石の座標の抽出
21-
static int GetHandicapPosition( SGF_record_t *kifu, char *sgf_text, int cursor, int color );
21+
static int GetHandicapPosition( SGF_record_t *kifu, const char *sgf_text, const int cursor, const int color );
2222
// コミの抽出
23-
static int GetKomi( SGF_record_t *kifu, char *sgf_text, int cursor );
23+
static int GetKomi( SGF_record_t *kifu, const char *sgf_text, const int cursor );
2424
// 対局者の名前を抽出
25-
static int GetPlayerName( SGF_record_t *kifu, char *sgf_text, int cursor, int color );
25+
static int GetPlayerName( SGF_record_t *kifu, const char *sgf_text, const int cursor, const int color );
2626
// 無視する情報を飛ばす処理
27-
static int SkipData( SGF_record_t *kifu, char *sgf_text, int cursor );
27+
static int SkipData( SGF_record_t *kifu, const char *sgf_text, const int cursor );
2828

2929

3030
//////////////////
@@ -44,7 +44,8 @@ GetKifuMove( const SGF_record_t *kifu, const int n )
4444
////////////////////
4545
// 置き石の抽出 //
4646
////////////////////
47-
int GetHandicapStone( const SGF_record_t *kifu, const int n )
47+
int
48+
GetHandicapStone( const SGF_record_t *kifu, const int n )
4849
{
4950
if (kifu->handicap_x[n] == 0) {
5051
return PASS;
@@ -101,7 +102,6 @@ ExtractKifu( const char *file_name, SGF_record_t *kifu )
101102
memset(kifu->handicap_x, 0, sizeof(kifu->handicap_x));
102103
memset(kifu->handicap_y, 0, sizeof(kifu->handicap_y));
103104
memset(kifu->handicap_color, 0, sizeof(kifu->handicap_color));
104-
105105

106106
while ((cursor < 100000) && (sgf_text[cursor] != '\0')) {
107107
if (sgf_text[cursor] == '\n' ||
@@ -132,6 +132,8 @@ ExtractKifu( const char *file_name, SGF_record_t *kifu )
132132
// GetHandicaps : 置き石の個数の抽出
133133
// GetHandicapPosition : 置き石の座標
134134
// GetMove : 着手の抽出
135+
// GetKomi : コミの抽出
136+
// GetPlayerName : 対局者の名前の抽出
135137
if (strncmp(&sgf_text[cursor], "SZ[", 3) == 0) cursor = GetSize(kifu, sgf_text, cursor);
136138
if (strncmp(&sgf_text[cursor], "RE[", 3) == 0) cursor = GetResult(kifu, sgf_text, cursor);
137139
if (strncmp(&sgf_text[cursor], "HA[", 3) == 0) cursor = GetHandicaps(kifu, sgf_text, cursor);
@@ -169,21 +171,22 @@ ExtractKifu( const char *file_name, SGF_record_t *kifu )
169171
// 盤の大きさの抽出 //
170172
///////////////////////
171173
static int
172-
GetSize( SGF_record_t *kifu, char *sgf_text, int cursor )
174+
GetSize( SGF_record_t *kifu, const char *sgf_text, const int cursor )
173175
{
174176
int tmp_cursor = 3;
175177
char size[10];
176-
memset(size, 0, sizeof(char)*10);
178+
179+
memset(size, 0, sizeof(char) * 10);
177180

178-
while ((cursor+tmp_cursor < 100000) && (sgf_text[cursor + tmp_cursor] != ']')) tmp_cursor++;
181+
while ((cursor + tmp_cursor < 100000) && (sgf_text[cursor + tmp_cursor] != ']')) tmp_cursor++;
179182

180183
for (int i = 0; i < tmp_cursor - 3; i++) {
181184
if (cursor + i + 3 < 100000){
182185
size[i] = sgf_text[cursor + i + 3];
183186
}
184187
}
185188
kifu->board_size = atoi(size);
186-
while ((cursor+tmp_cursor < 100000) && (sgf_text[cursor + tmp_cursor] != ']')) tmp_cursor++;
189+
while ((cursor + tmp_cursor < 100000) && (sgf_text[cursor + tmp_cursor] != ']')) tmp_cursor++;
187190
return cursor + tmp_cursor;
188191
}
189192

@@ -192,10 +195,12 @@ GetSize( SGF_record_t *kifu, char *sgf_text, int cursor )
192195
// 結果の抽出 //
193196
/////////////////
194197
static int
195-
GetResult( SGF_record_t *kifu, char *sgf_text, int cursor )
198+
GetResult( SGF_record_t *kifu, const char *sgf_text, const int cursor )
196199
{
197200
int tmp_cursor = 3;
198-
while ((cursor+tmp_cursor < 100000) && (sgf_text[cursor + tmp_cursor] != ']')) tmp_cursor++;
201+
202+
while ((cursor + tmp_cursor < 100000) && (sgf_text[cursor + tmp_cursor] != ']')) tmp_cursor++;
203+
199204
if (cursor + 3 < 100000){
200205
switch (sgf_text[cursor + 3]) {
201206
case 'B':
@@ -212,7 +217,7 @@ GetResult( SGF_record_t *kifu, char *sgf_text, int cursor )
212217
break;
213218
}
214219
}
215-
while ((cursor+tmp_cursor < 100000) && (sgf_text[cursor + tmp_cursor] != ']')) tmp_cursor++;
220+
while ((cursor + tmp_cursor < 100000) && (sgf_text[cursor + tmp_cursor] != ']')) tmp_cursor++;
216221
return cursor + tmp_cursor;
217222
}
218223

@@ -221,9 +226,10 @@ GetResult( SGF_record_t *kifu, char *sgf_text, int cursor )
221226
// 着手の抽出 //
222227
/////////////////
223228
static int
224-
GetMove( SGF_record_t *kifu, char *sgf_text, int cursor )
229+
GetMove( SGF_record_t *kifu, const char *sgf_text, const int cursor )
225230
{
226231
int tmp_cursor = 0;
232+
227233
if (cursor + 3 < 100000){
228234
if (kifu->moves == 0) {
229235
if (sgf_text[cursor] == 'B') {
@@ -255,11 +261,12 @@ GetMove( SGF_record_t *kifu, char *sgf_text, int cursor )
255261
// 置き石の数の抽出 //
256262
///////////////////////
257263
static int
258-
GetHandicaps( SGF_record_t *kifu, char *sgf_text, int cursor )
264+
GetHandicaps( SGF_record_t *kifu, const char *sgf_text, const int cursor )
259265
{
260266
int tmp_cursor = 3;
261267
char handicaps[10] = {0};
262-
while ((cursor+tmp_cursor < 100000) && (sgf_text[cursor + tmp_cursor] != ']')) tmp_cursor++;
268+
269+
while ((cursor + tmp_cursor < 100000) && (sgf_text[cursor + tmp_cursor] != ']')) tmp_cursor++;
263270

264271
for (int i = 0; i < tmp_cursor - 3; i++) {
265272
if (cursor + i + 3 < 100000){
@@ -277,7 +284,7 @@ GetHandicaps( SGF_record_t *kifu, char *sgf_text, int cursor )
277284
// 置き石の座標の抽出 //
278285
/////////////////////////
279286
static int
280-
GetHandicapPosition( SGF_record_t *kifu, char *sgf_text, int cursor, int color )
287+
GetHandicapPosition( SGF_record_t *kifu, const char *sgf_text, const int cursor, const int color )
281288
{
282289
int tmp_cursor = 3;
283290
int handicaps = 0;
@@ -311,7 +318,7 @@ GetHandicapPosition( SGF_record_t *kifu, char *sgf_text, int cursor, int color )
311318
// コミの抽出 //
312319
//////////////////
313320
static int
314-
GetKomi( SGF_record_t *kifu, char *sgf_text, int cursor )
321+
GetKomi( SGF_record_t *kifu, const char *sgf_text, const int cursor )
315322
{
316323
int tmp_cursor = 3;
317324
char komi[10] = {0};
@@ -335,7 +342,7 @@ GetKomi( SGF_record_t *kifu, char *sgf_text, int cursor )
335342
// 対局名の抽出 //
336343
////////////////////
337344
static int
338-
GetPlayerName( SGF_record_t *kifu, char *sgf_text, int cursor, int color )
345+
GetPlayerName( SGF_record_t *kifu, const char *sgf_text, const int cursor, const int color )
339346
{
340347
int tmp_cursor = 0;
341348

@@ -363,7 +370,7 @@ GetPlayerName( SGF_record_t *kifu, char *sgf_text, int cursor, int color )
363370
// 無視する情報を飛ばす処理 //
364371
///////////////////////////////
365372
static int
366-
SkipData( SGF_record_t *kifu, char *sgf_text, int cursor )
373+
SkipData( SGF_record_t *kifu, const char *sgf_text, const int cursor )
367374
{
368375
int tmp_cursor = 3;
369376

0 commit comments

Comments
 (0)