v10i062: xboard, Part02/03

Chris Sears sears at decwrl.dec.com
Tue Dec 18 13:06:28 AEST 1990


Submitted-by: sears at decwrl.dec.com (Chris Sears)
Posting-number: Volume 10, Issue 62
Archive-name: xboard/part02

X   0xe7, 0xff, 0x07, 0xe0, 0xff, 0xe7, 0x07, 0x00, 0x00, 0xc0, 0x81, 0xff,
X   0x1f, 0xf8, 0xff, 0x81, 0x03, 0x00, 0x00, 0x80, 0x00, 0xfe, 0x7f, 0xfe,
X   0x7f, 0x00, 0x03, 0x00, 0x00, 0x80, 0x81, 0xff, 0xff, 0xff, 0xff, 0x81,
X   0x01, 0x00, 0x00, 0x00, 0xe7, 0xff, 0x01, 0x80, 0xff, 0xe7, 0x00, 0x00,
X   0x00, 0x00, 0xff, 0x03, 0xfc, 0x3f, 0xc0, 0xff, 0x00, 0x00, 0x00, 0x80,
X   0x01, 0xf8, 0xff, 0xff, 0x1f, 0x80, 0x01, 0x00, 0x00, 0x80, 0xfc, 0xff,
X   0xff, 0xff, 0xff, 0x3f, 0x01, 0x00, 0x00, 0x80, 0xff, 0xff, 0xff, 0xff,
X   0xff, 0xff, 0x01, 0x00, 0x00, 0xc0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
X   0x03, 0x00, 0x00, 0xc0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x03, 0x00,
X   0x00, 0xc0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x03, 0x00, 0x00, 0xe0,
X   0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x07, 0x00, 0x00, 0xe0, 0xff, 0xff,
X   0xff, 0xff, 0xff, 0xff, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
X   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
X   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
X   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
X   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
SHAR_EOF
$TOUCH -am 1031190590 solid_queen.bitmap &&
chmod 0644 solid_queen.bitmap ||
echo "restore of solid_queen.bitmap failed"
set `wc -c solid_queen.bitmap`;Wc_c=$1
if test "$Wc_c" != "5096"; then
	echo original size 5096, current size $Wc_c
