6 * Board parser for xshogi.
8 * ------------------------------------------------------------------------
9 * xshogi is based on XBoard -- an Xt/Athena user interface for GNU Chess.
11 * Original authors: Dan Sears, Chris Sears
12 * Enhancements (Version 2.0 and following): Tim Mann
13 * Modifications to XShogi (Version 1.0): Matthias Mutz
14 * Enhancements to XShogi (Version 1.1): Matthias Mutz
15 * Modified implementation of ISS mode for XShogi: Matthias Mutz
16 * Current maintainer: Michael C. Vanier
18 * XShogi borrows some of its piece bitmaps from CRANES Shogi.
20 * Copyright 1991 by Digital Equipment Corporation, Maynard, Massachusetts.
21 * Enhancements Copyright 1992 Free Software Foundation, Inc.
22 * Enhancements for XShogi Copyright 1993, 1994, 1995 Matthias Mutz
23 * Copyright 1998, 1999 Michael C. Vanier and the Free Software Foundation
25 * The following terms apply to Digital Equipment Corporation's copyright
27 * ------------------------------------------------------------------------
30 * Permission to use, copy, modify, and distribute this software and its
31 * documentation for any purpose and without fee is hereby granted,
32 * provided that the above copyright notice appear in all copies and that
33 * both that copyright notice and this permission notice appear in
34 * supporting documentation, and that the name of Digital not be
35 * used in advertising or publicity pertaining to distribution of the
36 * software without specific, written prior permission.
38 * DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
39 * ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
40 * DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
41 * ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
42 * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
43 * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
45 * ------------------------------------------------------------------------
47 * This file is part of GNU shogi.
49 * GNU shogi is free software; you can redistribute it and/or modify
50 * it under the terms of the GNU General Public License as published by
51 * the Free Software Foundation.
53 * GNU shogi is distributed in the hope that it will be useful,
54 * but WITHOUT ANY WARRANTY; without even the implied warranty of
55 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
56 * GNU General Public License for more details.
58 * You should have received a copy of the GNU General Public License
59 * along with GNU shogi; see the file COPYING. If not, write to
60 * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
62 * ------------------------------------------------------------------------
73 static void yyerror();
75 static ShogiMove move_type;
76 static int from_x, from_y, to_x, to_y;
79 char currentMoveString[MSG_SIZ];
80 static char token[20];
82 FILE *outfile = (FILE *)0;
84 extern FILE *gameFileFP, *toFirstProgFP;
85 extern int currentMove;
86 extern char moveList[MAX_MOVES][MOVE_LEN];
88 extern void SendToProgram(char *message, FILE *fp);
89 extern void MakeMove(ShogiMove *move_type, int from_x, int from_y,
95 %token PROMOTE DROPS PIECE SQUARE NUMBER COMMENT COLON
96 %token BLACK_WINS WHITE_WINS DRAW
98 %union { int val; char* string; }
103 comment_list move_elem move_list
107 | comment_list COMMENT
108 { fprintf(stderr, "%s\n", $<string>2); }
112 | move_list move_elem
116 { strcpy(token, "number"); } number
117 { strcpy(token, "promoted"); } promoted
118 { strcpy(token, "move"); } move
122 | NUMBER { strcpy(token, "colon"); } COLON
130 SQUARE { from_x = '9' - $<string>1[0];
131 from_y = 'i' - $<string>1[1];
132 strcpy(currentMoveString,$<string>1);
133 strcpy(token, "square"); }
134 SQUARE { to_x = '9' - $<string>3[0];
135 to_y = 'i' - $<string>3[1];
136 strcat(currentMoveString,$<string>3); }
137 { move_type = NormalMove; }
140 SendToProgram(currentMoveString, toFirstProgFP);
141 strcpy(moveList[currentMove], currentMoveString);
142 MakeMove(&move_type, from_x, from_y, to_x, to_y);
145 PIECE { piece = $<string>1[0];
146 strcpy(currentMoveString,$<string>1);
147 strcpy(token,"'*'"); }
148 DROPS { strcat(currentMoveString,"*");
149 strcpy(token, "square"); }
150 SQUARE { to_x = '9' - $<string>5[0];
151 to_y = 'i' - $<string>5[1];
152 strcat(currentMoveString,$<string>5); }
154 move_type = (BlackOnMove(currentMove) ? BlackDrop : WhiteDrop);
158 case 'P': from_x = 81; break;
159 case 'L': from_x = 82; break;
160 case 'N': from_x = 83; break;
161 case 'S': from_x = 84; break;
162 case 'G': from_x = 85; break;
163 case 'B': from_x = 86; break;
164 case 'R': from_x = 87; break;
165 case 'K': from_x = 88; break;
166 default: from_x = -1;
170 SendToProgram(currentMoveString, toFirstProgFP);
171 strcpy(moveList[currentMove], currentMoveString);
172 MakeMove(&move_type, from_x, from_y, to_x, to_y);
176 loaded_game_finished = 1;
177 DisplayMessage("Black wins", False);
181 loaded_game_finished = 1;
182 DisplayMessage("White wins", False);
186 loaded_game_finished = 1;
187 DisplayMessage("Draw", False);
193 { move_type = (BlackOnMove(currentMove)
194 ? BlackPromotion : WhitePromotion);
195 strcat(currentMoveString,"+"); }
205 static void yyerror(char *errmsg)
207 if (strlen(token) > 0)
209 fprintf(stderr, "parse error line %d column %d : %s expected\n",
215 fprintf(stderr,"parse error line %d column %d : %s\n",
216 lines, cols, errmsg);