Changing license to GPL3 (and bumping version to 1.4.0).
[gnushogi.git] / gnushogi / pat2inc.c
1 /*
2  * FILE: pat2inc.c
3  *
4  *     Convert GNU Shogi pattern textfile to an include file.
5  *
6  * ----------------------------------------------------------------------
7  *
8  * Copyright (c) 2012 Free Software Foundation
9  *
10  * GNU SHOGI is based on GNU CHESS
11  *
12  * This file is part of GNU SHOGI.
13  *
14  * GNU Shogi is free software; you can redistribute it and/or modify it
15  * under the terms of the GNU General Public License as published by the
16  * Free Software Foundation; either version 3 of the License,
17  * or (at your option) any later version.
18  *
19  * GNU Shogi is distributed in the hope that it will be useful, but WITHOUT
20  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
22  * for more details.
23  *
24  * You should have received a copy of the GNU General Public License along
25  * with GNU Shogi; see the file COPYING. If not, see
26  * <http://www.gnu.org/licenses/>.
27  * ----------------------------------------------------------------------
28  *
29  */
30
31 #include "version.h"
32 #include "gnushogi.h"
33 #include "pattern.h"
34
35
36 extern void ReadOpeningSequences(short *pindex);
37 extern void WriteOpeningSequences(short pindex);
38
39 /*
40
41 small_short PieceCnt[2];
42 small_short PieceList[2][NO_SQUARES];
43 small_short PieceIndex[NO_SQUARES];
44
45 small_short board[NO_SQUARES];
46 small_short color[NO_SQUARES];
47
48 */
49
50 void
51 test_distance()
52 {
53     short side, piece, f, t, d;
54
55     for (side = 0; side <= 1; side++)
56     {
57         printf("SIDE = %d\n", side);
58
59         for (piece = pawn; piece <= king; piece++)
60         {
61             printf("PIECE = %d\n", piece);
62
63             for (f = 0; f < NO_SQUARES; f++)
64             {
65                 printf("FROM %d TO ", f);
66
67                 for (t = 0; t < NO_SQUARES; t++)
68                 {
69                     d = piece_distance(side, piece, f, t);
70
71                     if (d != CANNOT_REACH)
72                         printf("%d:%d ", t, d);
73                 }
74
75                 printf("\n");
76             }
77         }
78     }
79
80 }
81
82
83
84 int
85 main(int argc, char **argv)
86
87 {
88
89     short sq, side, max_pattern_data;
90
91 #if defined(EXTLANGFILE)
92     char *Lang = NULL;
93 #endif
94
95 #ifdef TEST_DISTANCE
96     short d;
97     char  s[80];
98 #endif
99
100     display_type = DISPLAY_RAW;
101
102 #if defined(EXTLANGFILE)
103     InitConst(Lang);
104 #endif
105
106     Initialize_data();
107
108     for (sq = 0; sq < NO_SQUARES; sq++)
109     {
110         board[sq] = no_piece;
111         color[sq] = neutral;
112     }
113
114     ClearCaptured();
115
116     for (side = 0; side <= 1; side++)
117         PieceCnt[side] = -1;
118
119 #ifdef TEST_DISTANCE
120     strcpy(s, "g6i k5i g4i p9g p8g r* s3h p7g b8h B* S5f");
121
122     if (string_to_board_color(s))
123     {
124         printf("ERROR IN string_to_board_color");
125         exit(1);
126     }
127     else
128     {
129         UpdateDisplay(0, 0, 1, 0);
130     }
131
132     d = pattern_distance(black, &pattern);
133
134     printf("distance = %d\n", d);
135
136 #endif
137
138     ReadOpeningSequences(&max_pattern_data);
139     WriteOpeningSequences(max_pattern_data);
140
141     return 0;
142 }
143