/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\
* 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 Monte Carlo local pattern database. This produces mcpat.c. */
/* See also mc_*.db and engine/montecarlo.c. */
/* Trim leading path, a possible mc_ prefix, and a possible .db suffix
* from the filename. The caller has to free the returned pointer when
* FIXME: This code is quite ugly and should be possible to clean up.
copy_and_trim_name(const char *filename
)
int name_length
= strlen(filename
);
char *name
= malloc(name_length
+ 1);
name_length
-= (p
- name
);
if (strncmp(start
, "mc_", 3) == 0) {
if (strncmp(start
+ name_length
- 3, ".db", 3) == 0)
start
[name_length
- 3] = '\0';
name2
= malloc(name_length
+ 1);
main(int argc
, char *argv
[])
int N
= mc_get_size_of_pattern_values_table();
fprintf(stderr
, "Usage: ...\n");
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\\\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, 2007, *\n\
* 2008 and 2009 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 mkmcpat. Do not\n");
printf(" * edit it directly. Instead, edit the pattern databases\n");
printf("#include <stdio.h> /* for NULL */\n");
printf("#include \"liberty.h\"\n\n");
printf("#include \"patterns.h\"\n\n");
values
= malloc(N
* sizeof(*values
));
for (i
= 1; i
< argc
; i
++) {
if (!mc_load_patterns_from_db(argv
[i
], values
))
name
= copy_and_trim_name(argv
[i
]);
printf("static const unsigned int %s_values[] = {\n", name
);
for (k
= 0; k
< N
; k
++) {
printf("%u, ", values
[k
]);
printf("struct mc_pattern_database mc_pattern_databases[] = {\n");
for (i
= 1; i
< argc
; i
++) {
name
= copy_and_trim_name(argv
[i
]);
printf(" {\"%s\", %s_values},\n", name
, name
);
printf(" {NULL, NULL}};\n");