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 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
97
%union { int val; char* string; }
102
comment_list move_elem move_list
106
| comment_list COMMENT
107
{ fprintf(stderr, "%s\n", $<string>2); }
111
| move_list move_elem
115
{ strcpy(token, "number"); } number
116
{ strcpy(token, "promoted"); } promoted
117
{ strcpy(token, "move"); } move
121
| NUMBER { strcpy(token, "colon"); } COLON
129
SQUARE { from_x = '9' - $<string>1[0];
130
from_y = 'i' - $<string>1[1];
131
strcpy(currentMoveString,$<string>1);
132
strcpy(token, "square"); }
133
SQUARE { to_x = '9' - $<string>3[0];
134
to_y = 'i' - $<string>3[1];
135
strcat(currentMoveString,$<string>3); }
136
{ move_type = NormalMove; }
139
SendToProgram(currentMoveString, toFirstProgFP);
140
strcpy(moveList[currentMove], currentMoveString);
141
MakeMove(&move_type, from_x, from_y, to_x, to_y);
144
PIECE { piece = $<string>1[0];
145
strcpy(currentMoveString,$<string>1);
146
strcpy(token,"'*'"); }
147
DROPS { strcat(currentMoveString,"*");
148
strcpy(token, "square"); }
149
SQUARE { to_x = '9' - $<string>5[0];
150
to_y = 'i' - $<string>5[1];
151
strcat(currentMoveString,$<string>5); }
153
move_type = (BlackOnMove(currentMove) ? BlackDrop : WhiteDrop);
157
case 'P': from_x = 81; break;
158
case 'L': from_x = 82; break;
159
case 'N': from_x = 83; break;
160
case 'S': from_x = 84; break;
161
case 'G': from_x = 85; break;
162
case 'B': from_x = 86; break;
163
case 'R': from_x = 87; break;
164
case 'K': from_x = 88; break;
165
default: from_x = -1;
169
SendToProgram(currentMoveString, toFirstProgFP);
170
strcpy(moveList[currentMove], currentMoveString);
171
MakeMove(&move_type, from_x, from_y, to_x, to_y);
177
{ move_type = (BlackOnMove(currentMove) ? BlackPromotion : WhitePromotion);
178
strcat(currentMoveString,"+"); }
188
static void yyerror(char *errmsg)
190
if (strlen(token) > 0)
192
fprintf(stderr, "parse error line %d column %d : %s expected\n",
198
fprintf(stderr,"parse error line %d column %d : %s\n",
199
lines, cols, errmsg);