fi
# ============= solid_rook.bitmap ==============
echo "x - extracting solid_rook.bitmap (Text)"
sed 's/^X//' << 'SHAR_EOF' > solid_rook.bitmap &&
X#define solid_rook_width 80
X#define solid_rook_height 80
Xstatic char solid_rook_bits[] = {
X   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
X   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
X   0xf8, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0xff,
X   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x01, 0xf8, 0xff, 0x00, 0x3c,
X   0x00, 0x00, 0x00, 0x80, 0xff, 0x01, 0xf8, 0xff, 0x00, 0xfc, 0x0f, 0x00,
X   0x00, 0xc0, 0xff, 0x01, 0xf8, 0xff, 0x00, 0xfc, 0x1f, 0x00, 0x00, 0xc0,
X   0xff, 0x01, 0xf8, 0xff, 0x00, 0xfc, 0x1f, 0x00, 0x00, 0xc0, 0xff, 0x01,
X   0xf8, 0xff, 0x00, 0xfc, 0x1f, 0x00, 0x00, 0xc0, 0xff, 0x01, 0xff, 0xff,
X   0x07, 0xfc, 0x1f, 0x00, 0x00, 0xc0, 0xff, 0xfd, 0x01, 0x00, 0xfc, 0xfd,
X   0x1f, 0x00, 0x00, 0xc0, 0xff, 0x07, 0xfc, 0xff, 0x01, 0xff, 0x1f, 0x00,
X   0x00, 0xc0, 0x1f, 0xf0, 0xff, 0xff, 0x7f, 0xc0, 0x1f, 0x00, 0x00, 0x40,
X   0xc0, 0xff, 0x07, 0x00, 0xff, 0x1f, 0x10, 0x00, 0x00, 0xc0, 0xff, 0x1f,
X   0xf0, 0x7f, 0xc0, 0xff, 0x1f, 0x00, 0x00, 0xc0, 0x7f, 0xc0, 0xfd, 0xff,
X   0x1d, 0xf0, 0x1f, 0x00, 0x00, 0x00, 0xc0, 0xff, 0xfd, 0xff, 0xfd, 0x1f,
X   0x00, 0x00, 0x00, 0x00, 0xc0, 0xff, 0xfd, 0xff, 0xfd, 0x1f, 0x00, 0x00,
X   0x00, 0x00, 0xc0, 0xff, 0xfd, 0xff, 0xfd, 0x1f, 0x00, 0x00, 0x00, 0x00,
X   0xc0, 0xff, 0xfd, 0xff, 0xfd, 0x1f, 0x00, 0x00, 0x00, 0x00, 0xc0, 0xff,
X   0xfd, 0xff, 0xfd, 0x1f, 0x00, 0x00, 0x00, 0x00, 0xc0, 0xff, 0xfd, 0xff,
X   0xfd, 0x1f, 0x00, 0x00, 0x00, 0x00, 0xc0, 0xff, 0xfd, 0xff, 0xfd, 0x1f,
X   0x00, 0x00, 0x00, 0x00, 0xc0, 0xff, 0xfd, 0xff, 0xfd, 0x1f, 0x00, 0x00,
X   0x00, 0x00, 0xc0, 0xff, 0xfd, 0xff, 0xfd, 0x1f, 0x00, 0x00, 0x00, 0x00,
X   0xc0, 0x7f, 0x00, 0x00, 0xf0, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00,
X   0xff, 0xfe, 0x07, 0x10, 0x00, 0x00, 0x00, 0x00, 0xc0, 0xff, 0xff, 0xfe,
X   0xff, 0x1f, 0x00, 0x00, 0x00, 0x00, 0xc0, 0xff, 0xff, 0xfe, 0xff, 0x1f,
X   0x00, 0x00, 0x00, 0x00, 0xc0, 0xff, 0xff, 0xfe, 0xff, 0x1f, 0x00, 0x00,
X   0x00, 0x00, 0xc0, 0xff, 0xff, 0xfe, 0xff, 0x1f, 0x00, 0x00, 0x00, 0x00,
X   0xc0, 0xff, 0xff, 0xfe, 0xff, 0x1f, 0x00, 0x00, 0x00, 0x00, 0xc0, 0xff,
X   0xff, 0xfe, 0xff, 0x1f, 0x00, 0x00, 0x00, 0x00, 0xc0, 0xff, 0xff, 0xfe,
X   0xff, 0x1f, 0x00, 0x00, 0x00, 0x00, 0xc0, 0xff, 0xff, 0xfe, 0xff, 0x1f,
X   0x00, 0x00, 0x00, 0x00, 0xc0, 0xff, 0xff, 0xfe, 0xff, 0x1f, 0x00, 0x00,
X   0x00, 0x00, 0xc0, 0xff, 0xff, 0xfe, 0xff, 0x1f, 0x00, 0x00, 0x00, 0x00,
X   0xc0, 0xff, 0xff, 0xfe, 0xff, 0x1f, 0x00, 0x00, 0x00, 0x00, 0xc0, 0xff,
X   0x0f, 0x80, 0xff, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0xe0, 0x3f,
X   0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0xc0, 0xff, 0xfd, 0xff, 0xfd, 0x1f,
X   0x00, 0x00, 0x00, 0x00, 0xc0, 0xff, 0xfd, 0xff, 0xfd, 0x1f, 0x00, 0x00,
X   0x00, 0x00, 0xc0, 0xff, 0xfd, 0xff, 0xfd, 0x1f, 0x00, 0x00, 0x00, 0x00,
X   0xc0, 0xff, 0xfd, 0xff, 0xfd, 0x1f, 0x00, 0x00, 0x00, 0x00, 0xc0, 0xff,
X   0xfd, 0xff, 0xfd, 0x1f, 0x00, 0x00, 0x00, 0x00, 0xc0, 0xff, 0xfd, 0xff,
X   0xfd, 0x1f, 0x00, 0x00, 0x00, 0x00, 0xc0, 0xff, 0xfd, 0xff, 0xfd, 0x1f,
X   0x00, 0x00, 0x00, 0x00, 0xc0, 0xff, 0xfd, 0xff, 0xfd, 0x1f, 0x00, 0x00,
X   0x00, 0x00, 0xc0, 0xff, 0xfd, 0xff, 0xfd, 0x1f, 0x00, 0x00, 0x00, 0x00,
X   0xc0, 0xff, 0xfd, 0xff, 0xfd, 0x1f, 0x00, 0x00, 0x00, 0x00, 0xc0, 0xff,
X   0xfd, 0xff, 0xfd, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00,
X   0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0xc0, 0xff, 0xff, 0xfd, 0xff, 0x1f,
X   0x00, 0x00, 0x00, 0x00, 0xc0, 0xff, 0xff, 0xfd, 0xff, 0x1f, 0x00, 0x00,
X   0x00, 0x00, 0xc0, 0xff, 0xff, 0xfd, 0xff, 0x1f, 0x00, 0x00, 0x00, 0x00,
X   0xc0, 0xff, 0xff, 0xfd, 0xff, 0x1f, 0x00, 0x00, 0x00, 0x00, 0xc0, 0xff,
X   0xff, 0xfd, 0xff, 0x1f, 0x00, 0x00, 0x00, 0x00, 0xc0, 0xff, 0xff, 0xfd,
X   0xff, 0x1f, 0x00, 0x00, 0x00, 0x00, 0xc0, 0xff, 0xff, 0xfd, 0xff, 0x1f,
X   0x00, 0x00, 0x00, 0x00, 0xc0, 0xff, 0xff, 0xfd, 0xff, 0x1f, 0x00, 0x00,
X   0x00, 0x00, 0xc0, 0xff, 0xff, 0xfd, 0xff, 0x1f, 0x00, 0x00, 0x00, 0x00,
X   0xc0, 0xff, 0xff, 0xfd, 0xff, 0x1f, 0x00, 0x00, 0x00, 0x00, 0xc0, 0xff,
X   0xff, 0xfd, 0xff, 0x1f, 0x00, 0x00, 0x00, 0x00, 0xc0, 0xff, 0xff, 0xfd,
X   0xff, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x10,
X   0x00, 0x00, 0x00, 0x00, 0xf8, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00,
X   0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x80, 0x01, 0x00, 0x00, 0x00,
X   0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x02, 0x00,
X   0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00,
X   0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
X   0x07, 0x00, 0x00, 0x80, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x00,
X   0x00, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x60,
X   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x20, 0x00, 0x00,
X   0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00,
X   0x00, 0x00, 0x20, 0x00, 0x00, 0xe0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
X   0x3f, 0x00, 0x00, 0xe0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x3f, 0x00,
X   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
X   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
SHAR_EOF
$TOUCH -am 1031190590 solid_rook.bitmap &&
chmod 0644 solid_rook.bitmap ||
echo "restore of solid_rook.bitmap failed"
set `wc -c solid_rook.bitmap`;Wc_c=$1
if test "$Wc_c" != "5093"; then
	echo original size 5093, current size $Wc_c
fi
# ============= xboard.1 ==============
echo "x - extracting xboard.1 (Text)"
sed 's/^X//' << 'SHAR_EOF' > xboard.1 &&
X.TH XBOARD 1 "August 23, 1990" "X Version 11"
X.SH NAME
Xxboard \- X11 user interface for GNU Chess
X.SH SYNOPSIS
X.B xboard
X[
X.IR "standard Xt options"
X]
X[
X.IR "\-whitePieceColor color"
X]
X[
X.IR "\-blackPieceColor color"
X]
X[
X.IR "\-lightSquareColor color"
X]
X[
X.IR "\-darkSquareColor color"
X]
X[
X.IR "\-timeDelay seconds"
X]
X[
X.IR "\-timeControl minutes"
X]
X[
X.IR "\-movesPerSession moves"
X]
X[
X.IR "\-saveGameFile file"
X]
X[
X.IR "\-readGameFile file"
X]
X[
X.IR "\-savePositionFile file"
X]
X[
X.IR "\-savePositionFile file"
X]
X[
X.IR "\-firstChessProgram program"
X]
X[
X.IR "\-secondChessProgram program"
X]
X[
X.IR "\-firstHost host"
X]
X[
X.IR "\-secondHost host"
X]
X[
X.IR "\-solidPawnBitmap file
X]
X[
X.IR "\-solidRookBitmap file
X]
X[
X.IR "\-solidBishopBitmap file
X]
X[
X.IR "\-solidKnightBitmap file
X]
X[
X.IR "\-solidQueenBitmap file
X]
X[
X.IR "\-solidKingBitmap file
X]
X[
X.IR "\-outlinePawnBitmap file
X]
X[
X.IR "\-outlineRookBitmap file
X]
X[
X.IR "\-outlineBishopBitmap file
X]
X[
X.IR "\-outlineKnightBitmap file
X]
X[
X.IR "\-outlineQueenBitmap file
X]
X[
X.IR "\-outlineKingBitmap file
X]
X[
X.IR "\-matchMode (False | Init | Position | Opening)"
X]
X[
X.IR "\-monoMode (False | True)"
X]
X[
X.IR "\-debugMode (False | True)"
X]
X.SH DESCRIPTION
X.IR xboard
Xprovides an X11/Xt/Athena Widgets user interface for GNU Chess.
XWith
X.IR xboard
Xyou can play GNU Chess,
Xsetup arbitrary positions,
Xforce variations or watch
X.IR xboard
Xmanage a game between two chess programs.
X.LP
XAfter starting
X.IR xboard
Xyou can make moves by pressing a mouse button
Xwhile the cursor is over a square with your piece on it
Xand dragging the mouse to another square.
XIf the move is illegal,
X.IR xboard
Xwill not allow it.
X.LP
XAlternate bitmaps for piece icons can be specified
Xwith file name resources described below.
X.SH OPTIONS
XThe following command line options also correspond to X resources
Xthat you can set in your
X.IR \&.Xdefaults
Xfile.
X.TP 8
X.B standard Xt options
X.IR xboard
Xaccepts standard Xt options like
X.IR "\-display"
Xand
X.IR "\-geometry" .
X.TP 8
X.B -whitePieceColor color
XColor specification for white pieces
Xsuitable for
X.IR XParseColor (3X11).
XDefault: #FFFFCC.
X.TP 8
X.B -blackPieceColor color
XSame for black pieces.
XDefault: #202020.
X.TP 8
X.B -lightSquareColor color
XSame for light squares.
XDefault: #C8C365.
X.TP 8
X.B -darkSquareColor color
XSame for dark squares.
XDefault: #77A26D.
X.TP 8
X.B -timeDelay seconds
XTime delay between moves during "Play From File".
XDefault: 1 second.
X.TP 8
X.B -timeControl minutes
XAmount of time for a set of moves determined by
X.IR movesPerSession .
XIf this number of moves is played within the time control period,
X.IR xboard
Xresets the time clocks.
XDefault: 5 minutes.
X.TP 8
X.B -movesPerSession moves
XNumber of moves in a playing session.
XDefault: 40 moves.
X.TP 8
X.B -saveGameFile file
XName of file to save a game record to.
XDefault: "xboard.game.save".
X.TP 8
X.B -readGameFile file
XName of file to read a game record from.
XDefault: "xboard.game.read".
X.TP 8
X.B -savePositionFile file
XName of file to save a game position to.
XDefault: "xboard.position.save".
X.TP 8
X.B -readPositionFile file
XName of file to read a game position from.
XDefault: "xboard.position.read".
X.TP 8
X.B -firstChessProgram program
XName of first chess program.
XDefault: "gnuchessr".
X.TP 8
X.B -secondChessProgram program
XName of second chess program.
XDefault: "gnuchessr".
X.TP 8
X.B -firstHost host
XName of host the first chess program plays on.
XDefault: "localhost".
X.TP 8
X.B -secondHost host
XName of host the second chess program plays on.
XDefault: "localhost".
X.TP 8
X.B -solid.*Bitmap file
XNames of the bitmap files for the bitmap piece icons.
XDefault: solid_pawn.bitmap, solid_rook.bitmap ...
X.TP 8
X.B -outline.*Bitmap file
XNames of the bitmap files for the outline piece icons.
XDefault: outline_pawn.bitmap, outline_rook.bitmap ...
X.TP 8
X.B -matchMode (False | Init | Position | Opening)
XAutomatically run a game between
X.IR firstChessProgram
Xand
X.IR secondChessProgram .
XIf
X.IR matchMode
Xis set to
X.IR Init ,
X.IR xboard
Xwill start the game with the initial chess position.
XIf
X.IR matchMode
Xis set to
X.IR Position
X.IR xboard
Xwill start the game with the position specified in
X.IR xboard.position.read .
XIf
X.IR matchMode
Xis set to
X.IR Opening
X.IR xboard
Xwill play out the opening moves specified in
X.IR xboard.game.read .
XDefault: "False".
X.TP 8
X.B -debugMode (False | True)
XTurns on tracing of messages sent to and from gnuchess.
X.TP 8
X.B -monoMode (False | True)
XDetermines whether
X.IR xboard
Xdisplays its pieces and squares with two colors or four.
X.SH COMMAND BUTTONS
X.TP 8
X.B Quit
XQuits
X.IR xboard .
X.TP 8
X.B Reset
XResets
X.IR xboard
Xto the beginning of a chess game.
X.TP 8
X.B Flip View
Xinverts the view of the chess board.
X.TP 8
X.B Hint
Xdisplays a move hint from GNU Chess.
X.TP 8
X.B Play From File
Xplays a game from a record file.
X.TP 8
X.B Setup From File
Xsets up a position from a position file.
X.TP 8
X.B Save Game
Xsaves a game to a record file.
X.TP 8
X.B Save Position
Xsaves a position to a position file.
X.TP 8
X.B Machine Black
Xforces GNU Chess to play black.
X.TP 8
X.B Machine White
Xforces GNU Chess to play white.
X.TP 8
X.B Switch Sides
Xforces GNU Chess to switch colors.
X.TP 8
X.B Two Machines
Xplays a game between two computer programs.
X.TP 8
X.B Forward
Xmoves forward through a series of remembered moves.
X.TP 8
X.B Backward
Xmoves backward through a series of remembered moves.
X.TP 8
X.B Force Moves
Xforces a series of moves.
X.TP 8
X.B Pause
Xpauses the game clocks or game replay.
X.SH SEE ALSO
X.IR xchess (1),
X.IR gnuchess (1)
X.SH LIMITATIONS
X.LP
XDoesn't handle black to play positions.
X.LP
XOnly recognizes algebraic notation.
X.LP
XIf you press the Pause button during GNU Chess's turn
Xxboard will stop the clocks, but GNU Chess will still make a move.
X.LP
XIf you play out an opening set of moves with "Play From File,"
Xyou must make a move and then select "Machine Black."
SHAR_EOF
$TOUCH -am 1031191890 xboard.1 &&
chmod 0644 xboard.1 ||
echo "restore of xboard.1 failed"
set `wc -c xboard.1`;Wc_c=$1
if test "$Wc_c" != "5825"; then
	echo original size 5825, current size $Wc_c
fi
# ============= xboard.c ==============
echo "x - extracting xboard.c (Text)"
sed 's/^X//' << 'SHAR_EOF' > xboard.c &&
X/*
X * XBoard -- an Xt user interface for GNU Chess
X *
X * Dan Sears
X * Chris Sears
X *
X * XBoard borrows its colors, icon and piece bitmaps from
X * XChess which was written and is copyrighted by Wayne Christopher.
X *
X * Revision 1.0 90/10/31
X *		Initial release.
X *
X * Copyright 1990 by Digital Equipment Corporation, Maynard, Massachusetts.
X *
X * All Rights Reserved
X *
X * Permission to use, copy, modify, and distribute this software and its
X * documentation for any purpose and without fee is hereby granted,
X * provided that the above copyright notice appear in all copies and that
X * both that copyright notice and this permission notice appear in
X * supporting documentation, and that the name of Digital not be
X * used in advertising or publicity pertaining to distribution of the
X * software without specific, written prior permission.
X *
X * DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
X * ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
X * DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
X * ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
X * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
X * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
X * SOFTWARE.
X */
X
X#include <stdio.h>
X#include <signal.h>
X#include <X11/Intrinsic.h>
X#include <X11/Shell.h>
X#include <X11/Xaw/Form.h>
X#include <X11/Xaw/List.h>
X#include <X11/Xaw/Label.h>
X#include <X11/StringDefs.h>
X#include <X11/cursorfont.h>
X#include "xboard.h"
X
X#include "solid_pawn.bitmap"
X#include "solid_rook.bitmap"
X#include "solid_knight.bitmap"
X#include "solid_bishop.bitmap"
X#include "solid_queen.bitmap"
X#include "solid_king.bitmap"
X
X#include "outline_pawn.bitmap"
X#include "outline_rook.bitmap"
X#include "outline_knight.bitmap"
X#include "outline_bishop.bitmap"
X#include "outline_queen.bitmap"
X#include "outline_king.bitmap"
X
X#include "knight_small.bitmap"
X
X#define WHITE_PIXEL (XWhitePixel(xDisplay, xScreen))
X#define BLACK_PIXEL (XBlackPixel(xDisplay, xScreen))
X
X#ifdef __STDC__
Xvoid main(int argc, char **argv);
Xvoid GetGCs(void);
Xvoid CreatePieces(void);
Xvoid CreateGrid(void);
Xint EventToOrdinal(int);
Xvoid DrawSquare(int row, int column, u_char piece);
Xvoid MakeMove(int *move_type, int from_x, int from_y, int to_x, int to_y);
Xvoid InitPosition(void);
Xvoid CopyBoard(Board to, Board from);
Xvoid DrawPosition(Widget w, XExposeEvent *event);
Xvoid HandleUserMove(Widget w, XEvent *event);
Xvoid HandleMachineMove(char *message);
XXtCallbackProc SelectCommand(Widget w, XtPointer client_data,
X	XtPointer call_data);
Xvoid EndOfGameProc(char *message);
Xvoid QuitProc(void);
Xvoid BackwardProc(void);
Xvoid ForwardProc(void);
Xvoid FlipProc(void);
Xvoid ResetProc(void);
Xvoid SaveGameProc(void);
Xvoid SavePositionProc(void);
Xvoid HintProc(void);
Xvoid SwitchProc(void);
Xvoid SetupPositionFromFileProc(void);
Xvoid SendPosition(FILE *fp);
Xvoid PlayFromGameFileProc(void);
XXtTimerCallbackProc ReadGameFile(FILE *fp);
Xvoid MachinePlaysBlackProc(void);
Xvoid MachinePlaysWhiteProc(void);
Xvoid TwoMachinesPlayProc(void);
Xvoid ForceProc(void);
Xvoid PauseProc(void);
Xvoid InitChessProgram(void);
Xvoid SendToProgram(char *message, FILE *fp);
Xvoid ReceiveFromProgram(FILE *fp);
Xvoid DisplayMessage(char *message);
XXtTimerCallbackProc DisplayTimers(int clock_mode);
Xchar *TimeString(time_t tm);
Xvoid Syntax(int argc, char **argv);
X#else
Xvoid main();
Xvoid GetGCs();
Xvoid CreatePieces();
Xvoid CreateGrid();
Xint EventToOrdinal();
Xvoid DrawSquare();
Xvoid MakeMove();
Xvoid InitPosition();
Xvoid CopyBoard();
Xvoid DrawPosition();
Xvoid HandleUserMove();
Xvoid HandleMachineMove();
XXtCallbackProc SelectCommand();
Xvoid EndOfGameProc();
Xvoid QuitProc();
Xvoid BackwardProc();
Xvoid ForwardProc();
Xvoid FlipProc();
Xvoid ResetProc();
Xvoid SaveGameProc();
Xvoid SavePositionProc();
Xvoid HintProc();
Xvoid SwitchProc();
Xvoid SetupPositionFromFileProc();
Xvoid SendPosition();
Xvoid PlayFromGameFileProc();
XXtTimerCallbackProc ReadGameFile();
Xvoid MachinePlaysBlackProc();
Xvoid MachinePlaysWhiteProc();
Xvoid TwoMachinesPlayProc();
Xvoid ForceProc();
Xvoid PauseProc();
Xvoid InitChessProgram();
Xvoid SendToProgram();
Xvoid ReceiveFromProgram();
Xvoid DisplayMessage();
XXtTimerCallbackProc DisplayTimers();
Xchar *TimeString();
Xvoid Syntax();
X#endif
X
Xint xScreen;
XDisplay *xDisplay;
XWindow xBoardWindow;
XGC lightSquareGC, darkSquareGC, lineGC,
X	wdPieceGC, wlPieceGC, bdPieceGC, blPieceGC,
X	wbPieceGC, wwPieceGC, bbPieceGC, bwPieceGC;
XPixmap solidPawnBitmap, solidRookBitmap, solidKnightBitmap, solidBishopBitmap,
X	solidQueenBitmap, solidKingBitmap, outlinePawnBitmap, outlineRookBitmap,
X	outlineKnightBitmap, outlineBishopBitmap, outlineQueenBitmap,
X	outlineKingBitmap, iconPixmap;
XWidget shellWidget, formWidget, boardWidget, commandsWidget, messageWidget,
X	whiteTimerWidget, blackTimerWidget, widgetList[5];
XXSegment gridSegments[(BOARD_SIZE + 1) * 2];
XXtIntervalId firstProgXID = NULL, secondProgXID = NULL, readGameXID = NULL;
XXFontStruct *labelFont;
X
XFILE *fromFirstProgFP, *toFirstProgFP, *fromSecondProgFP, *toSecondProgFP;
Xint currentMove = 0, firstMove = True, forwardMostMove = 0, flipView = False,
X	forwardForce = False, gameMode = BeginningOfGame, onMove = WhiteOnMove,
X	wCount = 0, bCount = 0, firstProgPID = NULL, secondProgPID = NULL;
Xchar moveList[MAX_MOVES][8], whitePieces[16][4], blackPieces[16][4],
X	currentMoveString[8];
X
XBoard boards[MAX_MOVES], initialPosition = {
X	{ WhiteRook, WhiteKnight, WhiteBishop, WhiteQueen,
X		WhiteKing, WhiteBishop, WhiteKnight, WhiteRook },
X	{ WhitePawn, WhitePawn, WhitePawn, WhitePawn,
X		WhitePawn, WhitePawn, WhitePawn, WhitePawn },
X	{ EmptySquare, EmptySquare, EmptySquare, EmptySquare,
X		EmptySquare, EmptySquare, EmptySquare, EmptySquare },
X	{ EmptySquare, EmptySquare, EmptySquare, EmptySquare,
X		EmptySquare, EmptySquare, EmptySquare, EmptySquare },
X	{ EmptySquare, EmptySquare, EmptySquare, EmptySquare,
X		EmptySquare, EmptySquare, EmptySquare, EmptySquare },
X	{ EmptySquare, EmptySquare, EmptySquare, EmptySquare,
X		EmptySquare, EmptySquare, EmptySquare, EmptySquare },
X	{ BlackPawn, BlackPawn, BlackPawn, BlackPawn,
X		BlackPawn, BlackPawn, BlackPawn, BlackPawn },
X	{ BlackRook, BlackKnight, BlackBishop, BlackQueen,
X		BlackKing, BlackBishop, BlackKnight, BlackRook }
X};
X
XString buttonStrings[] = {
X	"Quit", "Play From File", "Machine Black", "Forward",
X	"Reset", "Setup From File", "Machine White", "Backward",
X	"Flip View", "Save Game", "Switch Sides", "Force Moves",
X	"Hint", "Save Position", "Two Machines", "Pause"
X};
X
XArg shellArgs[] = {
X	{ XtNwidth, 0 },
X	{ XtNheight, 0 },
X	{ XtNminWidth, 0 },
X	{ XtNminHeight, 0 },
X	{ XtNmaxWidth, 0 },
X	{ XtNmaxHeight, 0 }
X};
X
XArg boardArgs[] = {
X	{ XtNborderWidth, 0 },
X	{ XtNwidth, LINE_GAP + BOARD_SIZE * (SQUARE_SIZE + LINE_GAP) },
X	{ XtNheight, LINE_GAP + BOARD_SIZE * (SQUARE_SIZE + LINE_GAP) }
X};
X
XArg commandsArgs[] = {
X	{ XtNborderWidth, 0 },
X	{ XtNdefaultColumns, 4 },
X	{ XtNforceColumns, True },
X	{ XtNlist, (int) buttonStrings },
X	{ XtNnumberStrings, XtNumber(buttonStrings) }
X};
X
XArg messageArgs[] = {
X	{ XtNborderWidth, 0 },
X	{ XtNwidth, 600 },
X	{ XtNjustify, XtJustifyLeft }
X};
X
XArg timerArgs[] = {
X	{ XtNborderWidth, 0 },
X	{ XtNjustify, XtJustifyLeft }
X};
X
Xtypedef struct {
X	Pixel whitePieceColor;
X	Pixel blackPieceColor;
X	Pixel lightSquareColor;
X	Pixel darkSquareColor;
X	float timeDelay;
X	int timeControl;
X	int movesPerSession;
X	String saveGameFile;
X	String readGameFile;
X	String initString;
X	String savePositionFile;
X	String readPositionFile;
X	String firstChessProgram;
X	String secondChessProgram;
X	String firstHost;
X	String secondHost;
X	String solidPawnBitmap;
X	String solidRookBitmap;
X	String solidBishopBitmap;
X	String solidKnightBitmap;
X	String solidQueenBitmap;
X	String solidKingBitmap;
X	String outlinePawnBitmap;
X	String outlineRookBitmap;
X	String outlineBishopBitmap;
X	String outlineKnightBitmap;
X	String outlineQueenBitmap;
X	String outlineKingBitmap;
X	int matchMode;
X	Boolean monoMode;
X	int debugMode;
X} AppData, *AppDataPtr;
X
XAppData appData;
X
XXtResource clientResources[] = {
X	{
X		"whitePieceColor", "whitePieceColor", XtRPixel, sizeof(Pixel),
X		XtOffset(AppDataPtr, whitePieceColor), XtRString, WHITE_PIECE_COLOR
X	}, {
X		"blackPieceColor", "blackPieceColor", XtRPixel, sizeof(Pixel),
X		XtOffset(AppDataPtr, blackPieceColor), XtRString, BLACK_PIECE_COLOR
X	}, {
X		"lightSquareColor", "lightSquareColor", XtRPixel, sizeof(Pixel),
X		XtOffset(AppDataPtr, lightSquareColor), XtRString, LIGHT_SQUARE_COLOR
X	}, {
X		"darkSquareColor", "darkSquareColor", XtRPixel, sizeof(Pixel),
X		XtOffset(AppDataPtr, darkSquareColor), XtRString, DARK_SQUARE_COLOR
X	}, {
X		"timeDelay", "timeDelay", XtRFloat, sizeof(float),
X		XtOffset(AppDataPtr, timeDelay), XtRImmediate, (XtPointer) TIME_DELAY
X	}, {
X		"timeControl", "timeControl", XtRInt, sizeof(int),
X		XtOffset(AppDataPtr, timeControl), XtRImmediate,
X		(XtPointer) TIME_CONTROL
X	}, {
X		"movesPerSession", "movesPerSession", XtRInt, sizeof(int),
X		XtOffset(AppDataPtr, movesPerSession), XtRImmediate,
X		(XtPointer) MOVES_PER_SESSION
X	}, {
X		"saveGameFile", "saveGameFile", XtRString, sizeof(String),
X		XtOffset(AppDataPtr, saveGameFile), XtRString, SAVE_GAME_FILE
X	}, {
X		"readGameFile", "readGameFile", XtRString, sizeof(String),
X		XtOffset(AppDataPtr, readGameFile), XtRString, READ_GAME_FILE
X	}, {
X		"initString", "initString", XtRString, sizeof(String),
X		XtOffset(AppDataPtr, initString), XtRString, INIT_STRING
X	}, {
X		"savePositionFile", "savePositionFile", XtRString, sizeof(String),
X		XtOffset(AppDataPtr, savePositionFile), XtRString, SAVE_POSITION_FILE
X	}, {
X		"readPositionFile", "readPositionFile", XtRString, sizeof(String),
X		XtOffset(AppDataPtr, readPositionFile), XtRString, READ_POSITION_FILE
X	}, {
X		"firstChessProgram", "firstChessProgram", XtRString, sizeof(String),
X		XtOffset(AppDataPtr, firstChessProgram), XtRString, FIRST_CHESS_PROGRAM
X	}, {
X		"secondChessProgram", "secondChessProgram", XtRString, sizeof(String),
X		XtOffset(AppDataPtr, secondChessProgram), XtRString,
X		SECOND_CHESS_PROGRAM
X	}, {
X		"firstHost", "firstHost", XtRString, sizeof(String),
X		XtOffset(AppDataPtr, firstHost), XtRString, FIRST_HOST
X	}, {
X		"secondHost", "secondHost", XtRString, sizeof(String),
X		XtOffset(AppDataPtr, secondHost), XtRString, SECOND_HOST
X	}, {
X		"solidPawnBitmap", "solidPawnBitmap", XtRString, sizeof(String),
X		XtOffset(AppDataPtr, solidPawnBitmap), XtRString, SOLID_PAWN_BITMAP
X	}, {
X		"solidRookBitmap", "solidRookBitmap", XtRString, sizeof(String),
X		XtOffset(AppDataPtr, solidRookBitmap), XtRString, SOLID_ROOK_BITMAP
X	}, {
X		"solidKnightBitmap", "solidKnightBitmap", XtRString, sizeof(String),
X		XtOffset(AppDataPtr, solidKnightBitmap), XtRString, SOLID_KNIGHT_BITMAP
X	}, {
X		"solidBishopBitmap", "solidBishopBitmap", XtRString, sizeof(String),
X		XtOffset(AppDataPtr, solidBishopBitmap), XtRString, SOLID_BISHOP_BITMAP
X	}, {
X		"solidQueenBitmap", "solidQueenBitmap", XtRString, sizeof(String),
X		XtOffset(AppDataPtr, solidQueenBitmap), XtRString, SOLID_QUEEN_BITMAP
X	}, {
X		"solidKingBitmap", "solidKingBitmap", XtRString, sizeof(String),
X		XtOffset(AppDataPtr, solidKingBitmap), XtRString, SOLID_KING_BITMAP
X	}, {
X		"outlinePawnBitmap", "outlinePawnBitmap", XtRString, sizeof(String),
X		XtOffset(AppDataPtr, outlinePawnBitmap), XtRString, OUTLINE_PAWN_BITMAP
X	}, {
X		"outlineRookBitmap", "outlineRookBitmap", XtRString, sizeof(String),
X		XtOffset(AppDataPtr, outlineRookBitmap), XtRString, OUTLINE_ROOK_BITMAP
X	}, {
X		"outlineKnightBitmap", "outlineKnightBitmap", XtRString,
X		sizeof(String), XtOffset(AppDataPtr, outlineKnightBitmap), XtRString,
X		OUTLINE_KNIGHT_BITMAP
X	}, {
X		"outlineBishopBitmap", "outlineBishopBitmap", XtRString,
X		sizeof(String), XtOffset(AppDataPtr, outlineBishopBitmap), XtRString,
X		OUTLINE_BISHOP_BITMAP
X	}, {
X		"outlineQueenBitmap", "outlineQueenBitmap", XtRString, sizeof(String),
X		XtOffset(AppDataPtr, outlineQueenBitmap), XtRString,
X		OUTLINE_QUEEN_BITMAP
X	}, {
X		"outlineKingBitmap", "outlineKingBitmap", XtRString, sizeof(String),
X		XtOffset(AppDataPtr, outlineKingBitmap), XtRString, OUTLINE_KING_BITMAP
X	}, {
X		"matchMode", "matchMode", XtRInt, sizeof(int),
X		XtOffset(AppDataPtr, matchMode), XtRImmediate, (XtPointer) MATCH_MODE
X	}, {
X		"monoMode", "monoMode", XtRBoolean, sizeof(Boolean),
X		XtOffset(AppDataPtr, monoMode), XtRImmediate, (XtPointer) False
X	}, {
X		"debugMode", "debugMode", XtRBoolean, sizeof(Boolean),
X		XtOffset(AppDataPtr, debugMode), XtRImmediate, (XtPointer) False
X	}
X};
X
XPixmap *pieceToSolid[] = {
X	&solidPawnBitmap, &solidRookBitmap, &solidKnightBitmap,
X	&solidBishopBitmap, &solidQueenBitmap, &solidKingBitmap,
X	&solidPawnBitmap, &solidRookBitmap, &solidKnightBitmap,
X	&solidBishopBitmap, &solidQueenBitmap, &solidKingBitmap
X};
X
XPixmap *pieceToOutline[] = {
X	&outlinePawnBitmap, &outlineRookBitmap, &outlineKnightBitmap,
X	&outlineBishopBitmap, &outlineQueenBitmap, &outlineKingBitmap,
X	&outlinePawnBitmap, &outlineRookBitmap, &outlineKnightBitmap,
X	&outlineBishopBitmap, &outlineQueenBitmap, &outlineKingBitmap
X};
X
Xint pieceToColor[] = {
X	True, True, True, True, True, True,
X	False, False, False, False, False, False
X};
X
Xchar *pieceToString[] = {
X	"P", "R", "N", "B", "Q", "K",
X	"p", "r", "n", "b", "q", "k", "."
X};
X
Xstatic XrmOptionDescRec shellOptions[] = {
X	{ "-whitePieceColor", "*whitePieceColor", XrmoptionSepArg, NULL },
X	{ "-blackPieceColor", "*blackPieceColor", XrmoptionSepArg, NULL },
X	{ "-lightSquareColor", "*lightSquareColor", XrmoptionSepArg, NULL },
X	{ "-darkSquareColor", "*darkSquareColor", XrmoptionSepArg, NULL },
X	{ "-timeDelay", "*timeDelay", XrmoptionSepArg, NULL },
X	{ "-timeControl", "*timeControl", XrmoptionSepArg, NULL },
X	{ "-movesPerSession", "*movesPerSession", XrmoptionSepArg, NULL },
X	{ "-saveGameFile", "*saveGameFile", XrmoptionSepArg, NULL },
X	{ "-readGameFile", "*readGameFile", XrmoptionSepArg, NULL },
X	{ "-initString", "*initString", XrmoptionSepArg, NULL },
X	{ "-savePositionFile", "*savePositionFile", XrmoptionSepArg, NULL },
X	{ "-readPositionFile", "*readPositionFile", XrmoptionSepArg, NULL },
X	{ "-firstChessProgram", "*firstChessProgram", XrmoptionSepArg, NULL },
X	{ "-secondChessProgram", "*secondChessProgram", XrmoptionSepArg, NULL },
X	{ "-firstHost", "*firstHost", XrmoptionSepArg, NULL },
X	{ "-secondHost", "*secondHost", XrmoptionSepArg, NULL },
X	{ "-matchMode", "*matchMode", XrmoptionSepArg, NULL },
X	{ "-monoMode", "*monoMode", XrmoptionSepArg, NULL },
X	{ "-debugMode", "*debugMode", XrmoptionSepArg, NULL }
X};
X
Xstatic XtActionsRec boardActions[] = {
X	{ "HandleUserMove", HandleUserMove },
X	{ "DrawPosition", DrawPosition }
X};
X
Xvoid
Xmain(argc, argv)
X	int argc;
X	char **argv;
X{
X	XSetWindowAttributes window_attributes;
X	char buf[MSG_SIZ];
X	Arg args[3];
X	int length;
X
X	setbuf(stdout, NULL);
X	setbuf(stderr, NULL);
X
X	shellWidget = XtInitialize(argv[0], "XBoard", shellOptions,
X		XtNumber(shellOptions), &argc, argv);
X
X	if (argc > 1)
X		Syntax(argc, argv);
X
X	XtGetApplicationResources(shellWidget, &appData, clientResources,
X		XtNumber(clientResources), NULL, 0);
X
X	xDisplay = XtDisplay(shellWidget);
X	xScreen = DefaultScreen(xDisplay);
X
X	/*
X	 * widget hierarchy
X	 */
X	formWidget = XtCreateManagedWidget("form",
X		formWidgetClass, shellWidget, NULL, 0);
X
X		widgetList[0] = whiteTimerWidget = XtCreateWidget("white time:",
X			labelWidgetClass, formWidget, timerArgs, XtNumber(timerArgs));
X
X		widgetList[1] = blackTimerWidget = XtCreateWidget("black time:",
X			labelWidgetClass, formWidget, timerArgs, XtNumber(timerArgs));
X
X		widgetList[2] = messageWidget = XtCreateWidget("message",
X			labelWidgetClass, formWidget, messageArgs, XtNumber(messageArgs));
X
X		widgetList[3] = commandsWidget = XtCreateWidget("commands",
X			listWidgetClass, formWidget, commandsArgs, XtNumber(commandsArgs));
X
X		widgetList[4] = boardWidget = XtCreateWidget("board",
X			widgetClass, formWidget, boardArgs, XtNumber(boardArgs));
X
X	XtManageChildren(widgetList, XtNumber(widgetList));
X
X	/*
X	 * Calculate the width of the timer labels.
X	 */
X	XtSetArg(args[0], XtNfont, &labelFont);
X	XtGetValues(whiteTimerWidget, args, 1);
X	sprintf(buf, "white: %s", TimeString(appData.timeControl * 60));
X	length = XTextWidth(labelFont, buf, strlen(buf));
X	XtSetArg(args[0], XtNwidth, length);
X	XtSetValues(whiteTimerWidget, args, 1);
X	XtSetValues(blackTimerWidget, args, 1);
X
X	/*
X	 * formWidget uses these constraints but they are stored in the children.
X	 */
X	XtSetArg(args[0], XtNfromHoriz, whiteTimerWidget);
X	XtSetValues(blackTimerWidget, args, 1);
X	XtSetArg(args[0], XtNfromVert, whiteTimerWidget);
X	XtSetArg(args[1], XtNbackground, BLACK_PIXEL);
X	XtSetArg(args[2], XtNforeground, WHITE_PIXEL);
X	XtSetValues(messageWidget, args, 3);
X	XtSetArg(args[0], XtNfromVert, messageWidget);
X	XtSetValues(commandsWidget, args, 1);
X	XtSetArg(args[0], XtNfromVert, commandsWidget);
X	XtSetValues(boardWidget, args, 1);
X
X	XtRealizeWidget(shellWidget);
X
X	xBoardWindow = XtWindow(boardWidget);
X
X	/*
X	 * Create an icon.
X	 */
X	iconPixmap = XCreateBitmapFromData(xDisplay, XtWindow(shellWidget),
X		knight_small_bits, knight_small_width, knight_small_height);
X	XtSetArg(args[0], XtNiconPixmap, iconPixmap);
X	XtSetValues(shellWidget, args, 1);
X
X	/*
X	 * Create a cursor for the board widget.
X	 */
X	window_attributes.cursor = XCreateFontCursor(xDisplay, XC_hand2);
X	XChangeWindowAttributes(xDisplay, xBoardWindow,
X		CWCursor, &window_attributes);
X
X	/*
X	 * inhibit resizing
X	 */
X	XtGetValues(shellWidget, shellArgs, 2);
X	shellArgs[4].value = shellArgs[2].value = shellArgs[0].value;
X	shellArgs[5].value = shellArgs[3].value = shellArgs[1].value;
X	XtSetValues(shellWidget, &shellArgs[2], 4);
X
X	CreatePieces();
X	GetGCs();
X	CreateGrid();
X	ResetProc();
X
X	XtAddCallback(commandsWidget, XtNcallback, SelectCommand, NULL);
X	XtAddActions(boardActions, XtNumber(boardActions));
X	XtOverrideTranslations(boardWidget,
X		XtParseTranslationTable("<Expose>: DrawPosition() \n\
X			<BtnDown>: HandleUserMove() \n\
X			<BtnUp>: HandleUserMove()"));
X
X	switch (appData.matchMode) {
X	case MatchInit:
X		TwoMachinesPlayProc();
X		break;
X	case MatchPosition:
X		SetupPositionFromFileProc();
X		TwoMachinesPlayProc();
X		break;
X	case MatchOpening:
X		PlayFromGameFileProc();
X		TwoMachinesPlayProc();
X		break;
X	case MatchFalse:
X		break;
X	}
X
X	XtMainLoop();
X}
X
Xvoid
XGetGCs()
X{
X	XGCValues gc_values;
X	XtGCMask value_mask = GCLineWidth | GCLineStyle | GCForeground
X		| GCBackground | GCFunction | GCPlaneMask;
X
X	gc_values.plane_mask = AllPlanes;
X	gc_values.line_width = LINE_GAP;
X	gc_values.line_style = LineSolid;
X	gc_values.function = GXcopy;
X
X	gc_values.foreground =
X		appData.monoMode ? WHITE_PIXEL : appData.lightSquareColor;
X	gc_values.background =
X		appData.monoMode ? BLACK_PIXEL : appData.darkSquareColor;
X	lightSquareGC = XtGetGC(shellWidget, value_mask, &gc_values);
X
X	gc_values.foreground =
X		appData.monoMode ? BLACK_PIXEL : appData.darkSquareColor;
X	gc_values.background =
X		appData.monoMode ? WHITE_PIXEL : appData.lightSquareColor;
X	darkSquareGC = XtGetGC(shellWidget, value_mask, &gc_values);
X
X	gc_values.foreground = BLACK_PIXEL;
X	gc_values.background = BLACK_PIXEL;
X	lineGC = XtGetGC(shellWidget, value_mask, &gc_values);
X
X	if (appData.monoMode) {
X		gc_values.foreground = WHITE_PIXEL;
X		gc_values.background = BLACK_PIXEL;
X		wbPieceGC = XtGetGC(shellWidget, value_mask, &gc_values);
X
X		gc_values.foreground = BLACK_PIXEL;
X		gc_values.background = WHITE_PIXEL;
X		wwPieceGC = XtGetGC(shellWidget, value_mask, &gc_values);
X
X		gc_values.foreground = WHITE_PIXEL;
X		gc_values.background = BLACK_PIXEL;
X		bbPieceGC = XtGetGC(shellWidget, value_mask, &gc_values);
X
X		gc_values.foreground = BLACK_PIXEL;
X		gc_values.background = WHITE_PIXEL;
X		bwPieceGC = XtGetGC(shellWidget, value_mask, &gc_values);
X	} else {
X		gc_values.foreground = appData.whitePieceColor;
X		gc_values.background = appData.darkSquareColor;
X		wdPieceGC = XtGetGC(shellWidget, value_mask, &gc_values);
X
X		gc_values.foreground = appData.whitePieceColor;
X		gc_values.background = appData.lightSquareColor;
X		wlPieceGC = XtGetGC(shellWidget, value_mask, &gc_values);
X
X		gc_values.foreground = appData.blackPieceColor;
X		gc_values.background = appData.darkSquareColor;
X		bdPieceGC = XtGetGC(shellWidget, value_mask, &gc_values);
X
X		gc_values.foreground = appData.blackPieceColor;
X		gc_values.background = appData.lightSquareColor;
X		blPieceGC = XtGetGC(shellWidget, value_mask, &gc_values);
X	}
X}
X
Xvoid
XCreatePieces()
X{
X	int w, h, x_hot, y_hot;
X
XXSynchronize(xDisplay, True);	/* Work-around for xlib/xt bug */
X	if (XReadBitmapFile(xDisplay, xBoardWindow, appData.solidPawnBitmap,
X			&w, &h, &solidPawnBitmap, &x_hot, &y_hot)
X			!= BitmapSuccess || w != SQUARE_SIZE || h != SQUARE_SIZE)
X		solidPawnBitmap = XCreateBitmapFromData(xDisplay, xBoardWindow,
X			solid_pawn_bits, SQUARE_SIZE, SQUARE_SIZE);
X
X	if (XReadBitmapFile(xDisplay, xBoardWindow, appData.solidRookBitmap,
X			&w, &h, &solidRookBitmap, &x_hot, &y_hot)
X			!= BitmapSuccess || w != SQUARE_SIZE || h != SQUARE_SIZE)
X		solidRookBitmap = XCreateBitmapFromData(xDisplay, xBoardWindow,
X			solid_rook_bits, SQUARE_SIZE, SQUARE_SIZE);
X
X	if (XReadBitmapFile(xDisplay, xBoardWindow, appData.solidKnightBitmap,
X			&w, &h, &solidKnightBitmap, &x_hot, &y_hot)
X			!= BitmapSuccess || w != SQUARE_SIZE || h != SQUARE_SIZE)
X		solidKnightBitmap = XCreateBitmapFromData(xDisplay, xBoardWindow,
X			solid_knight_bits, SQUARE_SIZE, SQUARE_SIZE);
X
X	if (XReadBitmapFile(xDisplay, xBoardWindow, appData.solidBishopBitmap,
X			&w, &h, &solidBishopBitmap, &x_hot, &y_hot)
X			!= BitmapSuccess || w != SQUARE_SIZE || h != SQUARE_SIZE)
X		solidBishopBitmap = XCreateBitmapFromData(xDisplay, xBoardWindow,
X			solid_bishop_bits, SQUARE_SIZE, SQUARE_SIZE);
X
X	if (XReadBitmapFile(xDisplay, xBoardWindow, appData.solidQueenBitmap,
X			&w, &h, &solidQueenBitmap, &x_hot, &y_hot)
X			!= BitmapSuccess || w != SQUARE_SIZE || h != SQUARE_SIZE)
X		solidQueenBitmap = XCreateBitmapFromData(xDisplay, xBoardWindow,
X			solid_queen_bits, SQUARE_SIZE, SQUARE_SIZE);
X
X	if (XReadBitmapFile(xDisplay, xBoardWindow, appData.solidKingBitmap,
X			&w, &h, &solidKingBitmap, &x_hot, &y_hot)
X			!= BitmapSuccess || w != SQUARE_SIZE || h != SQUARE_SIZE)
X		solidKingBitmap = XCreateBitmapFromData(xDisplay, xBoardWindow,
X			solid_king_bits, SQUARE_SIZE, SQUARE_SIZE);
X
X	if ((appData.monoMode) || (DisplayPlanes(xDisplay, xScreen) == 1)) {
X		if (XReadBitmapFile(xDisplay, xBoardWindow, appData.outlinePawnBitmap,
X				&w, &h, &outlinePawnBitmap, &x_hot, &y_hot)
X				!= BitmapSuccess || w != SQUARE_SIZE || h != SQUARE_SIZE)
X			outlinePawnBitmap = XCreateBitmapFromData(xDisplay, xBoardWindow,
X				outline_pawn_bits, SQUARE_SIZE, SQUARE_SIZE);
X
X		if (XReadBitmapFile(xDisplay, xBoardWindow, appData.outlineRookBitmap,
X				&w, &h, &outlineRookBitmap, &x_hot, &y_hot)
X				!= BitmapSuccess || w != SQUARE_SIZE || h != SQUARE_SIZE)
X			outlineRookBitmap = XCreateBitmapFromData(xDisplay, xBoardWindow,
X				outline_rook_bits, SQUARE_SIZE, SQUARE_SIZE);
X
X		if (XReadBitmapFile(xDisplay, xBoardWindow, appData.outlineKnightBitmap,
X				&w, &h, &outlineKnightBitmap, &x_hot, &y_hot)
X				!= BitmapSuccess || w != SQUARE_SIZE || h != SQUARE_SIZE)
X			outlineKnightBitmap = XCreateBitmapFromData(xDisplay, xBoardWindow,
X				outline_knight_bits, SQUARE_SIZE, SQUARE_SIZE);
X
X		if (XReadBitmapFile(xDisplay, xBoardWindow, appData.outlineBishopBitmap,
X				&w, &h, &outlineBishopBitmap, &x_hot, &y_hot)
X				!= BitmapSuccess || w != SQUARE_SIZE || h != SQUARE_SIZE)
X			outlineBishopBitmap = XCreateBitmapFromData(xDisplay, xBoardWindow,
X				outline_bishop_bits, SQUARE_SIZE, SQUARE_SIZE);
X
X		if (XReadBitmapFile(xDisplay, xBoardWindow, appData.outlineQueenBitmap,
X				&w, &h, &outlineQueenBitmap, &x_hot, &y_hot)
X				!= BitmapSuccess || w != SQUARE_SIZE || h != SQUARE_SIZE)
X			outlineQueenBitmap = XCreateBitmapFromData(xDisplay, xBoardWindow,
X				outline_queen_bits, SQUARE_SIZE, SQUARE_SIZE);
X
X		if (XReadBitmapFile(xDisplay, xBoardWindow, appData.outlineKingBitmap,
X				&w, &h, &outlineKingBitmap, &x_hot, &y_hot)
X				!= BitmapSuccess || w != SQUARE_SIZE || h != SQUARE_SIZE)
X			outlineKingBitmap = XCreateBitmapFromData(xDisplay, xBoardWindow,
X				outline_king_bits, SQUARE_SIZE, SQUARE_SIZE);
X	}
XXSynchronize(xDisplay, False);	/* Work-around for xlib/xt bug */
X}
X
Xvoid
XCreateGrid()
X{
X	int i;
X
X	for (i = 0; i < BOARD_SIZE + 1; i++) {
X		gridSegments[i].x1 = 0;
X		gridSegments[i].y1 = LINE_GAP / 2 + (i * (SQUARE_SIZE + LINE_GAP));
X		gridSegments[i].x2 = LINE_GAP + BOARD_SIZE * (SQUARE_SIZE + LINE_GAP);
X		gridSegments[i].y2 = LINE_GAP / 2 + (i * (SQUARE_SIZE + LINE_GAP));
X		gridSegments[i + BOARD_SIZE + 1].x1 = LINE_GAP / 2
X			+ (i * (SQUARE_SIZE + LINE_GAP));
X		gridSegments[i + BOARD_SIZE + 1].y1 = 0;
X		gridSegments[i + BOARD_SIZE + 1].x2 = LINE_GAP / 2
X			+ (i * (SQUARE_SIZE + LINE_GAP));
X		gridSegments[i + BOARD_SIZE + 1].y2 =
X			BOARD_SIZE * (SQUARE_SIZE + LINE_GAP);
X	}
X}
X
X/*
X * If the user mouse selects on a border boundary then return failure.
X * Otherwise map the event coordinate to the square.
X */
Xint
XEventToOrdinal(x)
X	int x;
X{
X	if (x < LINE_GAP)
X		return -1;
X	x -= LINE_GAP;
X	if ((x % (SQUARE_SIZE + LINE_GAP)) >= SQUARE_SIZE)
X		return -1;
X	return x / (SQUARE_SIZE + LINE_GAP);
X}
X
Xvoid
XDrawSquare(row, column, piece)
X	int row, column;
X	u_char piece;
X{
X	int square_color, x, y;
X
X	if (flipView)
X		column = (BOARD_SIZE - 1) - column;
X	else
X		row = (BOARD_SIZE - 1) - row;
X
X	square_color = ((column % 2 == 1) && (row % 2 == 1))
X		|| ((column % 2 == 0) && (row % 2 == 0));
X
X	x = LINE_GAP + column * (SQUARE_SIZE + LINE_GAP);
X	y = LINE_GAP + row * (SQUARE_SIZE + LINE_GAP);
X
X	if (piece == EmptySquare) {
X		XFillRectangle(xDisplay, xBoardWindow,
X			square_color ? lightSquareGC : darkSquareGC, x, y,
X			SQUARE_SIZE, SQUARE_SIZE);
X		return;
X	}
X
X	if (appData.monoMode) {
X		if (square_color)
X			XCopyPlane(xDisplay, pieceToColor[piece]
X				? *pieceToOutline[piece] : *pieceToSolid[piece],
X				xBoardWindow, pieceToColor[piece] ? wwPieceGC : bwPieceGC,
X				0, 0, SQUARE_SIZE, SQUARE_SIZE, x, y, 1);
X		else XCopyPlane(xDisplay, pieceToColor[piece]
X				? *pieceToSolid[piece] : *pieceToOutline[piece],
X				xBoardWindow, pieceToColor[piece] ? wbPieceGC : bbPieceGC,
X				0, 0, SQUARE_SIZE, SQUARE_SIZE, x, y, 1);
X	} else {
X		if (square_color)
X			XCopyPlane(xDisplay, *pieceToSolid[piece],
X				xBoardWindow, pieceToColor[piece] ? wlPieceGC : blPieceGC,
X				0, 0, SQUARE_SIZE, SQUARE_SIZE, x, y, 1);
X		else XCopyPlane(xDisplay, *pieceToSolid[piece],
X				xBoardWindow, pieceToColor[piece] ? wdPieceGC : bdPieceGC,
X				0, 0, SQUARE_SIZE, SQUARE_SIZE, x, y, 1);

dan
----------------------------------------------------
O'Reilly && Associates   argv at sun.com / argv at ora.com
Opinions expressed reflect those of the author only.
--
dan
----------------------------------------------------
O'Reilly && Associates   argv at sun.com / argv at ora.com
Opinions expressed reflect those of the author only.



More information about the Comp.sources.x mailing list