* Modified implementation of ISS mode for XShogi: Matthias Mutz
* Current maintainer: Michael C. Vanier
*
- * XShogi borrows its piece bitmaps from CRANES Shogi.
+ * XShogi borrows some of its piece bitmaps from CRANES Shogi.
*
* Copyright 1991 by Digital Equipment Corporation, Maynard, Massachusetts.
* Enhancements Copyright 1992 Free Software Foundation, Inc.
#include "bitmaps.h" /* Piece bitmaps. */
#include "xshogifn.h" /* Forward declarations. */
-#define off_board(x) (x < 2 || x > BOARD_SIZE + 1)
+#define off_board(x) ((x < 2) || (x > BOARD_SIZE + 1))
/**********************************************************************
typedef struct
{
- Pixel blackPieceColor;
- Pixel whitePieceColor;
- Pixel lightSquareColor;
- Pixel darkSquareColor;
+ Pixel pieceColor;
+ Pixel squareColor;
Pixel charPieceColor;
Pixel zeroColor;
Pixel oneColor;
XtResource clientResources[] =
{
{
- "blackPieceColor", "BlackPieceColor", XtRPixel, sizeof(Pixel),
- XtOffset(AppDataPtr, blackPieceColor), XtRString,
- BLACK_PIECE_COLOR
- },
- {
- "whitePieceColor", "WhitePieceColor", XtRPixel, sizeof(Pixel),
- XtOffset(AppDataPtr, whitePieceColor), XtRString,
- WHITE_PIECE_COLOR
+ "pieceColor", "pieceColor", XtRPixel, sizeof(Pixel),
+ XtOffset(AppDataPtr, pieceColor), XtRString,
+ PIECE_COLOR
},
{
"charPieceColor", "CharPieceColor", XtRPixel, sizeof(Pixel),
ZERO_COLOR
},
{
- "lightSquareColor", "LightSquareColor", XtRPixel,
- sizeof(Pixel), XtOffset(AppDataPtr, lightSquareColor),
- XtRString, LIGHT_SQUARE_COLOR
- },
- {
- "darkSquareColor", "DarkSquareColor", XtRPixel, sizeof(Pixel),
- XtOffset(AppDataPtr, darkSquareColor), XtRString,
- DARK_SQUARE_COLOR
+ "squareColor", "squareColor", XtRPixel,
+ sizeof(Pixel), XtOffset(AppDataPtr, squareColor),
+ XtRString, SQUARE_COLOR
},
{
"westernPieceSet", "WesternPieceSet", XtRBoolean, sizeof(Boolean),
struct DisplayData
{
-
AppData appData;
Arg shellArgs[6];
int xScreen;
Window xBoardWindow;
- GC lightSquareGC, darkSquareGC, lineGC, wdPieceGC, wlPieceGC,
- woPieceGC, boPieceGC, bdPieceGC, blPieceGC, wbPieceGC,
- bwPieceGC, coordGC, dropPiece;
-
- GC charPieceGC;
+ GC squareGC, lineGC, pieceGC, oPieceGC, charPieceGC,
+ squareOffBoardGC, coordGC, dropPiece;
Font mainFontID, coordFontID;
XFontStruct *mainFontStruct, *coordFontStruct;
};
-int pieceisWhite[] =
-{
- False, False, False, False, False, False, False,
- False, False, False, False, False, False, False,
- True, True, True, True, True, True, True,
- True, True, True, True, True, True, True,
- False
-};
-
-
-
ShogiSquare pieceToPromoted[] =
{
BlackPPawn, BlackPLance, BlackPKnight, BlackPSilver, BlackGold,
XrmOptionDescRec shellOptions[] =
{
- { "-blackPieceColor", "blackPieceColor", XrmoptionSepArg, NULL },
- { "-bpc", "blackPieceColor", XrmoptionSepArg, NULL },
- { "-whitePieceColor", "whitePieceColor", XrmoptionSepArg, NULL },
- { "-wpc", "whitePieceColor", XrmoptionSepArg, NULL },
+ { "-pieceColor", "pieceColor", XrmoptionSepArg, NULL },
+ { "-pc", "pieceColor", XrmoptionSepArg, NULL },
{ "-charPieceColor", "charPieceColor", XrmoptionSepArg, NULL },
{ "-cpc", "charPieceColor", XrmoptionSepArg, NULL },
{ "-zeroColor", "zeroColor", XrmoptionSepArg, NULL },
{ "-zc", "zeroColor", XrmoptionSepArg, NULL },
{ "-oneColor", "oneColor", XrmoptionSepArg, NULL },
{ "-oc", "oneColor", XrmoptionSepArg, NULL },
- { "-lightSquareColor", "lightSquareColor", XrmoptionSepArg, NULL },
- { "-lsc", "lightSquareColor", XrmoptionSepArg, NULL },
- { "-darkSquareColor", "darkSquareColor", XrmoptionSepArg, NULL },
- { "-dsc", "darkSquareColor", XrmoptionSepArg, NULL },
+ { "-squareColor", "squareColor", XrmoptionSepArg, NULL },
+ { "-sc", "squareColor", XrmoptionSepArg, NULL },
{ "-westernPieceSet", "westernPieceSet", XrmoptionSepArg, NULL },
{ "-wps", "westernPieceSet", XrmoptionSepArg, NULL },
{ "-movesPerSession", "movesPerSession", XrmoptionSepArg, NULL },
static FileModeInfo fmi;
+/*
+ * This is a hack that allows the parser to tell the program
+ * that the game it's loading has ended.
+ */
+
+int loaded_game_finished = 0;
+
+
/**********************************************************************
*
* End of globals.
player->xScreen = DefaultScreen(player->xDisplay);
}
+#undef DONT_ADJUST_BOARDSIZE
+#ifndef DONT_ADJUST_BOARDSIZE
if (((DisplayWidth(player->xDisplay, player->xScreen) < 800)
|| (DisplayHeight(player->xDisplay, player->xScreen) < 800))
&& (player->boardSize == Large))
{
player->boardSize = Medium;
}
+#endif
switch (player->boardSize)
{
if (player->appData.clockMode)
{
- /* sprintf(buf, "Black: %s ", TimeString(timeControl));
- timerWidth = XTextWidth(player->mainFontStruct,
- buf, strlen(buf)); */
timerWidth = XTextWidth(player->mainFontStruct,
"Black: 8:88:88 ", 15);
}
XtSetArg(args[0], XtNwidth, &commandsWidth);
XtGetValues(player->commandsWidget, args, 1);
w = ((commandsWidth > boardWidth) ? commandsWidth : boardWidth);
- XtSetArg(args[0], XtNwidth, w - timerWidth*2 - 12);
+ XtSetArg(args[0], XtNwidth, w - timerWidth * 2 - 12);
XtSetValues(player->titleWidget, args, 1);
XtSetArg(args[0], XtNwidth, w - 8);
XtSetValues(player->messageWidget, args, 1);
/*
- * formWidget uses these constraints but they are stored
+ * 'formWidget' uses these constraints but they are stored
* in the children.
*/
player->iconPixmap =
XCreateBitmapFromData(player->xDisplay,
XtWindow(player->shellWidget),
- icon_bits, icon_width, icon_height);
+ (char *)icon_bits, icon_width, icon_height);
XtSetArg(args[0], XtNiconPixmap, player->iconPixmap);
XtSetValues(player->shellWidget, args, 1);
xshogiDebug = localPlayer.appData.debugMode;
/*
- * Determine matchMode state -- poor man's resource converter
+ * Determine matchMode state -- poor man's resource converter.
*/
if (strcasecmp(localPlayer.appData.matchMode, "Init") == 0)
gc_values.foreground
= XWhitePixel(player->xDisplay, player->xScreen);
gc_values.background
- = XBlackPixel(player->xDisplay, player->xScreen);
- player->lightSquareGC = player->darkSquareGC = player->wbPieceGC
- = XtGetGC(player->shellWidget, value_mask, &gc_values);
- gc_values.foreground
- = XBlackPixel(player->xDisplay, player->xScreen);
- gc_values.background
= XWhitePixel(player->xDisplay, player->xScreen);
- player->bwPieceGC
+
+ /* empty square off board */
+ player->squareOffBoardGC
+ = XtGetGC(player->shellWidget, value_mask, &gc_values);
+
+ /* empty square on board */
+ player->squareGC
= XtGetGC(player->shellWidget, value_mask, &gc_values);
}
else
{
- /* white piece black background */
- gc_values.foreground
- = XWhitePixel(player->xDisplay, player->xScreen);
- gc_values.background
- = XBlackPixel(player->xDisplay, player->xScreen);
- player->wbPieceGC
- = XtGetGC(player->shellWidget, value_mask, &gc_values);
+ Pixel bg; /* background color */
+ Arg args[1];
- /* black piece white background */
- gc_values.foreground
- = XBlackPixel(player->xDisplay, player->xScreen);
- gc_values.background
- = XWhitePixel(player->xDisplay, player->xScreen);
- player->bwPieceGC
- = XtGetGC(player->shellWidget, value_mask, &gc_values);
+ /* Get background color. */
+ XtSetArg(args[0], XtNbackground, &bg);
+ XtGetValues(player->shellWidget, args, 1);
- /* light empty square */
- gc_values.foreground
- = player->appData.lightSquareColor;
- gc_values.background
- = player->appData.darkSquareColor;
- player->lightSquareGC
+ /* empty square off board */
+ gc_values.foreground = gc_values.background = bg;
+ player->squareOffBoardGC
= XtGetGC(player->shellWidget, value_mask, &gc_values);
- /* dark empty square */
+ /* empty square on board */
gc_values.foreground
- = player->appData.darkSquareColor;
+ = player->appData.squareColor;
gc_values.background
- = player->appData.lightSquareColor;
- player->darkSquareGC
+ = player->appData.squareColor;
+ player->squareGC
= XtGetGC(player->shellWidget, value_mask, &gc_values);
- /* black piece on dark square */
- gc_values.background
- = player->appData.blackPieceColor;
- gc_values.foreground
- = player->appData.darkSquareColor;
- player->bdPieceGC
- = XtGetGC(player->shellWidget, value_mask, &gc_values);
-
- /* black piece on light square */
- gc_values.background
- = player->appData.blackPieceColor;
- gc_values.foreground
- = player->appData.lightSquareColor;
- player->blPieceGC
- = XtGetGC(player->shellWidget, value_mask, &gc_values);
-
- /* white piece on dark square */
- gc_values.background
- = player->appData.whitePieceColor;
+ /* piece off board */
gc_values.foreground
- = player->appData.darkSquareColor;
- player->wdPieceGC
- = XtGetGC(player->shellWidget, value_mask, &gc_values);
-
- /* white piece on dark square */
- gc_values.background
- = player->appData.whitePieceColor;
- gc_values.foreground
- = player->appData.lightSquareColor;
- player->wlPieceGC
+ = player->appData.pieceColor;
+ gc_values.background = bg;
+ player->oPieceGC
= XtGetGC(player->shellWidget, value_mask, &gc_values);
- /* black piece off board */
- gc_values.background
- = player->appData.blackPieceColor;
+ /* piece on board */
gc_values.foreground
- = XWhitePixel(player->xDisplay, player->xScreen);
- player->boPieceGC
- = XtGetGC(player->shellWidget, value_mask, &gc_values);
-
- /* white piece off board */
+ = player->appData.pieceColor;
gc_values.background
- = player->appData.whitePieceColor;
- gc_values.foreground
- = XWhitePixel(player->xDisplay, player->xScreen);
- player->woPieceGC
+ = player->appData.squareColor;
+ player->pieceGC
= XtGetGC(player->shellWidget, value_mask, &gc_values);
/* piece symbol */
+ /*
+ * FIXME: charPieceColor seems to have no effect;
+ * the bitmap is *always* black.
+ */
gc_values.function = (player->black_pixel_is_zero ? GXand : GXor);
gc_values.foreground
- = XBlackPixel(player->xDisplay, player->xScreen);
+ = player->appData.charPieceColor;
gc_values.background
- = XWhitePixel(player->xDisplay, player->xScreen);
+ = player->appData.charPieceColor;
+
player->charPieceGC
= XtGetGC(player->shellWidget, value_mask, &gc_values);
}
ReadBitmap(player->appData.reverseBigSolidBitmap,
&player->reverseBigSolidBitmap,
NULL,
- bigsolidR_bits, bigsolidR_bits, bigsolidR_bits);
+ bigsolidR_bits, bigsolidR_m_bits, bigsolidR_l_bits);
ReadBitmap(player->appData.reverseSmallSolidBitmap,
&player->reverseSmallSolidBitmap,
NULL,
- smallsolidR_bits, smallsolidR_bits, smallsolidR_bits);
+ smallsolidR_bits, smallsolidR_m_bits, smallsolidR_l_bits);
ReadBitmap(player->appData.normalBigSolidBitmap,
&player->normalBigSolidBitmap,
NULL,
- bigsolid_bits, bigsolid_bits, bigsolid_bits);
+ bigsolid_bits, bigsolid_m_bits, bigsolid_l_bits);
ReadBitmap(player->appData.normalSmallSolidBitmap,
&player->normalSmallSolidBitmap,
NULL,
- smallsolid_bits, smallsolid_bits, smallsolid_bits);
+ smallsolid_bits, smallsolid_m_bits, smallsolid_l_bits);
ReadBitmap(player->appData.reversePawnBitmap,
&player->reversePawnBitmap,
void
ReadBitmap(String name, Pixmap *pm, Pixmap *qm,
- char *small_bits, char *medium_bits, char *large_bits)
+ unsigned char *small_bits,
+ unsigned char *medium_bits,
+ unsigned char *large_bits)
{
int x_hot, y_hot;
- u_int w, h;
+ unsigned int w, h;
if ((name == NULL)
|| (ReadBitmapFile(player->xDisplay, player->xBoardWindow, name,
case Large:
*pm = XCreatePixmapFromBitmapData(player->xDisplay,
player->xBoardWindow,
- large_bits,
+ (char *)large_bits,
player->squareSize,
player->squareSize,
fg, bg, depth);
case Medium:
*pm = XCreatePixmapFromBitmapData(player->xDisplay,
player->xBoardWindow,
- medium_bits,
+ (char *)medium_bits,
player->squareSize,
player->squareSize,
fg, bg, depth);
case Small:
*pm = XCreatePixmapFromBitmapData(player->xDisplay,
player->xBoardWindow,
- small_bits,
+ (char *)small_bits,
player->squareSize,
player->squareSize,
fg, bg, depth);
= LINE_GAP / 2 + (i * (player->squareSize + LINE_GAP));
player->gridSegments[i].x2 = LINE_GAP + BOARD_SIZE *
(player->squareSize + LINE_GAP) + offset;
- player->gridSegments[i + BOARD_SIZE + 1].x1
+ player->gridSegments[i + BOARD_SIZE + 1].x1
= player->gridSegments[i + BOARD_SIZE + 1].x2 = LINE_GAP / 2
+ (i * (player->squareSize + LINE_GAP)) + offset;
- player->gridSegments[i + BOARD_SIZE + 1].y2
+ player->gridSegments[i + BOARD_SIZE + 1].y2
= BOARD_SIZE * (player->squareSize + LINE_GAP);
}
}
blackPieceMenu, NULL, 0);
selection = pieceMenuTranslation[0][i];
XtAddCallback(entry, XtNcallback,
- (XtCallbackProc) PieceMenuSelect,
- (caddr_t)selection);
+ (XtCallbackProc)PieceMenuSelect,
+ (XtPointer)selection);
if (selection == BlackPawn)
{
whitePieceMenu, NULL, 0);
selection = pieceMenuTranslation[1][i];
XtAddCallback(entry, XtNcallback,
- (XtCallbackProc) PieceMenuSelect,
- (caddr_t)selection);
+ (XtCallbackProc)PieceMenuSelect,
+ (XtPointer)selection);
if (selection == WhitePawn)
{
void
PieceMenuPopup(Widget w, XEvent *event, String *params, Cardinal *num_params)
{
- if (event->type != ButtonPress)
+ if (event->type != ButtonPress)
return;
- if (gameMode != EditPosition)
+ if (gameMode != EditPosition)
return;
- if (((pmFromX = EventToXSquare(event->xbutton.x)) < 1)
- || (pmFromX > BOARD_SIZE + 2)
+ if (((pmFromX = EventToXSquare(event->xbutton.x)) < 1)
+ || (pmFromX > BOARD_SIZE + 2)
|| ((pmFromY = EventToSquare(event->xbutton.y)) < 0))
{
pmFromX = pmFromY = -1;
static void
-PieceMenuSelect(Widget w, ShogiSquare piece, caddr_t junk)
+PieceMenuSelect(Widget w, ShogiSquare piece, char *junk)
{
if ((pmFromX < 0) || (pmFromY < 0))
return;
{
int saveCM;
- if (gameMode != EditPosition)
+ if (gameMode != EditPosition)
return;
whitePlaysFirst = False;
{
int saveCM;
- if (gameMode != EditPosition)
+ if (gameMode != EditPosition)
return;
whitePlaysFirst = True;
{
/* empty square off board */
XFillRectangle(player->xDisplay, player->xBoardWindow,
- player->wbPieceGC,
+ player->squareOffBoardGC,
x, y, player->squareSize,
player->squareSize);
}
else
{
/* empty square on board */
- XFillRectangle(player->xDisplay, player->xBoardWindow,
- ((square_color == LIGHT)
- ? player->lightSquareGC
- : player->darkSquareGC),
- x, y, player->squareSize,
+ XFillRectangle(player->xDisplay,
+ player->xBoardWindow,
+ player->squareGC,
+ x, y,
+ player->squareSize,
player->squareSize);
}
}
- else if (player->monoMode)
+ else if (player->monoMode) /* Draw a piece in mono mode. */
{
- /* in mono mode */
- if (square_color == LIGHT)
- {
- XCopyArea(player->xDisplay,
- ((((((int)piece) < ((int)WhitePawn)))
- ^ player->flipView)
- ? *pieceToNormal[remote][(int)piece]
- : *pieceToReverse[remote][(int)piece]),
- player->xBoardWindow,
- (player->monoMode
- ? player->wbPieceGC
- : player->wlPieceGC),
- 0, 0,
- player->squareSize, player->squareSize, x, y);
- }
- else
- {
- XCopyArea(player->xDisplay,
- ((((((int)piece) < ((int)WhitePawn)))
- ^ player->flipView)
- ? *pieceToNormal[remote][(int)piece]
- : *pieceToReverse[remote][(int)piece]),
- player->xBoardWindow,
- (player->monoMode
- ? player->bwPieceGC
- : player->blPieceGC),
- 0, 0,
- player->squareSize, player->squareSize, x, y);
- }
+ XCopyArea(player->xDisplay,
+ ((((((int)piece) < ((int)WhitePawn)))
+ ^ player->flipView)
+ ? *pieceToNormal[remote][(int)piece]
+ : *pieceToReverse[remote][(int)piece]),
+ player->xBoardWindow,
+ (player->monoMode
+ ? player->squareOffBoardGC /* ??? FIXME? */
+ : player->pieceGC),
+ 0, 0,
+ player->squareSize, player->squareSize, x, y);
}
- else
+ else /* Draw a piece in color mode. */
{
- /* in color mode */
- if ((column < 0) || (column >= BOARD_SIZE))
+ if ((column < 0) || (column >= BOARD_SIZE)) /* off board */
{
- /* off board */
- XCopyPlane(player->xDisplay,
- ((((((int)piece) < ((int)WhitePawn)))
- ^ player->flipView)
- ? *pieceToNormalSolid[remote][(int)piece]
- : *pieceToReverseSolid[remote][(int)piece]),
- player->xBoardWindow,
- (pieceisWhite[(int)piece]
- ? player->woPieceGC
- : player->boPieceGC),
- 0, 0,
- player->squareSize, player->squareSize, x, y, 1);
+ /* draw piece background */
- XCopyArea(player->xDisplay,
- ((((((int)piece) < ((int)WhitePawn)))
- ^ player->flipView)
- ? *pieceToNormal[remote][(int)piece]
- : *pieceToReverse[remote][(int)piece]),
- player->xBoardWindow,
- player->charPieceGC,
- 0, 0,
- player->squareSize, player->squareSize, x, y);
- }
- else if (square_color == LIGHT)
- {
- /* on board, light square */
XCopyPlane(player->xDisplay,
((((((int)piece) < ((int)WhitePawn)))
^ player->flipView)
? *pieceToNormalSolid[remote][(int)piece]
: *pieceToReverseSolid[remote][(int)piece]),
player->xBoardWindow,
- pieceisWhite[(int)piece]
- ? player->wlPieceGC
- : player->blPieceGC,
+ player->oPieceGC,
0, 0,
player->squareSize, player->squareSize, x, y, 1);
+ /* draw piece bitmap */
+
XCopyArea(player->xDisplay,
((((((int)piece) < ((int)WhitePawn)))
^ player->flipView)
0, 0,
player->squareSize, player->squareSize, x, y);
}
- else
+ else /* on board */
{
- /* on board, dark square */
+ /* draw piece background */
+
XCopyPlane(player->xDisplay,
((((((int)piece) < ((int)WhitePawn)))
^ player->flipView)
? *pieceToNormalSolid[remote][(int)piece]
: *pieceToReverseSolid[remote][(int)piece]),
player->xBoardWindow,
- (pieceisWhite[(int)piece]
- ? player->wdPieceGC
- : player->bdPieceGC),
+ player->pieceGC,
0, 0,
player->squareSize, player->squareSize, x, y, 1);
+ /* draw piece bitmap */
+
XCopyArea(player->xDisplay,
((((((int)piece) < ((int)WhitePawn)))
^ player->flipView)
player->charPieceGC,
0, 0,
player->squareSize, player->squareSize, x, y);
- }
+ }
}
+
string[1] = NULLCHAR;
if (player->showCoords
void
-EventProc(Widget widget, caddr_t client_data, XEvent *event)
+EventProc(Widget widget, XtPointer client_data, XEvent *event)
{
if (event->type == MappingNotify)
{
DrawSquare(y, x, catchedIndexToPiece[Color][F]);
ShowCount(y, (Color ? (x - 1) : (x + 1)), c);
- if (Color)
+ if (Color)
y--;
else
y++;
DrawSquare(y, x, EmptySquare);
ShowCount(y, (Color ? (x - 1) : (x + 1)), 0);
- if (Color)
+ if (Color)
y--;
else
y++;
{
if (catches[currentMove][Color][F] > 0)
{
- if (Color)
+ if (Color)
y--;
- else
+ else
y++;
}
}
if (color)
{
- if (x != 1)
+ if (x != 1)
return (no_piece);
y = 8 - y;
}
else
{
- if (x != 11)
+ if (x != 11)
return no_piece;
}
{
if (catches[currentMove][color][F] > 0)
{
- if (n == y)
+ if (n == y)
return F;
n++;
break;
case ButtonRelease:
- if ((fromX < 0) || (fromY < 0))
+ if ((fromX < 0) || (fromY < 0))
return;
if (((to_x = EventToXSquare(event->xbutton.x)) < 1)
if (updateRemotePlayer
&& (BlackOnMove(forwardMostMove) == fromRemotePlayer))
{
- DisplayMessage("do not drop opponent pieces",
+ DisplayMessage("Do not try to drop your opponent's pieces!",
fromRemotePlayer);
fromX = fromY = -1;
return;
&& updateRemotePlayer
&& ((from_piece < WhitePawn) == fromRemotePlayer))
{
- DisplayMessage("do not move opponent pieces",
+ DisplayMessage("Do not try to move your opponent's pieces!",
fromRemotePlayer);
fromX = fromY = -1;
return;
sprintf(user_move, "%c%c%c%c+\n",
'9' - fromX, 'i' - fromY, '9' - to_x, 'i' - to_y);
break;
-
+
case BlackDrop:
case WhiteDrop:
sprintf(user_move, "%c*%c%c\n",
catchedIndexToChar[fromX - 81], '9' - to_x, 'i' - to_y);
break;
-
+
case NormalMove:
sprintf(user_move, "%c%c%c%c\n",
'9' - fromX, 'i' - fromY, '9' - to_x, 'i' - to_y);
break;
-
+
default:
fprintf(stderr, "%s: internal error; bad move_type\n",
(char *)programName);
{
switch (machine_move[0])
{
- case 'P':
+ case 'P':
*from_x = 81;
break;
- case 'L':
+ case 'L':
*from_x = 82;
break;
- case 'N':
+ case 'N':
*from_x = 83;
break;
- case 'S':
+ case 'S':
*from_x = 84;
break;
- case 'G':
+ case 'G':
*from_x = 85;
break;
- case 'B':
+ case 'B':
*from_x = 86;
break;
- case 'R':
+ case 'R':
*from_x = 87;
break;
- case 'K':
+ case 'K':
*from_x = 88;
break;
- default:
+ default:
*from_x = -1;
}
switch (machine_move[4])
{
case '+':
- *move_type = (BlackOnMove(forwardMostMove)
+ *move_type = (BlackOnMove(forwardMostMove)
? BlackPromotion : WhitePromotion);
break;
fprintf(stderr,
"%s: failed to start shogi program %s on %s: %s\n",
programName,
- ((fp == fromFirstProgFP)
+ ((fp == fromFirstProgFP)
? localPlayer.appData.firstShogiProgram
: localPlayer.appData.secondShogiProgram),
((fp == fromFirstProgFP)
return;
}
- if (forwardMostMove <= backwardMostMove)
+ if (forwardMostMove <= backwardMostMove)
return;
- if (gameMode == PauseGame)
+ if (gameMode == PauseGame)
PauseProc(NULL, NULL, NULL, NULL);
if (gameMode == PlayFromGameFile)
currentMove = --forwardMostMove;
- if ((gameMode == PlayFromGameFile)
+ if ((gameMode == PlayFromGameFile)
|| (gameMode == ForceMoves))
DisplayClocks(ReDisplayTimers);
else
if (xshogiDebug)
{
printf("from '%s' synchronize %s clock %ld\n",
- message,
+ message,
(BlackOnMove(forwardMostMove)
- ? "Black's"
- : "White's"),
+ ? "Black's"
+ : "White's"),
time_remaining);
}
if (xshogiDebug)
{
printf("from '%s' synchronize %s clock %ld\n",
- message,
+ message,
((!BlackOnMove(forwardMostMove))
- ? "Black's" : "White's"),
+ ? "Black's" : "White's"),
time_remaining);
}
putc(BELLCHAR, stderr);
if ((gameMode == TwoMachinesPlay)
- || ((gameMode == PauseGame)
+ || ((gameMode == PauseGame)
&& (pausePreviousMode == TwoMachinesPlay)))
{
strcat(machine_move, "\n");
if (gameFileFP == NULL)
return (int)False;
- if (gameMode == PauseGame)
+ if (gameMode == PauseGame)
return True;
if (gameMode != PlayFromGameFile)
lastGameMode = gameMode;
gameMode = ForceMoves;
ModeHighlight();
- DisplayMessage("End of game file", False);
+
+ if (!loaded_game_finished)
+ DisplayMessage("End of game file", False);
if (readGameXID != 0)
{
-/*
+/*
* Apply a move to the given board. Oddity: move_type is ignored on input
* unless the move is seen to be a pawn promotion, in which case move_type
* tells us what to promote to.
if (gameMode == PlayFromGameFile)
{
- sprintf(message, "%d. %s%s",
+ sprintf(message, "%d. %s%s",
((currentMove + 1) / 2),
- (BlackOnMove(currentMove) ? "... " : ""),
+ (BlackOnMove(currentMove) ? "... " : ""),
currentMoveString);
strcpy(parseList[currentMove - 1], currentMoveString);
}
MakeAlg(from_x, from_y, to_x, to_y, promoPiece,
currentMove - 1, movestr);
- sprintf(message, "%d. %s%s",
+ sprintf(message, "%d. %s%s",
((currentMove + 1) / 2),
- (BlackOnMove(currentMove) ? "... " : ""),
+ (BlackOnMove(currentMove) ? "... " : ""),
movestr);
strcpy(parseList[currentMove - 1], movestr);
}
DisplayMessage(message, False);
- if ((gameMode == PlayFromGameFile) || (gameMode == ForceMoves)
- || ((gameMode == PauseGame)
+ if ((gameMode == PlayFromGameFile) || (gameMode == ForceMoves)
+ || ((gameMode == PauseGame)
&& (pausePreviousMode == PlayFromGameFile)))
{
DisplayClocks(ReDisplayTimers);
int dummy_source;
XtInputId dummy_id;
- if (localPlayer.appData.noShogiProgram)
+ if (localPlayer.appData.noShogiProgram)
return;
signal(SIGPIPE, CatchPipeSignal);
XtSetArg(args[1], XtNheight, &pw_height);
XtGetValues(player->promotionShell, args, 2);
- XtTranslateCoords(player->boardWidget,
+ XtTranslateCoords(player->boardWidget,
((bw_width - pw_width) / 2),
- (LINE_GAP
- + player->squareSize / 3
- + (((piece == BlackPawn) ^ (player->flipView))
- ? 0
+ (LINE_GAP
+ + player->squareSize / 3
+ + (((piece == BlackPawn) ^ (player->flipView))
+ ? 0
: (6 * (player->squareSize + LINE_GAP)))),
&x, &y);
XtDestroyWidget(w);
player->promotionUp = False;
- if (fromX == -1)
+ if (fromX == -1)
return;
if (strcmp(name, "Yes") == 0)
(*buttonProcs[list_return->list_index])
(w, NULL, NULL, &fromRemotePlayer);
- if (!filenameUp)
+ if (!filenameUp)
ModeHighlight();
}
if (gameMode != BeginningOfGame)
{
- DisplayMessage("Press Reset first", False);
+ DisplayMessage("Press Reset first.", False);
return;
}
{
char buf[MSG_SIZ];
+ loaded_game_finished = 0;
+
if (gameMode != BeginningOfGame)
{
DisplayMessage("Press Reset first", False);
-/*
+/*
* Restart the shogi program and feed it all the moves made so far.
* Used when the user wants to back up from end of game, when gnushogi
- * has already exited. Assumes gameMode == EndOfGame.
+ * has already exited. Assumes gameMode == EndOfGame.
*/
void
}
if (BlackOnMove((gameMode == ForceMoves)
- ? currentMove
+ ? currentMove
: forwardMostMove))
{
- DisplayMessage("It is not White's turn", False);
+ DisplayMessage("It is not White's turn.", False);
return;
}
- if (gameMode == ForceMoves)
+ if (gameMode == ForceMoves)
forwardMostMove = currentMove;
lastGameMode = gameMode = MachinePlaysWhite;
}
if (!BlackOnMove((gameMode == ForceMoves)
- ? currentMove
+ ? currentMove
: forwardMostMove))
{
- DisplayMessage("It is not Black's turn", False);
+ DisplayMessage("It is not Black's turn.", False);
return;
}
- if (gameMode == ForceMoves)
+ if (gameMode == ForceMoves)
forwardMostMove = currentMove;
lastGameMode = gameMode = MachinePlaysBlack;
if (updateRemotePlayer)
{
- DisplayMessage("Forward button disabled", fromRemotePlayer);
+ DisplayMessage("Forward button disabled.", fromRemotePlayer);
return;
}
if (fromRemotePlayer)
{
- DisplayMessage("only your opponent may reset the game",
+ DisplayMessage("Only your opponent may reset the game.",
fromRemotePlayer);
return;
}
if (gameMode != BeginningOfGame)
{
- DisplayMessage("Press Reset first", False);
+ DisplayMessage("Press Reset first.", False);
return (int)False;
}
if (updateRemotePlayer)
{
- DisplayMessage("you are already in challenge mode",
+ DisplayMessage("You are already in challenge mode.",
fromRemotePlayer);
return;
}
if (gameMode != BeginningOfGame)
{
- DisplayMessage("Press Reset first", False);
+ DisplayMessage("Press Reset first.", False);
return;
}
if ((BlackOnMove(forwardMostMove) && (gameMode == MachinePlaysBlack))
|| (!BlackOnMove(forwardMostMove) && (gameMode == MachinePlaysWhite)))
{
- DisplayMessage("Wait until your turn", False);
+ DisplayMessage("Wait until your turn.", False);
}
else
{
if ((!BlackOnMove(forwardMostMove) && (gameMode == MachinePlaysBlack))
|| (BlackOnMove(forwardMostMove) && (gameMode == MachinePlaysWhite)))
{
- DisplayMessage("Wait until machines turn", False);
+ DisplayMessage("Wait until machine's turn.", False);
}
else
{
if (gameMode != BeginningOfGame)
{
- DisplayMessage("Press Reset first", False);
+ DisplayMessage("Press Reset first.", False);
return;
}
if (gameMode != BeginningOfGame)
{
- DisplayMessage("Press Reset first", False);
+ DisplayMessage("Press Reset first.", False);
return False;
}
return;
}
- if (gameMode == EditPosition)
+ if (gameMode == EditPosition)
return;
ForceProc(w, event, prms, nprms);
- if (gameMode != ForceMoves)
+ if (gameMode != ForceMoves)
return;
DisplayName("<-- Press to set side to play next");
* Widget w
* XEvent *event
* String *prms
- * Cardinal *nprms
+ * Cardinal *nprms
*
* RETURN VALUE
* void
return;
}
- /*
+ /*
* Why do we need this here?
*/
return;
}
- if (localPlayer.appData.noShogiProgram)
+ if (localPlayer.appData.noShogiProgram)
return;
switch (gameMode)
return;
}
- if (gameMode == PauseGame)
+ if (gameMode == PauseGame)
PauseProc(w, event, prms, nprms);
- if (gameMode == PlayFromGameFile)
+ if (gameMode == PlayFromGameFile)
ForceProc(w, event, prms, nprms);
- if ((gameMode == EndOfGame)
+ if ((gameMode == EndOfGame)
|| (gameMode == TwoMachinesPlay)
|| localPlayer.appData.noShogiProgram)
{
case MachinePlaysWhite:
ForceProc(w, event, prms, nprms);
- if (gameMode != ForceMoves)
+ if (gameMode != ForceMoves)
return;
matchKind = MatchOpening;
return;
if (((gameMode == MachinePlaysWhite)
- && !BlackOnMove(forwardMostMove))
+ && !BlackOnMove(forwardMostMove))
|| ((gameMode == MachinePlaysBlack) &&
BlackOnMove(forwardMostMove)))
{
void
SendToProgram(char *message, FILE *fp)
{
- if (fp == NULL)
+ if (fp == NULL)
return;
lastMsgFP = fp;
ReceiveFromProgram(FILE *fp, int *source, XtInputId *id)
{
char message[MSG_SIZ], *end_str, *number, *name;
- extern const char *const sys_errlist[];
if (fgets(message, MSG_SIZ, fp) == NULL)
{
{
sprintf(message,
"error reading from %s shogi program (%s): %s",
- number, name, sys_errlist[ferror(fp)]);
+ number, name, strerror(ferror(fp)));
fprintf(stderr, "%s: %s\n", programName, message);
}
{
char message[MSG_SIZ];
- if (localPlayer.appData.searchDepth <= 0)
+ if (localPlayer.appData.searchDepth <= 0)
return;
sprintf(message, "depth\n%d\nhelp\n", localPlayer.appData.searchDepth);
opptime = blackTimeRemaining;
}
- if (comtime <= 0)
+ if (comtime <= 0)
comtime = 1000;
- if (opptime <= 0)
+ if (opptime <= 0)
opptime = 1000;
sprintf(message, "time %ld\n", comtime / 10);
}
else
{
- sprintf(message, "%d. %s%s %s",
+ sprintf(message, "%d. %s%s %s",
(moveNumber / 2 + 1),
(BlackOnMove(moveNumber) ? "" : "... "),
parseList[moveNumber],
-/* CHECKME: does this work?
- * This routine sends a SIGINT (^C interrupt) to gnushogi to awaken it
+/*
+ * This routine used to send a SIGINT (^C interrupt) to gnushogi to awaken it
* if it might be busy thinking on our time. This normally isn't needed,
- * but is useful on systems where the FIONREAD ioctl doesn't work since
- * on those systems the gnushogi feature that lets you interrupt its thinking
+ * but is useful on systems where the FIONREAD ioctl doesn't work since
+ * on those systems the gnushogi feature that lets you interrupt its thinking
* just by typing a command does not work.
*
- * In the future, similar code could be used to stop gnushogi and make
- * it move immediately when it is thinking about its own move; this could
- * be useful if we want to make Backward or ForceMoves work while gnushogi
- * is thinking.
+ * Now gnushogi periodically checks for user input without a need for
+ * this hack.
*/
void
Attention(int pid)
{
-#if !defined(FIONREAD)
+#if 0
if (localPlayer.appData.noShogiProgram || (pid == 0))
return;
if (!localPlayer.appData.clockMode)
return;
- if (forwardMostMove == 0)
+ if (forwardMostMove == 0)
return;
/*
PartialTickLength(void)
{
struct timeval tv;
- struct timezone tz;
int ptl;
- gettimeofday(&tv, &tz);
+ gettimeofday(&tv, NULL);
ptl = ((tv.tv_sec - tickStartTV.tv_sec) * 1000000 +
(tv.tv_usec - tickStartTV.tv_usec) + 500) / 1000;
- if (ptl > tickLength)
+ if (ptl > tickLength)
ptl = tickLength;
return ptl;
* We give the human user a slight advantage if he is playing black---the
* clocks don't run until he makes his first move, so it takes zero time.
* Also, DisplayClocks doesn't account for network lag so it could get out
- * of sync with GNU Shogi's clock -- but then, referees are always right.
+ * of sync with GNU Shogi's clock -- but then, referees are always right.
*/
void
DisplayClocks(int clock_mode)
{
-#ifdef HAVE_GETTIMEOFDAY
- struct timezone tz;
-#endif /* HAVE_GETTIMEOFDAY */
-
long timeRemaining;
switch (clock_mode)
case DecrementTimers:
/* Decrement running clock to next 1-second boundary */
- if (gameMode == PauseGame)
+ if (gameMode == PauseGame)
return;
timerXID = 0;
- if (!localPlayer.appData.clockMode)
+ if (!localPlayer.appData.clockMode)
return;
if (BlackOnMove(forwardMostMove))
#ifdef HAVE_GETTIMEOFDAY
tickLength = (((timeRemaining <= 1000) && (timeRemaining > 0))
? 100 : 1000);
- gettimeofday(&tickStartTV, &tz);
+ gettimeofday(&tickStartTV, NULL);
#endif /* HAVE_GETTIMEOFDAY */
timerXID =
CheckTimeControl();
DisplayLabels();
- if (!localPlayer.appData.clockMode)
+ if (!localPlayer.appData.clockMode)
return;
if ((gameMode == PauseGame)
- && ((pausePreviousMode == MachinePlaysBlack)
+ && ((pausePreviousMode == MachinePlaysBlack)
|| (pausePreviousMode == MachinePlaysWhite)))
{
return;
}
- timeRemaining = (BlackOnMove(forwardMostMove)
+ timeRemaining = (BlackOnMove(forwardMostMove)
? blackTimeRemaining : whiteTimeRemaining);
#ifdef HAVE_GETTIMEOFDAY
tickLength = (((timeRemaining <= 1000) && (timeRemaining > 0))
- ? (((timeRemaining - 1) % 100) + 1)
+ ? (((timeRemaining - 1) % 100) + 1)
: (((timeRemaining - 1) % 1000) + 1));
- if (tickLength <= 0)
+ if (tickLength <= 0)
tickLength += 1000;
- gettimeofday(&tickStartTV, &tz);
+ gettimeofday(&tickStartTV, NULL);
#endif /* HAVE_GETTIMEOFDAY */
timerXID =
XtRemoveTimeOut(timerXID);
timerXID = 0;
- if (!localPlayer.appData.clockMode)
+ if (!localPlayer.appData.clockMode)
return;
#ifdef HAVE_GETTIMEOFDAY
DisplayLabels();
- if (!localPlayer.appData.clockMode)
+ if (!localPlayer.appData.clockMode)
return;
- timeRemaining = (BlackOnMove(forwardMostMove)
+ timeRemaining = (BlackOnMove(forwardMostMove)
? blackTimeRemaining : whiteTimeRemaining);
- if (timeRemaining == 0)
+ if (timeRemaining == 0)
return;
#ifdef HAVE_GETTIMEOFDAY
- tickLength = (((timeRemaining <= 1000) && (timeRemaining > 0))
+ tickLength = (((timeRemaining <= 1000) && (timeRemaining > 0))
? (((timeRemaining - 1) % 100) + 1)
: (((timeRemaining - 1) % 1000) + 1));
- if (tickLength <= 0)
+ if (tickLength <= 0)
tickLength += 1000;
- gettimeofday(&tickStartTV, &tz);
+ gettimeofday(&tickStartTV, NULL);
#endif /* HAVE_GETTIMEOFDAY */
timerXID =
fprintf(stderr, "\t-size or -boardSize (Large | Medium | Small)\n");
fprintf(stderr, "\t-coords or -showCoords (True | False)\n");
fprintf(stderr, "\t-mono or -monoMode (True | False)\n");
- fprintf(stderr, "\t-bpc or -blackPieceColor color\n");
- fprintf(stderr, "\t-wpc or -whitePieceColor color\n");
- fprintf(stderr, "\t-lsc or -lightSquareColor color\n");
- fprintf(stderr, "\t-dsc or -darkSquareColor color\n");
+ fprintf(stderr, "\t-pc or -pieceColor color\n");
+ fprintf(stderr, "\t-sc or -squareColor color\n");
fprintf(stderr, "\t-wps or -westernPieceSet (True | False)\n");
fprintf(stderr, "\t-debug or -debugMode (True | False)\n");
exit(2);
CatchPipeSignal(int dummy)
{
char message[MSG_SIZ];
-
+
sprintf(message,
"%s shogi program (%s) exited unexpectedly",
((lastMsgFP == toFirstProgFP) ? "first" : "second"),