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
|
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\
* 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. */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "liberty.h"
/* Trim leading path, a possible mc_ prefix, and a possible .db suffix
* from the filename. The caller has to free the returned pointer when
* it's no longer needed.
*
* FIXME: This code is quite ugly and should be possible to clean up.
*/
static char *
copy_and_trim_name(const char *filename)
{
int name_length = strlen(filename);
char *name = malloc(name_length + 1);
char *start = name;
char *p;
char *name2;
strcpy(name, filename);
p = strrchr(name, '/');
if (p) {
p++;
name_length -= (p - name);
start = p;
}
if (strncmp(start, "mc_", 3) == 0) {
start += 3;
name_length -= 3;
}
if (strncmp(start + name_length - 3, ".db", 3) == 0)
start[name_length - 3] = '\0';
name2 = malloc(name_length + 1);
strcpy(name2, start);
free(name);
return name2;
}
int
main(int argc, char *argv[])
{
int N = mc_get_size_of_pattern_values_table();
unsigned int *values;
int i;
int k;
char *name;
if (argc < 2) {
fprintf(stderr, "Usage: ...\n");
exit(EXIT_FAILURE);
}
printf("\
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\\\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\
* *\n\
* Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, *\n\
* 2008 and 2009 by the Free Software Foundation. *\n\
* *\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\
* *\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\
* *\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(" * mc_*.db.\n");
printf(" */\n\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))
exit(EXIT_FAILURE);
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]);
if (k % 16 == 15)
printf("\n");
}
printf("\n};\n\n");
free(name);
}
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);
free(name);
}
printf(" {NULL, NULL}};\n");
return 0;
}
/*
* Local Variables:
* tab-width: 8
* c-basic-offset: 2
* End:
*/
|