/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\
* This is GNU Go, a Go program. Contact gnugo@gnu.org, or see *
* http://www.gnu.org/software/gnugo/ for more information. *
* Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, *
* 2008 and 2009 by the Free Software Foundation. *
* This program is free software; you can redistribute it and/or *
* modify it under the terms of the GNU General Public License as *
* published by the Free Software Foundation - version 3 or *
* (at your option) any later version. *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License in file COPYING for more details. *
* You should have received a copy of the GNU General Public *
* License along with this program; if not, write to the Free *
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, *
* Boston, MA 02111, USA. *
\* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/* Compile the eye database. This produces eyes.c. */
/* see also eyes.db, eyes.h and engine/optics.c */
char vertex
[MAXDIMEN
][MAXDIMEN
];
signed char marginal
[MAXDIMEN
][MAXDIMEN
];
signed char edge
[MAXDIMEN
][MAXDIMEN
];
unsigned char flags
[MAXDIMEN
][MAXDIMEN
];
int eye_number
[MAXPATNO
];
int two_neighbors
[MAXPATNO
];
int three_neighbors
[MAXPATNO
];
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\\\n\
* This is GNU Go, a Go program. Contact gnugo@gnu.org, or see *\n\
* http://www.gnu.org/software/gnugo/ for more information. *\n\
* Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006 and 2007 *\n\
* by the Free Software Foundation. *\n\
* This program is free software; you can redistribute it and/or *\n\
* modify it under the terms of the GNU General Public License as *\n\
* published by the Free Software Foundation - version 3 *\n\
* or (at your option) any later version *\n\
* This program is distributed in the hope that it will be useful, *\n\
* but WITHOUT ANY WARRANTY; without even the implied warranty of *\n\
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *\n\
* GNU General Public License in file COPYING for more details. *\n\
* You should have received a copy of the GNU General Public *\n\
* License along with this program; if not, write to the Free *\n\
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, *\n\
* Boston, MA 02111, USA. *\n\
\\* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */\n\n");
printf("/* This file is automatically generated by mkeyes. Do not\n");
printf(" * edit it directly. Instead, edit the eye shape database.\n");
printf("#include <stdio.h> /* for NULL */\n");
printf("#include \"eyes.h\"\n\n");
memset(ends
, 0, sizeof(ends
));
memset(two_neighbors
, 0, sizeof(two_neighbors
));
memset(three_neighbors
, 0, sizeof(three_neighbors
));
memset(esize
, 0, sizeof(esize
));
while (fgets(line
, MAXLINE
, stdin
) && !fatal_errors
) {
int last
= strlen(line
) - 1;
if (line
[last
] != '\n') {
fprintf(stderr
, "mkeyes: line truncated: %s\n", line
);
/* remove trailing whitespace */
for (last
--; last
>= 0 && isspace((int) line
[last
]); last
--) {
if (sscanf(line
, "Pattern %d", &p
)) {
if (patno
> 0 && eye_number
[patno
] <= eye_number
[patno
-1]) {
fprintf(stderr
, "mkeyes: Pattern %d out of sequence\n",
fprintf(stderr
, "parsing pattern %d\n", eye_number
[patno
]);
memset(vertex
, 0, sizeof(vertex
));
memset(marginal
, 0, sizeof(marginal
));
memset(edge
, 0, sizeof(edge
));
memset(flags
, 0, sizeof(flags
));
/* Empty line or comment line, skip. */
if (strncmp("#", line
, 1) == 0 || strncmp("\n", line
, 1) == 0)
if (strncmp(":", line
, 1) != 0) {
for (n
= 0; n
< MAXDIMEN
&& strncmp("\n", line
+ n
, 1); n
++) {
/* space, harmless CR, or corner symbol */
if (line
[n
] == ' ' || line
[n
] == '\r' || line
[n
] == '+')
fprintf(stderr
, "%c", line
[n
]);
flags
[m
][n
] = CAN_BE_EMPTY
;
flags
[m
][n
] = CAN_BE_EMPTY
;
flags
[m
][n
] = CAN_BE_EMPTY
| EYE_DEFENSE_POINT
| EYE_ATTACK_POINT
;
flags
[m
][n
] = CAN_CONTAIN_STONE
;
flags
[m
][n
] = CAN_BE_EMPTY
| EYE_ATTACK_POINT
;
flags
[m
][n
] = CAN_BE_EMPTY
| EYE_DEFENSE_POINT
;
flags
[m
][n
] = CAN_BE_EMPTY
| CAN_CONTAIN_STONE
;
flags
[m
][n
] = CAN_BE_EMPTY
| EYE_ATTACK_POINT
| EYE_DEFENSE_POINT
;
flags
[m
][n
] = CAN_BE_EMPTY
| EYE_ATTACK_POINT
;
flags
[m
][n
] = CAN_BE_EMPTY
| EYE_DEFENSE_POINT
;
flags
[m
][n
] = CAN_CONTAIN_STONE
;
"mkeyes: invalid character %c in pattern %d\n",
line
[n
], eye_number
[patno
]);
sscanf(line
, ":%1d%1d%1d%1d", &value_a
[patno
], &value_b
[patno
],
&value_c
[patno
], &value_d
[patno
]);
fprintf(stderr
, "value=%d%d%d%d\n", value_a
[patno
], value_b
[patno
],
value_c
[patno
], value_d
[patno
]);
if (value_b
[patno
] != value_c
[patno
]) {
if (num_attacks
== 0 || num_defenses
== 0) {
"mkeyes: missing attack or defense point in pattern %d\n",
if (value_b
[patno
] == value_c
[patno
]) {
if (num_attacks
> 0 || num_defenses
> 0) {
"mkeyes: attack or defense point in settled pattern %d\n",
printf("static struct eye_vertex eye%d[] = {\n", eye_number
[patno
]);
for (l
= 0; l
< esize
[patno
]; l
++) {
int mx
[MAXDIMEN
][MAXDIMEN
];
memset(mx
, -1, sizeof(mx
));
for (h
= 0; h
< 4; h
++) {
if (i
> 0 && vertex
[i
-1][j
]) {
if (i
< MAXDIMEN
-1 && vertex
[i
+1][j
]) {
if (j
> 0 && vertex
[i
][j
-1]) {
if (j
< MAXDIMEN
-1 && vertex
[i
][j
+1]) {
else if (neighbors
[l
] == 2)
else if (neighbors
[l
] == 3)
three_neighbors
[patno
]++;
for (h
= 0; h
< esize
[patno
]; h
++) {
if (ni
[k
] != -1 && vi
[h
] == ni
[k
] && vj
[h
] == nj
[k
])
printf(" {%d, %d, %2d, %d, {%2d, %2d, %2d, %2d}}",
marginal
[i
][j
], (int) edge
[i
][j
], (int) flags
[i
][j
],
neighbors
[l
], nb
[0], nb
[1], nb
[2], nb
[3]);
"mkeyes: Too many eye patterns. Increase MAXPATNO in mkeyes.c\n");
printf("\nstruct eye_graph graphs[] = {\n");
for (l
= 0; l
< patno
; l
++) {
printf(" {eye%d, %d, %d, %d, %d, %d, %d, {%d, %d, %d, %d}}",
eye_number
[l
], eye_number
[l
], esize
[l
], msize
[l
], ends
[l
],
two_neighbors
[l
], three_neighbors
[l
],
value_a
[l
], value_b
[l
], value_c
[l
], value_d
[l
]);
printf(",\n {NULL, 0, 0, 0, 0, 0, 0, {0, 0, 0, 0}}\n};\n");
printf("\n\n#error in eye database. Rebuild.\n\n");