Merge branch 'maint'
[gnushogi.git] / gnushogi / pat2inc.c
1 /*
2  * FILE: pat2inc.c
3  *
4  *     Convert GNU Shogi pattern textfile to an include file.
5  *
6  * ----------------------------------------------------------------------
7  * Copyright (c) 1993, 1994, 1995 Matthias Mutz
8  * Copyright (c) 1999 Michael Vanier and the Free Software Foundation
9  * Copyright (c) 2008, 2013, 2014 Yann Dirson and the Free Software Foundation
10  *
11  * GNU SHOGI is based on GNU CHESS
12  *
13  * Copyright (c) 1988, 1989, 1990 John Stanback
14  * Copyright (c) 1992 Free Software Foundation
15  *
16  * This file is part of GNU SHOGI.
17  *
18  * GNU Shogi is free software; you can redistribute it and/or modify it
19  * under the terms of the GNU General Public License as published by the
20  * Free Software Foundation; either version 3 of the License,
21  * or (at your option) any later version.
22  *
23  * GNU Shogi is distributed in the hope that it will be useful, but WITHOUT
24  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
25  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
26  * for more details.
27  *
28  * You should have received a copy of the GNU General Public License along
29  * with GNU Shogi; see the file COPYING. If not, see
30  * <http://www.gnu.org/licenses/>.
31  * ----------------------------------------------------------------------
32  *
33  */
34
35 #include "gnushogi.h"
36 #include "pattern.h"
37
38
39 extern void ReadOpeningSequences(short *pindex, const char* patternfile);
40 extern void WriteOpeningSequences(short pindex, const char* patternincfile);
41
42 small_short board[NO_SQUARES];
43 small_short color[NO_SQUARES];
44
45 int
46 main(int argc, char **argv)
47 {
48     short sq, side, max_pattern_data;
49
50     if (argc != 3) {
51         fprintf(stderr, "Usage: %s gnushogi.pat pattern.inc\n", argv[0]);
52         exit(1);
53     }
54     char* patternfile = argv[1];
55     char* patternincfile = argv[2];
56
57 #ifdef TEST_DISTANCE
58     short d;
59     char  s[80];
60 #endif
61
62     Initialize_data();
63
64     for (sq = 0; sq < NO_SQUARES; sq++)
65     {
66         board[sq] = no_piece;
67         color[sq] = neutral;
68     }
69
70     ClearCaptured();
71
72     for (side = 0; side <= 1; side++)
73         PieceCnt[side] = -1;
74
75 #ifdef TEST_DISTANCE
76     strcpy(s, "g6i k5i g4i p9g p8g r* s3h p7g b8h B* S5f");
77
78     if (string_to_board_color(s))
79     {
80         printf("ERROR IN string_to_board_color");
81         exit(1);
82     }
83     else
84     {
85         UpdateDisplay(0, 0, 1, 0);
86     }
87
88     d = pattern_distance(black, &pattern);
89
90     printf("distance = %d\n", d);
91
92 #endif
93
94     ReadOpeningSequences(&max_pattern_data, patternfile);
95     WriteOpeningSequences(max_pattern_data, patternincfile);
96
97     return 0;
98 }