40 return 8 * ((x - 11) / 10) + ((x - 11) % 10);
51 return 10 * (x / 8) + (x % 8) + 11;
64 static const char oko_to_edax[]={
75 return oko_to_edax[x & 0x3f];
89 memcpy(game->
name[0], name, 2);
90 memcpy(game->
name[1], name, 2);
120 && strcmp(game_1->
name[0], game_2->
name[0]) == 0 && strcmp(game_1->
name[1], game_2->
name[1]) == 0) {
121 for (i = 0; i < 60; ++i) {
122 if (game_1->
move[i] != game_2->
move[i])
return false;
140 for (i = 0; i < 60; ++i) {
141 if (game_1->
x[i] != game_2->
x[i])
return false;
200 for (i = 0; i < ply; i++) {
219 for (i = 0; i < 60 && game->
move[i] !=
NOMOVE; ++i) {
235 int n_discs_p, n_discs_o, n_empties;
236 int i, player, score;
241 for (i = 0; i < 60 && game->
move[i] !=
NOMOVE; ++i) {
252 n_empties = 64 - n_discs_p - n_discs_o;
253 score = n_discs_p - n_discs_o;
255 if (score < 0) score -= n_empties;
256 else if (score > 0) score += n_empties;
258 if (player == game->
player)
return score;
277 for (i = 0; i < 60 && *line;) {
279 if (s == line && move->
x ==
NOMOVE)
return;
280 if (move->
x !=
PASS) {
282 game->
move[i++] = move->
x;
298 for (i = 0; i < 60 && game->
move[i] !=
NOMOVE; i++) {
320 for (i = 0; i < 60; i++) {
347 for (i = 0; i < 60; i++) {
370 for (i = 0; i < 60; i++) {
394 for (i = 0, j = from; i < line->
n_moves && j < 60; ++i) {
442 fwrite(game,
sizeof (
Game), 1, f);
469 char s_game[128], s_board[80];
475 fprintf(f,
"%s;", s_board);
478 fprintf(f,
"%s\n", s_game);
533 tag[0] = tag[1] = tag[2] =
'\0';
536 for (i = 0; i < 3; i++) {
539 else if (c==
' ' || c==
'\n' || c==
'\r' || c==
'\t') {
543 else if (c ==
'[')
break;
544 else if (
'A' <= c && c <=
'Z') tag[i] = (char)c;
545 else if (i == 0 && (c ==
'(' || c ==
';')) {
548 if ((tag[0] ==
'(' && c ==
';') || (tag[0] ==
';' && c ==
')')) {
558 for (i = 0; i < 1000; i++) {
562 value[i] = tolower(c);
584 char tag[4], value[1000];
589 if (strcmp(tag,
"(;") == 0) {
591 if (strcmp(tag,
";)")==0) {
593 warn(
"error while importing a GGF game\n");
597 if (strcmp(tag,
"GM") == 0 && strcmp(value,
"othello") != 0)
break;
598 if (strcmp(tag,
"BO") == 0) {
599 if (value[0] !=
'8')
break;
601 }
else if (strcmp(tag,
"PB") == 0) {
604 }
else if (strcmp(tag,
"DT") == 0) {
606 sscanf(value,
"%d.%d.%d_%d:%d:%d", v, v + 1, v + 2, v + 3, v + 4, v + 5);
609 }
else if (strcmp(tag,
"PW") == 0) {
612 }
else if (i < 60 && (strcmp(tag,
"B") == 0 || strcmp(tag,
"W") == 0)) {
613 if (strncmp(
"pa", value, 2) == 0)
continue;
632static const char*
parse_tag(
const char *
string,
char *tag,
char *value)
638 if ((s[0] ==
'(' && s[1] ==
';') || (s[0] ==
';' && s[1] ==
')')) {
641 tag[2] = *value =
'\0';
643 n = 3;
while (*s && *s !=
'[' && n--) *tag++ = toupper(*s++);
647 n = 255;
while (*s && *s !=
']' && n--) *value++ = tolower(*s++);
666 const char *s = string;
668 char tag[4], value[256];
673 while ((next =
parse_tag(s, tag, value)) != s && strcmp(tag,
"(;") != 0) s = next;
675 if (strcmp(tag,
"(;") == 0) {
677 while ((next =
parse_tag(s, tag, value)) != s && strcmp(tag,
";)") != 0) {
680 if (strcmp(tag,
"GM") == 0 && strcmp(value,
"othello") != 0) {
683 }
else if (strcmp(tag,
"BO") == 0) {
684 if (value[0] !=
'8') {
689 }
else if (strcmp(tag,
"PB") == 0) {
692 }
else if (strcmp(tag,
"PW") == 0) {
695 }
else if (i < 60 && (strcmp(tag,
"B") == 0 || strcmp(tag,
"W") == 0)) {
696 if (strncmp(
"pa", value, 2) == 0)
continue;
717 static const char board_color[] =
"*O-?";
721 static const char move_color[] =
"BW";
722 char move_string[3] =
"xx";
724 fputs(
"(;GM[othello]PC[Edax]", f);
731 for (x = 0; x < 64; ++x) {
734 putc(board_color[square], f);
if ((x & 7) == 7) putc(
' ', f);
736 putc(board_color[(
int) game->
player], f); fputc(
']', f);
740 for (i = 0; i < 60 && game->
move[i] !=
NOMOVE; ++i) {
742 fprintf(f,
"%c[PA]", move_color[player]);
746 fprintf(f,
"%c[%s]", move_color[player],
move_to_string(game->
move[i], 0, move_string));
766 tag[0] = tag[1] = tag[2] =
'\0';
769 for (i = 0; i < 3; i++) {
771 if (c == EOF)
return 0;
772 else if (c ==
' ' || c ==
'\n' || c ==
'\r' || c ==
'\t' || c ==
';') {
776 else if (c ==
'[')
break;
777 else if (
'A' <= c && c <=
'Z') tag[i] = (char)c;
778 else if (i == 0 && (c ==
'(' || c ==
')')) {
786 if (c !=
'[')
return 0;
789 for (i = 0; i < 1000; i++) {
791 if (c == EOF)
return 0;
795 if (c == EOF)
return 0;
800 if (c !=
']')
return 0;
805 if (c == EOF)
return 0;
808 if (c == EOF)
return 0;
825 char tag[4], value[1000];
826 int i = 0, level = 1;
830 if (strcmp(tag,
"(") == 0) {
832 if (strcmp(tag,
"(") == 0) level++;
833 if (strcmp(tag,
")") == 0) {
836 warn(
"error while importing a SGF game\n");
840 if (strcmp(tag,
"GM") == 0 && strcmp(value,
"2") != 0)
break;
841 if (strcmp(tag,
"SZ") == 0 && strcmp(value,
"8") != 0)
break;
842 if (strcmp(tag,
"PB") == 0) {
845 }
else if (strcmp(tag,
"PW") == 0) {
848 }
else if (i < 60 && (strcmp(tag,
"B") == 0 || strcmp(tag,
"W") == 0)) {
856 if (strcmp(tag,
"(") == 0) level++;
857 if (strcmp(tag,
")") == 0) level--;
874 static const char color[2] = {
'B',
'W'};
877 time_t t = time(NULL);
878 struct tm *date = localtime(&t);
879 unsigned long long black, white;
884 if (multiline) fputc(
'\n',f);
885 fputs(
"PC[Edax]", f);
886 fprintf(f,
"DT[%04d-%02d-%02d]", 1900 + date->tm_year, 1 + date->tm_mon, date->tm_mday);
887 if (multiline) fputc(
'\n',f);
889 if (multiline) fputc(
'\n',f);
902 for (i =
A1; i <=
H8; i++){
908 for (i =
A1; i <=
H8; i++){
912 fprintf(f,
"PL[%c]", color[(
int) game->
player]);
913 if (multiline) fputc(
'\n', f);
917 if (score > 0) fprintf(f,
"RE[%c%+d]", color[(
int) game->
player], score);
918 else if (score < 0) fprintf(f,
"RE[%c%+d]", color[(
int) !game->
player], -score);
919 else fputs(
"RE[0]", f);
921 fputs(
"RE[Void]", f);
923 if (multiline) fputc(
'\n', f);
928 for (i = 0; i < 60 && game->
move[i] !=
NOMOVE; ++i) {
930 fprintf(f,
"%c[PA];", color[player]);
932 if (multiline && player == game->
player) fputc(
'\n', f);
937 if (multiline && player == game->
player) fputc(
'\n', f);
957 int c, state, i, j, k, n;
958 char move[5] =
"--\0\0";
959 int score[2] = {0, 0};
960 char info_tag[257] =
"", info_value[257] =
"";
962 const int info_size = 256;
982 while(state != STATE_END_GAME) {
986 state = STATE_END_GAME;
987 }
else if (c ==
'{') {
990 }
while(c != EOF && c !=
'}');
991 }
else if (c ==
'[') {
995 state = STATE_BEGIN_INFO;
999 case STATE_END_SCORE:
1001 state = STATE_END_GAME;
1004 warn(
"unexpected '['");
1006 }
else if (c ==
']') {
1008 case STATE_END_VALUE:
1009 state = STATE_END_INFO;
1012 warn(
"unmatched ']'");
1015 }
else if (c ==
'"') {
1017 case STATE_BEGIN_INFO:
1018 state = STATE_BEGIN_VALUE;
1019 for (--j; j >= 0 && isspace(info_tag[j]); --j);
1020 info_tag[j + 1] =
'\0';
1024 case STATE_BEGIN_VALUE:
1025 state = STATE_END_VALUE;
1026 info_value[j] =
'\0';
1028 if (strcmp(info_tag,
"black") == 0) {
1029 memcpy(game->
name[
BLACK], info_value, 31);
1031 }
else if (strcmp(info_tag,
"white") == 0) {
1032 memcpy(game->
name[
WHITE], info_value, 31);
1034 }
else if (strcmp(info_tag,
"date") == 0) {
1035 sscanf(info_value,
"%d.%d.%d", value, value + 1, value + 2);
1037 }
else if (strcmp(info_tag,
"time") == 0) {
1038 sscanf(info_value,
"%d:%d:%d", value, value + 1, value + 2);
1040 }
else if (strcmp(info_tag,
"FEN") == 0) {
1045 }
else if (isdigit(c)) {
1047 case STATE_BEGIN_SCORE:
1048 score[1] = score[1] * 10 + (c -
'0');
1050 case STATE_END_INFO:
1051 case STATE_END_MOVE:
1052 state = STATE_BEGIN_MOVE_N;
1055 case STATE_BEGIN_MOVE_N:
1056 n = 10 * n + (c -
'0');
1058 case STATE_BEGIN_MOVE:
1059 state = STATE_END_MOVE;
1065 case STATE_BEGIN_INFO:
1066 if (j >= info_size)
warn(
"info tag too long, will be truncated.");
1067 else info_tag[j++] = c;
1069 case STATE_BEGIN_VALUE:
1070 if (j >= info_size)
warn(
"info value too long, will be truncated.");
1071 else info_value[j++] = c;
1074 warn(
"unexpected digit %c", c);
1077 }
else if (c ==
'*') {
1079 case STATE_END_MOVE:
1080 state = STATE_BEGIN_SCORE;
1082 warn(
"uncomplete game.");
1084 case STATE_BEGIN_VALUE:
1085 if (j >= info_size)
warn(
"info value too long, will be truncated.");
1086 else info_value[j++] = c;
1089 warn(
"unexpected '*' %d", state);
1092 }
else if (c ==
'.') {
1094 case STATE_BEGIN_MOVE_N:
1095 state = STATE_END_MOVE_N;
1097 case STATE_END_MOVE_N:
1099 case STATE_BEGIN_INFO:
1100 if (j >= info_size)
warn(
"info tag too long, will be truncated.");
1101 else info_tag[j++] = c;
1103 case STATE_BEGIN_VALUE:
1104 if (j >= info_size)
warn(
"info value too long, will be truncated.");
1105 else info_value[j++] = c;
1108 warn(
"unexpected '.'");
1111 }
else if (c ==
'-') {
1113 case STATE_BEGIN_MOVE_N:
1114 state = STATE_BEGIN_SCORE;
1117 case STATE_BEGIN_INFO:
1118 if (j >= info_size)
warn(
"info tag too long, will be truncated.");
1119 else info_tag[j++] = c;
1121 case STATE_BEGIN_VALUE:
1122 if (j >= info_size)
warn(
"info value too long, will be truncated.");
1123 else info_value[j++] = c;
1125 case STATE_END_MOVE_N:
1126 case STATE_END_MOVE:
1129 warn(
"unexpected '-'");
1132 }
else if (isalpha(c) || c ==
'@') {
1134 case STATE_END_MOVE_N:
1135 case STATE_END_MOVE:
1136 state = STATE_BEGIN_MOVE;
1140 case STATE_BEGIN_MOVE:
1141 if (k < 4) move[k++] = c;
1142 else warn(
"unexpected %c", c);
1144 case STATE_BEGIN_INFO:
1145 if (j >= info_size)
warn(
"info tag too long, will be truncated.");
1146 else info_tag[j++] = c;
1148 case STATE_BEGIN_VALUE:
1149 if (j >= info_size)
warn(
"info value too long, will be truncated.");
1150 else info_value[j++] = c;
1153 warn(
"unexpected %c", c);
1156 }
else if (isspace(c)) {
1158 case STATE_BEGIN_SCORE:
1159 case STATE_END_SCORE:
1160 state = STATE_END_SCORE;
1162 case STATE_BEGIN_INFO:
1163 if (j >= info_size)
warn(
"info tag too long, will be truncated.");
1164 else info_tag[j++] = c;
1166 case STATE_BEGIN_VALUE:
1167 if (j >= info_size)
warn(
"info value too long, will be truncated.");
1168 else info_value[j++] = c;
1175 case STATE_BEGIN_INFO:
1176 if (j >= info_size)
warn(
"info tag too long, will be truncated.");
1177 else info_tag[j++] = c;
1179 case STATE_BEGIN_VALUE:
1180 if (j >= info_size)
warn(
"info value too long, will be truncated.");
1181 else info_value[j++] = c;
1184 warn(
"unexpected %c", c);
1192 warn(
"error while importing a PGN game\n");
1205 time_t t = time(NULL);
1206 struct tm *date = localtime(&t);
1208 const char *result = half_score < -32 ?
"*" : (half_score < 0 ?
"0-1" : (half_score > 0 ?
"1-0" :
"1/2-1/2"));
1209 const char *winner = (half_score < 0 ? game->
name[
WHITE]: (half_score > 0 ? game->
name[
BLACK] : NULL));
1217 fputs(
"[Event \"?\"]\n", f);
1218 fputs(
"[Site \"edax\"]\n", f);
1219 if (game->
date.
year == 0) fprintf(f,
"[Date \"%d.??.??\"]\n", date->tm_year + 1900);
1220 else if (game->
date.
month == 0) fprintf(f,
"[Date \"%d.??.??\"]\n", game->
date.
year);
1224 fputs(
"[Round \"?\"]\n", f);
1225 fprintf(f,
"[Black \"%s\"]\n", game->
name[
BLACK]);
1226 fprintf(f,
"[White \"%s\"]\n", game->
name[
WHITE]);
1227 fprintf(f,
"[Result \"%s\"]\n", result);
1235 for (i = j = k = 0; i < 60 && game->
move[i] !=
NOMOVE; ++i, ++k) {
1237 s[0] =
'p'; s[1] =
'a'; s[2] =
's'; s[3] =
's'; s[4] =
'\0'; --i;
1242 if ((j >= 78) || (player == game->
player && j >= 74)) {
1249 if (player == game->
player) j += fprintf(f,
"%d. ", (k >> 1) + 1);
1250 fputs(s, f); j += 2;
1253 if (winner) fprintf(f,
"\n{%s wins %d-%d}", winner, 32 + half_score, 32 - half_score);
1254 else if (half_score == 0) fprintf(f,
"\n{Draw 32-32}");
1255 fprintf(f,
" %s\n\n\n", result);
1266 time_t t = time(NULL);
1267 struct tm *date = localtime(&t);
1269 int i, color, player;
1270 char s_player[2][8] = {
"black",
"white"};
1273 fputs(
"%!PS-Adobe-3.0 EPSF-3.0\n",f);
1274 fputs(
"%%Creator: Edax-3.0\n",f);
1275 fprintf(f,
"%%%%CreationDate: %d/%d/%d %d:%d:%d\n", date->tm_year + 1900, date->tm_mon + 1, date->tm_mday, date->tm_hour, date->tm_min, date->tm_sec);
1276 fputs(
"%%BoundingBox: 0 0 200 200\n\n",f);
1277 fputs(
"%%BeginProlog\n\n",f);
1278 fputs(
"% othello coordinates\n",f);
1279 fputs(
"/A1 {40 160} def /A2 {40 140} def /A3 {40 120} def /A4 {40 100} def /A5 {40 80} def /A6 {40 60} def /A7 {40 40} def /A8 {40 20} def\n",f);
1280 fputs(
"/B1 {60 160} def /B2 {60 140} def /B3 {60 120} def /B4 {60 100} def /B5 {60 80} def /B6 {60 60} def /B7 {60 40} def /B8 {60 20} def\n",f);
1281 fputs(
"/C1 {80 160} def /C2 {80 140} def /C3 {80 120} def /C4 {80 100} def /C5 {80 80} def /C6 {80 60} def /C7 {80 40} def /C8 {80 20} def\n",f);
1282 fputs(
"/D1 {100 160} def /D2 {100 140} def /D3 {100 120} def /D4 {100 100} def /D5 {100 80} def /D6 {100 60} def /D7 {100 40} def /D8 {100 20} def\n",f);
1283 fputs(
"/E1 {120 160} def /E2 {120 140} def /E3 {120 120} def /E4 {120 100} def /E5 {120 80} def /E6 {120 60} def /E7 {120 40} def /E8 {120 20} def\n",f);
1284 fputs(
"/F1 {140 160} def /F2 {140 140} def /F3 {140 120} def /F4 {140 100} def /F5 {140 80} def /F6 {140 60} def /F7 {140 40} def /F8 {140 20} def\n",f);
1285 fputs(
"/G1 {160 160} def /G2 {160 140} def /G3 {160 120} def /G4 {160 100} def /G5 {160 80} def /G6 {160 60} def /G7 {160 40} def /G8 {160 20} def\n",f);
1286 fputs(
"/H1 {180 160} def /H2 {180 140} def /H3 {180 120} def /H4 {180 100} def /H5 {180 80} def /H6 {180 60} def /H7 {180 40} def /H8 {180 20} def\n\n",f);
1287 fputs(
"% draw a black disc\n",f);
1288 fputs(
"/disc_black{\n",f);
1289 fputs(
"\tnewpath\n",f);
1290 fputs(
"\t8.5 0 360 arc\n",f);
1291 fputs(
"\tfill\n",f);
1292 fputs(
"} def\n\n",f);
1293 fputs(
"% draw a white disc\n",f);
1294 fputs(
"/disc_white{\n",f);
1295 fputs(
"\tnewpath\n",f);
1296 fputs(
"\t0.5 setlinewidth\n",f);
1297 fputs(
"\t8.5 0 360 arc\n",f);
1298 fputs(
"\tstroke\n",f);
1299 fputs(
"} def\n\n",f);
1300 fputs(
"% draw a black move\n",f);
1301 fputs(
"/move_black{\n",f);
1302 fputs(
"\t/y exch def\n",f);
1303 fputs(
"\t/x exch def\n",f);
1304 fputs(
"\tnewpath\n",f);
1305 fputs(
"\tx y 8.5 0 360 arc\n",f);
1306 fputs(
"\tfill\n",f);
1307 fputs(
"\t1 setgray\n",f);
1308 fputs(
"\tx y moveto dup stringwidth pop 2 div neg -4.5 rmoveto\n",f);
1309 fputs(
"\tshow\n",f);
1310 fputs(
"\t0 setgray\n",f);
1311 fputs(
"} def\n\n",f);
1312 fputs(
"% draw a white move\n",f);
1313 fputs(
"/move_white{\n",f);
1314 fputs(
"\t/y exch def\n",f);
1315 fputs(
"\t/x exch def\n",f);
1316 fputs(
"\tnewpath\n",f);
1317 fputs(
"\t0.5 setlinewidth\n",f);
1318 fputs(
"\tx y 8.5 0 360 arc\n",f);
1319 fputs(
"\tstroke\n",f);
1320 fputs(
"\tx y moveto dup stringwidth pop 2 div neg -4.5 rmoveto\n",f);
1321 fputs(
"\tshow\n",f);
1322 fputs(
"} def\n\n",f);
1323 fputs(
"% draw the grid\n",f);
1324 fputs(
"/board_grid{\n",f);
1325 fputs(
"\tnewpath\n\n",f);
1326 fputs(
"\t%border\n",f);
1327 fputs(
"\t1.5 setlinewidth\n",f);
1328 fputs(
"\t 27 7 moveto\n",f);
1329 fputs(
"\t 166 0 rlineto\n",f);
1330 fputs(
"\t 0 166 rlineto\n",f);
1331 fputs(
"\t-166 0 rlineto\n",f);
1332 fputs(
"\tclosepath\n",f);
1333 fputs(
"\tstroke\n\n",f);
1334 fputs(
"\t%vertical lines\n",f);
1335 fputs(
"\t0.5 setlinewidth\n",f);
1336 fputs(
"\t30 10 moveto\n",f);
1337 fputs(
"\t0 1 8{\n",f);
1338 fputs(
"\t\t 0 160 rlineto\n",f);
1339 fputs(
"\t\t20 -160 rmoveto\n",f);
1340 fputs(
"\t}for\n\n",f);
1341 fputs(
"\t%horizontal lines\n",f);
1342 fputs(
"\t30 10 moveto\n",f);
1343 fputs(
"\t0 1 8{\n",f);
1344 fputs(
"\t\t 160 0 rlineto\n",f);
1345 fputs(
"\t\t-160 20 rmoveto\n",f);
1346 fputs(
"\t}for\n",f);
1347 fputs(
"\tstroke\n\n",f);
1348 fputs(
"\t%marks\n",f);
1349 fputs(
"\t 70 50 2 0 360 arc fill\n",f);
1350 fputs(
"\t150 50 2 0 360 arc fill\n",f);
1351 fputs(
"\t 70 130 2 0 360 arc fill\n",f);
1352 fputs(
"\t150 130 2 0 360 arc fill\n",f);
1353 fputs(
"}def\n\n",f);
1354 fputs(
"% draw coordinates\n",f);
1355 fputs(
"/board_coord{\n",f);
1356 fputs(
"\t/NewCenturySchoolbook-Roman findfont 15 scalefont setfont\n",f);
1357 fputs(
"\tnewpath\n",f);
1358 fputs(
"\t(a) 35 180 moveto show\n",f);
1359 fputs(
"\t(b) 55 180 moveto show\n",f);
1360 fputs(
"\t(c) 75 180 moveto show\n",f);
1361 fputs(
"\t(d) 95 180 moveto show\n",f);
1362 fputs(
"\t(e) 115 180 moveto show\n",f);
1363 fputs(
"\t(f) 135 180 moveto show\n",f);
1364 fputs(
"\t(g) 155 180 moveto show\n",f);
1365 fputs(
"\t(h) 175 180 moveto show\n",f);
1366 fputs(
"\t(1) 14 155 moveto show\n",f);
1367 fputs(
"\t(2) 14 135 moveto show\n",f);
1368 fputs(
"\t(3) 14 115 moveto show\n",f);
1369 fputs(
"\t(4) 14 95 moveto show\n",f);
1370 fputs(
"\t(5) 14 75 moveto show\n",f);
1371 fputs(
"\t(6) 14 55 moveto show\n",f);
1372 fputs(
"\t(7) 14 35 moveto show\n",f);
1373 fputs(
"\t(8) 14 15 moveto show\n",f);
1375 fputs(
"%%EndProlog\n\n",f);
1377 fputs(
"% do the drawing\n",f);
1379 fputs(
"\n\t% draw an empty board\n",f);
1380 fputs(
"\tboard_coord\n",f);
1381 fputs(
"\tboard_grid\n",f);
1382 fputs(
"\n\t% draw the discs\n",f);
1385 for (i =
A1; i <=
H8; i++) {
1387 if (color !=
EMPTY) {
1389 fprintf(f,
"\t%s disc_%s\n",
move_to_string(i, 0, s), s_player[color]);
1393 fputs(
"\n\t% draw the moves\n",f);
1394 fputs(
"\t/Utopia-Bold findfont 12 scalefont setfont\n",f);
1396 for (i = 0; i < 60 && game->
move[i] !=
NOMOVE; ++i) {
1406 fputs(
"grestore\n",f);
1411 int i, color, player;
1412 char s_color[2][8] = {
"black",
"white"};
1414 const char *style =
"font-size:22px;text-align:center;text-anchor:middle;font-family:Times New Roman;font-weight:bold";
1417 fputs(
"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n", f);
1419 fputs(
"\txmlns=\"http://www.w3.org/2000/svg\"\n", f);
1420 fputs(
"\tversion=\"1.1\"\n", f);
1421 fputs(
"\twidth=\"440\"\n", f);
1422 fputs(
"\theight=\"440\">\n", f);
1423 fputs(
"\t<desc>Othello Game</desc>\n", f);
1426 fputs(
"\t<rect\n", f);
1427 fputs(
"\t\twidth=\"332\" height=\"332\" ", f);
1428 fputs(
"x=\"54\" y=\"54\" ", f);
1429 fputs(
"stroke=\"black\" ", f);
1430 fputs(
"stroke-width=\"2\" ", f);
1431 fputs(
"fill=\"white\" />\n", f);
1432 fputs(
"\t<rect\n", f);
1433 fputs(
"\t\twidth=\"320\" height=\"320\" ", f);
1434 fputs(
"x=\"60\" y=\"60\" ", f);
1435 fputs(
"stroke=\"black\" ", f);
1436 fputs(
"fill=\"green\" />\n", f);
1437 for (i = 1; i < 8; ++i) {
1438 fputs(
"\t<line\n", f);
1439 fprintf(f,
"\t\tx1=\"60\" y1=\"%d\" ", 60 + 40 * i);
1440 fprintf(f,
"x2=\"380\" y2=\"%d\" ", 60 + 40 * i);
1441 fputs(
"stroke=\"black\" />\n", f);
1442 fputs(
"\t<line\n", f);
1443 fprintf(f,
"\t\tx1=\"%d\" y1=\"60\" ", 60 + 40 * i);
1444 fprintf(f,
"x2=\"%d\" y2=\"380\" ", 60 + 40 * i);
1445 fputs(
"stroke=\"black\" />\n", f);
1447 fputs(
"\t<circle cx=\"140\" cy=\"140\" r=\"4\" fill=\"black\" />\n", f);
1448 fputs(
"\t<circle cx=\"300\" cy=\"140\" r=\"4\" fill=\"black\" />\n", f);
1449 fputs(
"\t<circle cx=\"140\" cy=\"300\" r=\"4\" fill=\"black\" />\n", f);
1450 fputs(
"\t<circle cx=\"300\" cy=\"300\" r=\"4\" fill=\"black\" />\n", f);
1453 for (i = 0; i < 8; ++i) {
1454 fprintf(f,
"\t<text x=\"%d\" y=\"%d\" style = \"%s\" > %d </text>\n", 40, 85 + i * 40, style, i + 1);
1455 fprintf(f,
"\t<text x=\"%d\" y=\"%d\" style = \"%s\" > %c </text>\n", 80 + i * 40, 50, style, i +
'a');
1459 for (i =
A1; i <=
H8; i++) {
1461 if (color !=
EMPTY) {
1463 fprintf(f,
"\t<circle cx=\"%d\" cy=\"%d\" r=\"17\" fill=\"%s\" stroke=\"%s\" />\n",
1464 80 + 40 * (i % 8), 80 + 40 * (i / 8), s_color[color], s_color[!color]);
1471 for (i = 0; i < 60 && game->
move[i] !=
NOMOVE; ++i) {
1476 fprintf(f,
"\t<circle cx=\"%d\" cy=\"%d\" r=\"17\" fill=\"%s\" stroke=\"%s\" />\n",
1477 80 + 40 * (game->
move[i] % 8), 80 + 40 * (game->
move[i] / 8), s_color[player], s_color[!player]);
1479 fprintf(f,
"\t<text x=\"%d\" y=\"%d\" fill=\"%s\" style=\"%s\"> %d </text>\n",
1480 83 + 40 * (game->
move[i] % 8), 87 + 40 * (game->
move[i] / 8), s_color[player], style, i + 1);
1486 fputs(
"</svg>\n", f);
1500 unsigned long long moves;
1506 for (ply = 0; ply < n_ply; ply++) {
1517 game->
move[ply] = move->
x;
1552 for (i = n_move = 0; i < 60 && game->
move[i] !=
NOMOVE; ++i) {
1565 stack[n_move].n_empties = search->
n_empties;
1570 *stack[n_move].pv = *search->
result->
pv;
1580 fprintf(stderr,
"\n\n");
1591 for (i = n_move - 1; stack[i].n_empties <= n_empties; --i) {
1592 stack[i].played.score = -score;
1593 score =
MAX(stack[i].played.score, stack[i].best.score);
1597 while (stack[--n_move].n_empties <= n_empties) {
1598 if (stack[n_move].played.score < stack[n_move].best.score) {
1601 if (apply_correction && stack[n_move].best.x !=
NOMOVE) {
1602 for (i = 0; i < 60 && game->
move[i] != 0; ++i) {
1603 if (game->
move[i] == stack[n_move].played.x) {
1636 for (n = 0; n < 60; ++n) {
1638 for (i = 0; i < 60 && game->
move[i] !=
NOMOVE; ++i) {
DLL_API int bit_count(unsigned long long b)
Count the number of bits set to one in an unsigned long long.
Definition bit.c:72
int get_rand_bit(unsigned long long b, Random *r)
Get a random set bit index.
Definition bit.c:415
#define x_to_bit(x)
Definition bit.h:43
bool board_is_game_over(const Board *board)
Check if the game is over.
Definition board.c:1203
void board_print(const Board *board, const int player, FILE *f)
Print out the board.
Definition board.c:1230
void board_update(Board *board, const Move *move)
Update a board.
Definition board.c:469
unsigned long long board_get_move(const Board *board, const int x, Move *move)
Compute a move.
Definition board.c:438
char * board_to_FEN(const Board *board, const int player, char *string)
print to FEN description.
Definition board.c:1312
int board_get_square_color(const Board *board, const int x)
Get square color.
Definition board.c:1168
void board_init(Board *board)
Set a board to the starting position.
Definition board.c:280
char * board_to_string(const Board *board, const int player, char *s)
convert the to a compact string.
Definition board.c:1272
bool board_equal(const Board *b1, const Board *b2)
Compare two board for equality.
Definition board.c:335
DLL_API unsigned long long get_moves(const unsigned long long P, const unsigned long long O)
Get legal moves.
Definition board.c:621
DLL_API bool can_move(const unsigned long long P, const unsigned long long O)
Check if a player can move.
Definition board.c:797
int board_set(Board *board, const char *string)
Set a board from a string description.
Definition board.c:154
void board_pass(Board *board)
Passing move.
Definition board.c:503
bool board_is_occupied(const Board *board, const int x)
Check if a square is occupied.
Definition board.c:1180
int board_from_FEN(Board *board, const char *string)
Set a board from a string description.
Definition board.c:212
#define SCORE_INF
Definition const.h:52
@ B3
Definition const.h:31
@ D7
Definition const.h:35
@ PASS
Definition const.h:37
@ B6
Definition const.h:34
@ F3
Definition const.h:31
@ NOMOVE
Definition const.h:37
@ E8
Definition const.h:36
@ E6
Definition const.h:34
@ C4
Definition const.h:32
@ A6
Definition const.h:34
@ F5
Definition const.h:33
@ C5
Definition const.h:33
@ D1
Definition const.h:29
@ H4
Definition const.h:32
@ G5
Definition const.h:33
@ B8
Definition const.h:36
@ E7
Definition const.h:35
@ E3
Definition const.h:31
@ A2
Definition const.h:30
@ A3
Definition const.h:31
@ C7
Definition const.h:35
@ H5
Definition const.h:33
@ B7
Definition const.h:35
@ F1
Definition const.h:29
@ C2
Definition const.h:30
@ C8
Definition const.h:36
@ G6
Definition const.h:34
@ B4
Definition const.h:32
@ F7
Definition const.h:35
@ A1
Definition const.h:29
@ A7
Definition const.h:35
@ H1
Definition const.h:29
@ D2
Definition const.h:30
@ F4
Definition const.h:32
@ G3
Definition const.h:31
@ B2
Definition const.h:30
@ G8
Definition const.h:36
@ F6
Definition const.h:34
@ F2
Definition const.h:30
@ H6
Definition const.h:34
@ A5
Definition const.h:33
@ G1
Definition const.h:29
@ E1
Definition const.h:29
@ H7
Definition const.h:35
@ H3
Definition const.h:31
@ D6
Definition const.h:34
@ H2
Definition const.h:30
@ F8
Definition const.h:36
@ E2
Definition const.h:30
@ B1
Definition const.h:29
@ A4
Definition const.h:32
@ C3
Definition const.h:31
@ H8
Definition const.h:36
@ D3
Definition const.h:31
@ C6
Definition const.h:34
@ G7
Definition const.h:35
@ C1
Definition const.h:29
@ D8
Definition const.h:36
@ G2
Definition const.h:30
@ G4
Definition const.h:32
@ B5
Definition const.h:33
@ A8
Definition const.h:36
#define VERSION_STRING
Definition const.h:88
@ WHITE
Definition const.h:43
@ EMPTY
Definition const.h:44
@ BLACK
Definition const.h:42
#define SCORE_MIN
Definition const.h:55
static int move_to_wthor(int x)
Coordinates conversion from edax to wthor.
Definition game.c:49
@ PARSE_INVALID_VALUE
Definition game.c:29
@ PARSE_END_OF_FILE
Definition game.c:27
@ PARSE_INVALID_TAG
Definition game.c:28
@ PARSE_OK
Definition game.c:26
void game_export_ggf(const Game *game, FILE *f)
Write a game to the Generic Game Format (ggf) file.
Definition game.c:713
void game_import_text(Game *game, FILE *f)
Read a game from a text file.
Definition game.c:451
void game_read(Game *game, FILE *f)
Read a game from a binary file.
Definition game.c:429
int game_analyze(Game *game, Search *search, const int n_empties, const bool apply_correction)
Analyze an endgame.
Definition game.c:1532
bool game_check(Game *game)
Check a game.
Definition game.c:213
static bool game_update_player(Board *board, int x)
update a player.
Definition game.c:171
int game_complete(Game *game, Search *search)
Terminate an unfinished game.
Definition game.c:1625
char * parse_ggf(Game *game, const char *string)
Parse a ggf game from a string.
Definition game.c:664
bool game_update_board(Board *board, int x)
update a board.
Definition game.c:153
void game_export_sgf(const Game *game, FILE *f)
Definition game.c:944
void wthor_to_game(const WthorGame *thor, Game *game)
convert a Wthor game to a Game.
Definition game.c:340
void game_import_ggf(Game *game, FILE *f)
Read a game from the Generic Game Format (ggf) file.
Definition game.c:582
void game_import_oko(Game *game, FILE *f)
Read a game from the "allinf.oko" file.
Definition game.c:513
static int game_parse_sgf(FILE *f, char *tag, char *value)
Parse a Smart Game Format (sgf) game.
Definition game.c:762
void game_save_sgf(const Game *game, FILE *f, const bool multiline)
Write a game to the Generic Game Format (ggf) file.
Definition game.c:870
bool game_equals(const Game *game_1, const Game *game_2)
Test if two games are equal.
Definition game.c:114
void game_import_wthor(Game *game, FILE *f)
Read a game from a Wthor file.
Definition game.c:487
void game_rand(Game *game, int n_ply, Random *r)
Fill a game with some random moves.
Definition game.c:1497
void game_export_text(const Game *game, FILE *f)
Write a game to a text file.
Definition game.c:467
void game_export_svg(const Game *game, FILE *f)
Definition game.c:1409
void game_copy(Game *dest, const Game *src)
Game copy.
Definition game.c:103
static int game_parse_ggf(FILE *f, char *tag, char *value)
Parse a ggf game.
Definition game.c:529
void game_init(Game *game)
Create an empty game.
Definition game.c:83
void game_import_pgn(Game *game, FILE *f)
Read a game from a pgn file.
Definition game.c:955
void game_to_text(const Game *game, char *line)
Convert game to a text (ascii).
Definition game.c:294
void line_to_game(const Board *initial_board, const Line *line, Game *game)
Build a game from an initial position and a move sequence.
Definition game.c:415
void text_to_game(const char *line, Game *game)
Convert a text (ascii) game to a Game.
Definition game.c:267
void game_append_line(Game *game, const Line *line, const int from)
Build a game from an initial position and a move sequence.
Definition game.c:388
void game_export_wthor(const Game *game, FILE *f)
Write a game to a Wthor file.
Definition game.c:500
void game_to_wthor(const Game *game, WthorGame *thor)
convert a Game to a Whor game.
Definition game.c:366
static const char * parse_tag(const char *string, char *tag, char *value)
Parse a Tag/value ggf pair from a string.
Definition game.c:632
static int move_from_oko(int x)
Coordinates conversion from oko.
Definition game.c:62
void game_import_sgf(Game *game, FILE *f)
Read a game from a sgf file.
Definition game.c:823
void game_export_eps(const Game *game, FILE *f)
Write a game to an eps file.
Definition game.c:1264
void game_write(const Game *game, FILE *f)
Write a game to a binary file.
Definition game.c:440
void game_export_pgn(const Game *game, FILE *f)
Write a game to a pgn file.
Definition game.c:1203
void oko_to_game(const OkoGame *oko, Game *game)
convert an allinf.oko game to a Game.
Definition game.c:313
bool game_get_board(const Game *game, const int ply, Board *board)
Get the board after 'ply' move.
Definition game.c:195
int game_score(const Game *game)
Compute the final score of the game, for the initial player.
Definition game.c:233
bool wthor_equals(const WthorGame *game_1, const WthorGame *game_2)
Test if two Wthor games are equal.
Definition game.c:136
int move_from_wthor(int x)
Coordinates conversion from wthor to edax.
Definition game.c:38
unsigned long long hash_move[64][60]
Definition hash-lock-free.c:44
const Move MOVE_PASS
Definition move.c:26
Move * movelist_first(MoveList *movelist)
Return the first move of the list.
Definition move.c:422
void line_init(Line *line, const int player)
Initialize a sequence of moves.
Definition move.c:549
Move * movelist_exclude(MoveList *movelist, const int move)
Exclude a move.
Definition move.c:516
const Move MOVE_INIT
Definition move.c:25
char * move_to_string(const int x, const int player, char *s)
Print out a move.
Definition move.c:76
void * search_run(void *v)
Search the bestmove of a given board.
Definition root.c:810
void search_set_level(Search *search, const int level, const int n_empties)
Set the search level.
Definition search.c:609
const int NO_SELECTIVITY
Definition search.c:94
void search_cleanup(Search *search)
Clean-up some search data.
Definition search.c:578
void search_set_board(Search *search, const Board *board, const int player)
Set the board to analyze.
Definition search.c:593
unsigned long long player
Definition board.h:27
unsigned long long opponent
Definition board.h:27
char move[60]
Definition game.h:33
signed char second
Definition game.h:30
signed char day
Definition game.h:27
signed char month
Definition game.h:26
char name[2][32]
Definition game.h:32
unsigned long long hash
Definition game.h:35
Board initial_board[1]
Definition game.h:23
signed char minute
Definition game.h:29
short year
Definition game.h:25
signed char hour
Definition game.h:28
char player
Definition game.h:34
int n_moves
Definition move.h:37
char move[GAME_SIZE]
Definition move.h:36
int color
Definition move.h:38
int n_moves
Definition move.h:31
int x
Definition move.h:22
char move[61]
Definition game.h:48
int move
Definition search.h:44
int score
Definition search.h:45
int selectivity
Definition search.h:43
Line pv[1]
Definition search.h:47
int depth
Definition search.h:42
int n_empties
Definition search.h:99
void(* observer)(Result *)
Definition search.h:153
MoveList movelist[1]
Definition search.h:132
Result * result
Definition search.h:151
struct Search::@25 options
int verbosity
Definition search.h:142
signed char theoric_score
Definition game.h:40
char x[60]
Definition game.h:41
short tournament
Definition game.h:39
signed char score
Definition game.h:40
short white
Definition game.h:39
short black
Definition game.h:39
char * parse_move(const char *string, const Board *board, Move *move)
Parse a move.
Definition util.c:627
int string_to_coordinate(const char *s)
Convert the two first chars of a string into a coordinate.
Definition util.c:384
void string_to_lowercase(char *s)
Change all char of a string to lowercase.
Definition util.c:355
char * string_read_line(FILE *f)
Read a line.
Definition util.c:265
char * parse_skip_spaces(const char *string)
Skip spaces.
Definition util.c:514
Miscellaneous utilities header.
#define warn(...)
Display a warning message as "WARNING : ... ".
Definition util.h:373
#define MAX(a, b)
Definition util.h:98