v11i056: kriegspiel - a chess variant, Part01/03
Steve Schoch
schoch at trident.arc.nasa.gov
Wed Feb 13 18:03:54 AEST 1991
Submitted-by: schoch at trident.arc.nasa.gov (Steve Schoch)
Posting-number: Volume 11, Issue 56
Archive-name: kriegspiel/part01
#!/bin/sh
echo x - README
sed 's/^X//' >README <<'*-*-END-of-README-*-*'
X
XKriegspiel written by David Wolfe based on a program by Bert Enderton
X May 5, 1986
X
XModified to work with X window system by
X Steve Schoch <schoch at ames.arc.nasa.gov>.
X
XI also fixed the protocol to be more ARPA-like. -sks May 19, 1987
X
X1) First adjust the first to constants in constants.h
X2) If your machine does not have malloc (), then see comment in externs.h
X3) type 'make'
X If you don't have X, type "make ks" to make the curses version only.
X
XIf anyone on the arpanet wants to play a game with me, give a shout to
Xschoch at ames.arc.nasa.gov.
*-*-END-of-README-*-*
echo x - README.protocol
sed 's/^X//' >README.protocol <<'*-*-END-of-README.protocol-*-*'
XMay 20, 1987 Steve Schoch <schoch at ames.arc.nasa.gov>
X
XThis file describes the procotol between two games of Kriegspiel.
X
XDeciding on a Port
X Each instance of a game will use this method to decide on which port
Xto connect to carry out the communication with the other game. Since ks
Xrequires no server, one process will be the server, and one the client.
XAfter the initial exchange, there is no distinction between server and
Xclient. Each assumes the other is a peer.
X The ks program compares (using strcmp) the login name of the person
Xinvoking the game with that of the opponent (given on the command line).
XThe login name that is the greater (alphabetically) of the two assumes the
Xrole of server. If both names are the same, the role is decided based on
Xthe IP address of this host, and the host of the opponent, the server
Xbeing the one with the lower IP address.
X If both the login name and the host are the same, then which ever
Xhost binds to the port first is the server.
X
X Once the role is determined, the port is chosen. This is done by the
Xroutines hashaddr and hashport in connect.c. They are too dificult to
Xexplain here.
X
XOptions
X After connecting, the two processes agree on options. Currently,
Xthe options, are color, announce pawn tries, and announce captures.
XIf neither player selects preferences, the defaults are to choose color
Xat random, with announce pawn tries and announce captures on. If either
Xplay selects differently, for instance, if one player selects white,
Xwith announce captures off, then he will be white, and announce captures
Xwill be turned off. If players select conflicting options, for instance,
Xif both want to be white, or one wants announce captures on, and one wants
Xit off, then that option is chosen at random. Additionally, either player
Xcan force an option to be chosen at random.
X
X This is done by the client sending it's option values as ascii
Xdigits, '2' for unset, '0' for no (white), '1' for yes (black), or '3'
Xto force it random. Each line is ended eith <cr><lf>. The server then
Xfigures out the settings of the options, and sends this back to the
Xclient program in the same manner, except that the values will only be
X'0' and '1'.
X
XThe Game
X Each move or attempted move is sent as <start pos>-<end pos>, where
Xeach position is a letter (a-h) and a digit (1-8). The positions are
Xthe same for both processes, with a1 being the starting square for
Xwhite's queen's bishop. Again, each line sent is terminated with <cr><lf>.
XIf a player tries an illegal or blocked move, it is sent anyway, and
Xboth processes announce this fact.
X In addition, there are several other messages that may be sent at
Xany time. "say text", is sent by one program as a message from a player
Xto his opponent. "resign" is sent when one player resigns. draw is sent
Xwhen one player offers to call the game a draw, the opponent's process
Xsends either "yes" or "no" in response as directed by the player.
*-*-END-of-README.protocol-*-*
echo x - ks.1
sed 's/^X//' >ks.1 <<'*-*-END-of-ks.1-*-*'
X.TH KRIEGSPIEL 1 "2 May 1986"
X.UC 4
X.SH NAME
Xkriegspiel \- A Chess Variant
X.SH SYNOPSIS
X.B ks
X[{+-}[bwcaprsdh]] user[@machine]
X.br
Xxks
X[{+-}[bwcaprs]] [display] [=geometry] user[@machine]
X.br
X.SH DESCRIPTION
X.I Kriegspiel
Xis a chess variant in which each player cannot see his opponents
Xpieces. The computer acts as a judge for two players. The rules of
XKriegspiel are discussed at the end of this document.
X.PP
XThe game must be invoked separately by two users. Various options may be
Xchosen in the command line; conflicting options (such as if both players
Xchoose white) are resolved with a flip of a coin.
X.PP
XThe space bar or the return key will pick up the piece under the cursor.
XThe cursor (with or without the piece) may be moved with the terminal
Xarrow keys, or 'h', 'j', 'k', and 'l'.
XTyping return will put the piece down at the current square and typing
Xspace will abort the move and return the piece to its starting place.
XCastling can be done
Xby moving the king two squares.
X.PP
XThe other commands available are:
X.PP
X.br
X.ns
X.TP 15
X'q'
XResign.
X.br
X.ns
X.TP
X'd'
XOffer a draw.
X.br
X.ns
X.TP
X'?'
XShow legal commands.
X.br
X.ns
X.TP
X'a'
XCan I take with any of my pawns?
X.br
X.ns
X.TP
X'm'
XSend message to opponent.
X.br
X.ns
X.TP
X.I Control-L
XRedraw the screen.
X.PP
X.I Xks
Xis an version of the game for the X window system.
XPieces are moved with the left mouse button.
XOther commands are single letters on the keyboard.
XType 'h' for help after game starts.
X.PP
XUnder the default options, you will be informed of the following
Xinformation when applicable:
X.nf
X(1) your opponent tries an illegal move
X(2) you or your opponent is in check from the appropriate direction
X(3) a piece is taken (you will not be told which piece, however)
X(4) there are any pawn tries
X.fi
X.PP
XThe game ends if either player is checkmated or stalemated, if both players
Xhave insufficient material, if either player resigns, if both players
Xagree on a draw, or the game can end due to hardware error. (But not if
Xthe same position comes up three times or if the game goes 50 consecutive
Xmoves without a piece take or pawn capture, as in ordinary chess).
X
X.SH OPTIONS
X.PP
XSome options preceded by a `-' will turn the option off.
XIf the players choose
Xconflicting option, then the option will be chosen by a flip of a coin.
X.PP
X.br
X.ns
X.TP 15
X-w
XI wish to be white. Negated by opponent choosing options `c' or
X`w'
X.br
X.ns
X.TP
X-b
XI wish to be black. Negated by opponent choosing options `c' or
X`b'
X.br
X.ns
X.TP
X-c
XForce color to be chosen randomly. This is the default if neither person
Xchooses a color.
X.br
X.ns
X.TP
X[+-]a
XAnnounce to both players when a piece is taken, revealing also
Xwhether it was a pawn or a major piece that was taken. Also
Xannounce if a pawn ever promotes.
X.br
X.ns
X.TP
X[+-]p
XAnnounce to both players how many possible ways the player to move
Xcan take with his pawns (if he can at all). The player to move can
Xonly try three moves which take with his pawns. If, after exhausting these
Xthree tries, the player's
Xonly legal move is to take with his pawn, then the player is
Xcheckmated or stalemated as appropriate. If the player tries the
Xsame take twice, this will not be counted against him. The `any'
Xcommand is ignored under this option.
X.br
X.ns
X.TP
X-r
XReverse the board if I am black.
X.br
X.ns
X.TP
X-h
XPrint out this help file.
X.br
X.ns
X.TP
X[+-]s
XMake me the server. This option should only be used as a last
Xresort. Invisibly to the user, one player is the
Xserver, and one is the client. These are usually chosen by the
Xprogram by a protocol. If you're having troubles connecting with
Xyour opponent, then try the following: One player invoke the
Xprogram with the `+s' option, and one with the `-s' option.
X.br
X.ns
X.TP
X.I n
XA number between one and a thousand to be used as the port. This option
Xshould only be used if you are having troubles connecting. Both players
Xshould select the same number between 1 and 1000 to be used to compute
Xthe port on which they communicate.
X.SH RULES
XKriegspiel is a chess variation dating back at least before WWII.
XIt requires three people: two players and a judge. The players sit back to
Xback, each with a board with only their own pieces. The judge has a board
Xbetween the players, with the entire position. Each player in his turn
Xtries different moves. For each illegal move tried, the judge says
X`illegal' aloud. If a player is put into check, this fact is said out
Xloud, along with the direction from which he/she is in check: Check along
Xthe file, rank, short diagonal, long diagonal (from the point of view of
Xthe king), and knight. When the player makes a legal move, that is the
Xmove he must play.
X.PP
XBeyond this, the ammount of information the judge should reveal is
Xcontroversial. The author prefers the following. If a piece is taken, the
Xjudge (quietly) removes the piece from the injured party's board. On
Xher/his turn, a person may ask `any?', meaning `Are there any ways of
Xtaking any of my opponent's pieces with any of my pawns?' The judge
Xanswers aloud `yes' or `no', as appropriate. The reason this rule is
Xincluded is to speed up the game; otherwise each player would try all
Xpossible pawn takes at the start of each turn. The disadvantage with
Xasking `any?' is that the opponent also finds out the answer; the advantage
Xis that the player is under no obligation to actually take a piece with one
Xof his pawns, even if the answer is yes. (Thus, he has gained information
Xfor free.)
X.PP
XSome people prefer to play that takes are announced out loud,
Xalong with whether the piece taken was a pawn or not, allowing the players
Xto have an idea how well their doing. Furthermore, that it should be
Xannounced not only whether a person has any available pawn tries, but also
Xhow many on every move. This extra information, it is said, makes the game
Xless chaotic and random, and keeps it from becoming like Battleship.
XHowever, the extra information is somewhat tempered by the fact that a
Xperson may only try to take in three different ways with his pawns, after
Xwhich a pawn take becomes illegal.
X.SH AUTHOR
XDavid Wolfe
X.SH BUGS
XThere is no way of saving a game in progress. This is particularly
Xfrustrating if you are playing on an unreliable network: If the network
Xgoes down, give it up...
X.PP
XOther bugs, unknown. Please notify Steve Schoch <schoch at ames.arpa>
Xor David Wolfe <wolfe at ernie.berkeley.edu>
*-*-END-of-ks.1-*-*
echo x - Imakefile
sed 's/^X//' >Imakefile <<'*-*-END-of-Imakefile-*-*'
X/* SRCS1 are common sources. SRCS2 are curses sources. SRCS3 are X sources.
X *
X SRCS1 = check.c list.c mate.c pawntries.c options.c makemove.c \
X piecemoves.c legalmove.c move.c movetry.c funcs.c \
X error.c review.c init.c connect.c
X SRCS2 = init.c input.c output.c main.c movecycle.c traps.c \
X screen.c doesc.c
X SRCS3 = ChessBoard.c xmain.c xpieces.c xscreen.c xinput.c \
X xboard.c xoutput.c commands.c
X
X/* OBJS1 are common object files. OBJS2 and OBJS3 are separate object
X * files with common sources. OBJS4 are curses object files. OBJS5 are X
X * object files.
X */
X OBJS1 = check.o list.o mate.o pawntries.o options.o makemove.o \
X piecemoves.o legalmove.o move.o movetry.o funcs.o
X OBJS2 = error.o review.o init.o connect.o
X OBJS3 = xerror.o xreview.o xinit.o xconnect.o
X OBJS4 = init.o input.o output.o main.o movecycle.o traps.o \
X screen.o doesc.o
X OBJS5 = xmain.o xpieces.o xscreen.o xinput.o xboard.o \
X xoutput.o ChessBoard.o commands.o
X SRCS = $(SRCS1) $(SRCS2) $(SRCS3)
X OBJS = $(OBJS1) $(OBJS2) $(OBJS3) $(OBJS4) $(OBJS5)
X PROGRAMS = ks xks
X DEPLIBS1 = XawClientDepLibs
X TERMCAPLIB = -ltermcap
X CURSESLIB = -lcurses
X XKS_DEFINES = -DXKS
X
XAllTarget($(PROGRAMS))
X
X#define XksObjectRule(base) @@\
Xbase.o: base.c @@\
X $(CC) -c $(CFLAGS) $(XKS_DEFINES) $*.c @@\
X $(MV) $*.o x$*.o @@\
X $(CC) -c $(CFLAGS) $*.c
X
XXksObjectRule(error)
XXksObjectRule(review)
XXksObjectRule(init)
XXksObjectRule(connect)
XSpecialObjectRule($(OBJS5), ,$(XKS_DEFINES))
X
XNormalProgramTarget(ks,$(OBJS1) $(OBJS2) $(OBJS4),$(DEPLIBS1),,$(CURSESLIB) $(TERMCAPLIB))
XNormalProgramTarget(xks,$(OBJS1) $(OBJS3) $(OBJS5),$(DEPLIBS2),XawClientLibs,)
X
XInstallManPage(ks,$(MANDIR))
X
XDependTarget()
*-*-END-of-Imakefile-*-*
echo x - Makefile
sed 's/^X//' >Makefile <<'*-*-END-of-Makefile-*-*'
X# Makefile generated by imake - do not edit!
X# $XConsortium: imake.c,v 1.51 89/12/12 12:37:30 jim Exp $
X
X###########################################################################
X# Makefile generated from "Imake.tmpl" and <Imakefile>
X# $XConsortium: Imake.tmpl,v 1.77 89/12/18 17:01:37 jim Exp $
X#
X# Platform-specific parameters may be set in the appropriate .cf
X# configuration files. Site-wide parameters may be set in the file
X# site.def. Full rebuilds are recommended if any parameters are changed.
X#
X# If your C preprocessor doesn't define any unique symbols, you'll need
X# to set BOOTSTRAPCFLAGS when rebuilding imake (usually when doing
X# "make Makefile", "make Makefiles", or "make World").
X#
X# If you absolutely can't get imake to work, you'll need to set the
X# variables at the top of each Makefile as well as the dependencies at the
X# bottom (makedepend will do this automatically).
X#
X
X###########################################################################
X# platform-specific configuration parameters - edit is68k.cf to change
X
X# platform: $XConsortium: bsd.cf,v 1.8 89/12/23 14:19:17 jim Exp $
X# operating system: 4.3bsd
X
X###########################################################################
X# site-specific configuration parameters - edit site.def to change
X
X# site: $XConsortium: site.def,v 1.21 89/12/06 11:46:50 jim Exp $
X
X SHELL = /bin/sh
X
X TOP = /usr/src/local/X11R4/mit
X CURRENT_DIR = .
X
X AR = ar cq
X BOOTSTRAPCFLAGS =
X CC = cc
X
X COMPRESS = compress
X CPP = /lib/cpp $(STD_CPP_DEFINES)
X PREPROCESSCMD = cc -E $(STD_CPP_DEFINES)
X INSTALL = install
X LD = ld
X LINT = lint
X LINTLIBFLAG = -C
X LINTOPTS = -axz
X LN = ln -s
X MAKE = make
X MV = mv
X CP = cp
X RANLIB = ranlib
X RANLIBINSTFLAGS =
X RM = rm -f
X STD_INCLUDES =
X STD_CPP_DEFINES =
X STD_DEFINES =
X EXTRA_LOAD_FLAGS =
X EXTRA_LIBRARIES =
X TAGS = ctags
X
X SIGNAL_DEFINES = -DSIGNALRETURNSINT
X
X PROTO_DEFINES =
X
X INSTPGMFLAGS =
X
X INSTBINFLAGS = -m 0755
X INSTUIDFLAGS = -m 4755
X INSTLIBFLAGS = -m 0664
X INSTINCFLAGS = -m 0444
X INSTMANFLAGS = -m 0444
X INSTDATFLAGS = -m 0444
X INSTKMEMFLAGS = -m 4755
X
X DESTDIR =
X
X TOP_INCLUDES = -I$(TOP)
X
X CDEBUGFLAGS =
X CCOPTIONS =
X COMPATFLAGS =
X
X ALLINCLUDES = $(STD_INCLUDES) $(TOP_INCLUDES) $(INCLUDES) $(EXTRA_INCLUDES)
X ALLDEFINES = $(ALLINCLUDES) $(STD_DEFINES) $(PROTO_DEFINES) $(DEFINES) $(COMPATFLAGS)
X CFLAGS = $(CDEBUGFLAGS) $(CCOPTIONS) $(ALLDEFINES)
X LINTFLAGS = $(LINTOPTS) -DLINT $(ALLDEFINES)
X LDLIBS = $(SYS_LIBRARIES) $(EXTRA_LIBRARIES)
X LDOPTIONS = $(CDEBUGFLAGS) $(CCOPTIONS)
X LDCOMBINEFLAGS = -X -r
X
X MACROFILE = is68k.cf
X RM_CMD = $(RM) *.CKP *.ln *.BAK *.bak *.o core errs ,* *~ *.a .emacs_* tags TAGS make.log MakeOut
X
X IMAKE_DEFINES =
X
X IRULESRC = $(CONFIGSRC)
X IMAKE_CMD = $(NEWTOP)$(IMAKE) -I$(NEWTOP)$(IRULESRC) $(IMAKE_DEFINES)
X
X ICONFIGFILES = $(IRULESRC)/Imake.tmpl $(IRULESRC)/Imake.rules \
X $(IRULESRC)/Project.tmpl $(IRULESRC)/site.def \
X $(IRULESRC)/$(MACROFILE) $(EXTRA_ICONFIGFILES)
X
X###########################################################################
X# X Window System Build Parameters
X# $XConsortium: Project.tmpl,v 1.63 89/12/18 16:46:44 jim Exp $
X
X###########################################################################
X# X Window System make variables; this need to be coordinated with rules
X# $XConsortium: Project.tmpl,v 1.63 89/12/18 16:46:44 jim Exp $
X
X PATHSEP = /
X USRLIBDIR = $(DESTDIR)/usr/lib
X BINDIR = $(DESTDIR)/usr/bin/X11
X INCROOT = $(DESTDIR)/usr/include
X BUILDINCROOT = $(TOP)
X BUILDINCDIR = $(BUILDINCROOT)/X11
X BUILDINCTOP = ..
X INCDIR = $(INCROOT)/X11
X ADMDIR = $(DESTDIR)/usr/adm
X LIBDIR = $(USRLIBDIR)/X11
X CONFIGDIR = $(LIBDIR)/config
X LINTLIBDIR = $(USRLIBDIR)/lint
X
X FONTDIR = $(LIBDIR)/fonts
X XINITDIR = $(LIBDIR)/xinit
X XDMDIR = $(LIBDIR)/xdm
X AWMDIR = $(LIBDIR)/awm
X TWMDIR = $(LIBDIR)/twm
X GWMDIR = $(LIBDIR)/gwm
X MANPATH = $(DESTDIR)/usr/man
X MANSOURCEPATH = $(MANPATH)/man
X MANDIR = $(MANSOURCEPATH)n
X LIBMANDIR = $(MANSOURCEPATH)3
X XAPPLOADDIR = $(LIBDIR)/app-defaults
X
X FONTCFLAGS = -t
X
X INSTAPPFLAGS = $(INSTDATFLAGS)
X
X IMAKE = $(IMAKESRC)/imake.is68k
X DEPEND = $(DEPENDSRC)/makedepend
X RGB = $(RGBSRC)/rgb
X FONTC = $(BDFTOSNFSRC)/bdftosnf.is68k
X MKFONTDIR = $(MKFONTDIRSRC)/mkfontdir.is68k
X MKDIRHIER = /bin/sh $(SCRIPTSRC)/mkdirhier.sh
X
X CONFIGSRC = $(TOP)/config
X CLIENTSRC = $(TOP)/clients
X DEMOSRC = $(TOP)/demos
X LIBSRC = $(TOP)/lib
X FONTSRC = $(TOP)/fonts
X INCLUDESRC = $(TOP)/X11
X SERVERSRC = $(TOP)/server
X UTILSRC = $(TOP)/util
X SCRIPTSRC = $(UTILSRC)/scripts
X EXAMPLESRC = $(TOP)/examples
X CONTRIBSRC = $(TOP)/../contrib
X DOCSRC = $(TOP)/doc
X RGBSRC = $(TOP)/rgb
X DEPENDSRC = $(UTILSRC)/makedepend
X IMAKESRC = $(CONFIGSRC)
X XAUTHSRC = $(LIBSRC)/Xau/is68k
X XLIBSRC = $(LIBSRC)/X/is68k
X XMUSRC = $(LIBSRC)/Xmu/is68k
X TOOLKITSRC = $(LIBSRC)/Xt/is68k
X AWIDGETSRC = $(LIBSRC)/Xaw/is68k
X OLDXLIBSRC = $(LIBSRC)/oldX/is68k
X XDMCPLIBSRC = $(LIBSRC)/Xdmcp/is68k
X BDFTOSNFSRC = $(FONTSRC)/bdftosnf
X MKFONTDIRSRC = $(FONTSRC)/mkfontdir
X EXTENSIONSRC = $(TOP)/extensions
X
X DEPEXTENSIONLIB = $(EXTENSIONSRC)/lib/is68k/libXext.a
X EXTENSIONLIB = $(DEPEXTENSIONLIB)
X
X DEPXLIB = $(DEPEXTENSIONLIB) $(XLIBSRC)/libX11.a
X XLIB = $(EXTENSIONLIB) $(XLIBSRC)/libX11.a
X
X DEPXAUTHLIB = $(XAUTHSRC)/libXau.a
X XAUTHLIB = $(DEPXAUTHLIB)
X
X DEPXMULIB = $(XMUSRC)/libXmu.a
X XMULIB = $(DEPXMULIB)
X
X DEPOLDXLIB = $(OLDXLIBSRC)/liboldX.a
X OLDXLIB = $(DEPOLDXLIB)
X
X DEPXTOOLLIB = $(TOOLKITSRC)/libXt.a
X XTOOLLIB = $(DEPXTOOLLIB)
X
X DEPXAWLIB = $(AWIDGETSRC)/libXaw.a
X XAWLIB = $(DEPXAWLIB)
X
X LINTEXTENSIONLIB = $(EXTENSIONSRC)/lib/llib-lXext.ln
X LINTXLIB = $(XLIBSRC)/llib-lX11.ln
X LINTXMU = $(XMUSRC)/llib-lXmu.ln
X LINTXTOOL = $(TOOLKITSRC)/llib-lXt.ln
X LINTXAW = $(AWIDGETSRC)/llib-lXaw.ln
X
X DEPLIBS = $(LOCAL_LIBRARIES)
X
X DEPLIBS1 = $(DEPLIBS)
X DEPLIBS2 = $(DEPLIBS)
X DEPLIBS3 = $(DEPLIBS)
X
X###########################################################################
X# Imake rules for building libraries, programs, scripts, and data files
X# rules: $XConsortium: Imake.rules,v 1.67 89/12/18 17:14:15 jim Exp $
X
X###########################################################################
X# start of Imakefile
X
X OBJS1 = check.o list.o mate.o pawntries.o options.o makemove.o \
X piecemoves.o legalmove.o move.o movetry.o funcs.o
X OBJS2 = error.o review.o init.o connect.o
X OBJS3 = xerror.o xreview.o xinit.o xconnect.o
X OBJS4 = init.o input.o output.o main.o movecycle.o traps.o \
X screen.o doesc.o
X OBJS5 = xmain.o xpieces.o xscreen.o xinput.o xboard.o \
X xoutput.o ChessBoard.o commands.o
X SRCS = $(SRCS1) $(SRCS2) $(SRCS3)
X OBJS = $(OBJS1) $(OBJS2) $(OBJS3) $(OBJS4) $(OBJS5)
X PROGRAMS = ks xks
X DEPLIBS1 = $(DEPXAWLIB) $(DEPXMULIB) $(DEPXTOOLLIB) $(DEPXLIB)
X TERMCAPLIB = -ltermcap
X CURSESLIB = -lcurses
X XKS_DEFINES = -DXKS
X
Xall:: $(PROGRAMS)
X
Xerror.o: error.c
X $(CC) -c $(CFLAGS) $(XKS_DEFINES) $*.c
X $(MV) $*.o x$*.o
X $(CC) -c $(CFLAGS) $*.c
X
Xreview.o: review.c
X $(CC) -c $(CFLAGS) $(XKS_DEFINES) $*.c
X $(MV) $*.o x$*.o
X $(CC) -c $(CFLAGS) $*.c
X
Xinit.o: init.c
X $(CC) -c $(CFLAGS) $(XKS_DEFINES) $*.c
X $(MV) $*.o x$*.o
X $(CC) -c $(CFLAGS) $*.c
X
Xconnect.o: connect.c
X $(CC) -c $(CFLAGS) $(XKS_DEFINES) $*.c
X $(MV) $*.o x$*.o
X $(CC) -c $(CFLAGS) $*.c
X
X$(OBJS5):
X $(RM) $@
X $(CC) -c $(CFLAGS) $(XKS_DEFINES) $*.c
X
Xks: $(OBJS1) $(OBJS2) $(OBJS4) $(DEPLIBS1)
X $(RM) $@
X $(CC) -o $@ $(OBJS1) $(OBJS2) $(OBJS4) $(LDOPTIONS) $(LDLIBS) $(CURSESLIB) $(TERMCAPLIB) $(EXTRA_LOAD_FLAGS)
X
Xclean::
X $(RM) ks
X
Xxks: $(OBJS1) $(OBJS3) $(OBJS5) $(DEPLIBS2)
X $(RM) $@
X $(CC) -o $@ $(OBJS1) $(OBJS3) $(OBJS5) $(LDOPTIONS) $(XAWLIB) $(XMULIB) $(XTOOLLIB) $(XLIB) $(LDLIBS) $(EXTRA_LOAD_FLAGS)
X
Xclean::
X $(RM) xks
X
Xinstall.man:: ks.man
X $(INSTALL) -c $(INSTMANFLAGS) ks.man $(MANDIR)/ks.n
X
Xdepend:: $(DEPEND)
X
X$(DEPEND):
X @echo "checking $@ over in $(DEPENDSRC) first..."; \
X cd $(DEPENDSRC); $(MAKE); \
X echo "okay, continuing in $(CURRENT_DIR)"
X
Xdepend::
X $(DEPEND) -s "# DO NOT DELETE" -- $(ALLDEFINES) -- $(SRCS)
X
X###########################################################################
X# common rules for all Makefiles - do not edit
X
Xemptyrule::
X
Xclean::
X $(RM_CMD) \#*
X
XMakefile:: $(IMAKE)
X
X$(IMAKE):
X @(cd $(IMAKESRC); if [ -f Makefile ]; then \
X echo "checking $@ in $(IMAKESRC) first..."; $(MAKE) all; else \
X echo "bootstrapping $@ from Makefile.ini in $(IMAKESRC) first..."; \
X $(MAKE) -f Makefile.ini BOOTSTRAPCFLAGS=$(BOOTSTRAPCFLAGS); fi; \
X echo "okay, continuing in $(CURRENT_DIR)")
X
XMakefile::
X - at if [ -f Makefile ]; then \
X echo " $(RM) Makefile.bak; $(MV) Makefile Makefile.bak"; \
X $(RM) Makefile.bak; $(MV) Makefile Makefile.bak; \
X else exit 0; fi
X $(IMAKE_CMD) -DTOPDIR=$(TOP) -DCURDIR=$(CURRENT_DIR)
X
Xtags::
X $(TAGS) -w *.[ch]
X $(TAGS) -xw *.[ch] > TAGS
X
X###########################################################################
X# empty rules for directories that do not have SUBDIRS - do not edit
X
Xinstall::
X @echo "install in $(CURRENT_DIR) done"
X
Xinstall.man::
X @echo "install.man in $(CURRENT_DIR) done"
X
XMakefiles::
X
Xincludes::
X
X###########################################################################
X# dependencies generated by makedepend
X
*-*-END-of-Makefile-*-*
echo x - ChessBoard.c
sed 's/^X//' >ChessBoard.c <<'*-*-END-of-ChessBoard.c-*-*'
X#include <X11/Xlib.h>
X#include <X11/IntrinsicP.h>
X#include <X11/StringDefs.h>
X#include <X11/Xaw/XawInit.h>
X#include "ChessBoardP.h"
X#include "externs.h"
X
Xstatic void Init(), BoardResize(), BoardExpose();
Xstatic XtGeometryResult QueryGeometry();
Xstatic void Pick(), Put(), Drop(), Move();
X
Xstatic Boolean defaultUNSET = UNSET;
Xstatic Boolean defaultTRUE = TRUE;
X
Xstatic XtResource resources[] = {
X{XtNside, XtCString, XtRString, sizeof (char *),
X XtOffset(ChessBoardWidget, chess_board.side),
X XtRString, (caddr_t) NULL},
X{XtNserver, XtCBoolean, XtRBoolean, sizeof (Boolean),
X XtOffset(ChessBoardWidget, chess_board.server),
X XtRBoolean, (caddr_t) &defaultUNSET},
X{XtNreverse, XtCBoolean, XtRBoolean, sizeof (Boolean),
X XtOffset(ChessBoardWidget, chess_board.reverse),
X XtRBoolean, (caddr_t) &defaultTRUE},
X{XtNannounceTakes, XtCBoolean, XtRBoolean, sizeof (Boolean),
X XtOffset(ChessBoardWidget, chess_board.announce_takes),
X XtRBoolean, (caddr_t) &defaultUNSET},
X{XtNannouncePawns, XtCBoolean, XtRBoolean, sizeof (Boolean),
X XtOffset(ChessBoardWidget, chess_board.announce_pawns),
X XtRBoolean, (caddr_t) &defaultUNSET},
X};
X
Xstatic XtActionsRec actionTable[] = {
X { "Pick", Pick },
X { "Put", Put },
X { "Drop", Drop },
X { "Move", Move },
X};
X
Xstatic char defaultTranslations[] =
X "<Btn1Down>: Pick()\n\
X <Btn1Motion>: Move()\n\
X <Btn1Up>: Put()\n\
X <Leave>: Drop()";
X
XChessBoardClassRec chessBoardClassRec = {
X { /* superclass */ (WidgetClass)&simpleClassRec,
X /* class_name */ "ChessBoard",
X /* widget_size */ sizeof (ChessBoardRec),
X /* class_initialize */ NULL,
X /* class_part_initialize */ NULL,
X /* class_inited */ False,
X /* initialize */ Init,
X /* initialize_hook */ NULL,
X /* realize */ XtInheritRealize,
X /* actions */ actionTable,
X /* num_actions */ XtNumber(actionTable),
X /* resources */ resources,
X /* num_resources */ XtNumber(resources),
X /* xrm_class */ NULLQUARK,
X /* compress_motion */ TRUE,
X /* compress_exposure */ FALSE,
X /* compress_enterleave */ TRUE,
X /* visible_interest */ FALSE,
X /* destroy */ NULL,
X /* resize */ BoardResize,
X /* expose */ BoardExpose,
X /* set_values */ NULL,
X /* set_values_hook */ NULL,
X /* set_values_almost */ XtInheritSetValuesAlmost,
X /* get_values_hook */ NULL,
X /* accept_focus */ NULL,
X /* version */ XtVersion,
X /* callback_private */ NULL,
X /* tm_table */ defaultTranslations,
X /* query_geometry */ QueryGeometry,
X /* display_accelerator */ XtInheritDisplayAccelerator,
X /* extension */ NULL
X },
X /* Simple class field initialization */
X {
X /* change_sensitive */ XtInheritChangeSensitive
X }
X};
X
XWidgetClass chessBoardWidgetClass = (WidgetClass)&chessBoardClassRec;
X
Xstatic void
XInit(request, new)
XWidget request, new;
X{
X ChessBoardWidget w = (ChessBoardWidget)new;
X Pixel t;
X
X if (w->core.width <= 0)
X w->core.width = 64*8;
X if (w->core.height <= 0)
X w->core.height = 64*10;
X if (w->chess_board.side) {
X if (strcmp(w->chess_board.side, "white") == 0)
X option[COLOR] = WHITE;
X else if (strcmp(w->chess_board.side, "black") == 0)
X option[COLOR] = BLACK;
X else if (strcmp(w->chess_board.side, "random") == 0)
X option[COLOR] = RANDOM;
X }
X iamserver = w->chess_board.server;
X reverse = w->chess_board.reverse;
X option[ANNOUNCETAKES] = w->chess_board.announce_takes;
X option[ANNOUNCEPAWNS] = w->chess_board.announce_pawns;
X}
X
Xstatic void
XBoardExpose(w, event, region)
XWidget w;
XXEvent *event;
XRegion region;
X{
X redraw_region( event->xexpose.x, event->xexpose.y,
X event->xexpose.width, event->xexpose.height, event->xexpose.count);
X}
X
Xstatic void
XBoardResize(w)
XWidget w;
X{
X}
X
Xstatic XtGeometryResult
XQueryGeometry(w, request, preferred)
XWidget w;
XXtWidgetGeometry *request, *preferred;
X{
X preferred->request_mode = CWWidth | CWHeight;
X preferred->width = 64*8;
X preferred->height = 64*10;
X if ((request->request_mode & (CWWidth | CWHeight)) ==
X (CWWidth|CWHeight) &&
X request->width == preferred->width &&
X request->height == preferred->height)
X return XtGeometryYes;
X else if (preferred->width == w->core.width &&
X preferred->height == w->core.height)
X return XtGeometryNo;
X else
X return XtGeometryAlmost;
X}
X
Xstatic void
XPick(w, event)
XWidget w;
XXEvent *event;
X{
X startmove(event->xbutton.x, event->xbutton.y);
X}
X
Xstatic void
XDrop()
X{
X if (moving)
X droppiece();
X}
X
Xstatic void
XMove(w, event)
XWidget w;
XXEvent *event;
X{
X if (!moving)
X return;
X piecemove(event->xmotion.x, event->xmotion.y);
X}
X
Xstatic void
XPut(w)
XWidget w;
X{
X if (moving)
X stopmove();
X}
*-*-END-of-ChessBoard.c-*-*
echo x - ChessBoardP.h
sed 's/^X//' >ChessBoardP.h <<'*-*-END-of-ChessBoardP.h-*-*'
X#include <X11/Xaw/SimpleP.h>
X
X/* Class stuff */
Xtypedef struct {int foo; } ChessBoardClassPart;
X
Xtypedef struct _ChessBoardClassRec {
X CoreClassPart core_class;
X SimpleClassPart simple_class;
X ChessBoardClassPart chess_board_class;
X} ChessBoardClassRec;
X
X/* Widget stuff */
X
Xtypedef struct {
X char *side;
X Boolean server;
X Boolean reverse;
X Boolean announce_takes;
X Boolean announce_pawns;
X} ChessBoardPart;
X
Xtypedef struct _ChessBoardRec {
X CorePart core;
X SimplePart simple;
X ChessBoardPart chess_board;
X} ChessBoardRec;
X
X/* This stuff should go in Ks.h, but I'm lazy... */
X
X#define XtNside "side"
X#define XtNserver "server"
X#define XtNreverse "reverse"
X#define XtNannounceTakes "announceTakes"
X#define XtNannouncePawns "announcePawns"
X
Xextern ChessBoardClassRec chessBoardClassRec;
X
Xextern WidgetClass chessBoardWidgetClass;
X
Xtypedef struct _ChessBoardClassRec *ChessBoardWidgetClass;
Xtypedef struct _ChessBoardRec *ChessBoardWidget;
*-*-END-of-ChessBoardP.h-*-*
echo x - check.c
sed 's/^X//' >check.c <<'*-*-END-of-check.c-*-*'
X#ifndef lint
Xstatic char rcsid[] = "$Header: check.c,v 1.4 87/02/12 13:21:04 schoch Exp $";
X#endif
X
X/* check.c */
X#include "externs.h"
X
Xmoveintocheck (from, to)
X int from, to;
X{
X int victim, intocheck;
X u_char color;
X LIST check ();
X
X color = whose [from]; /* make move on board */
X victim = findvictim (from, to);
X if (victim)
X whose [victim] = EMPTY;
X whose [to] = color;
X whose [from] = EMPTY;
X if (occupant [from] == KING)
X kingloc [color] = to;
X intocheck = (check (color) != NIL); /* see if now in check */
X if (occupant [from] == KING) /* restore board position */
X kingloc [color] = from;
X whose [from] = color;
X whose [to] = EMPTY;
X if (victim)
X whose [victim] = 1 - color;
X return intocheck;
X}
X
XLIST
Xcheck (color)
Xu_char color;
X{
X LIST l, checkdirs, lmember (), linsert ();
X int direction, spot, dist, side;
X
X checkdirs = NIL;
X l = dirlist [QUEEN];
X while (l != NIL) {
X direction = l->i;
X l = l->n;
X spot = kingloc [color];
X for (dist = 1; TRUE; dist++) {
X spot += direction;
X if (spot < 0 || spot > 99)
X continue;
X if ((whose [spot] == 1 - color)
X && (lmember (-direction, dirlist [occupant [spot]])
X && !(occupant [spot] == KING && dist > 1)))
X checkdirs = linsert (checkdirs, direction);
X if (whose [spot] != EMPTY)
X break;
X }
X }
X l = dirlist [KNIGHT];
X while (l != NIL) {
X direction = l->i;
X l = l->n;
X spot = kingloc [color] + direction;
X if (spot < 0 || spot > 99)
X continue;
X if (whose [spot] == 1 - color && occupant [spot] == KNIGHT)
X checkdirs = linsert (checkdirs, direction);
X }
X for (side = -1; side <= 1; side += 2) {
X spot = kingloc [color] + pawndir [color] + side;
X if (spot < 0 || spot > 99)
X continue;
X if (whose [spot] == 1 - color && occupant [spot] == PAWN)
X checkdirs = linsert(checkdirs, pawndir [color] + side);
X }
X
X return checkdirs;
X}
*-*-END-of-check.c-*-*
echo x - commands.c
sed 's/^X//' >commands.c <<'*-*-END-of-commands.c-*-*'
X#include "externs.h"
X#include <X11/Xaw/Command.h>
X#include <X11/Xaw/Label.h>
X#include <X11/Xaw/Form.h>
X#include <X11/Xaw/Dialog.h>
X#include <X11/Xaw/AsciiText.h>
X#include <X11/IntrinsicP.h>
X#include <X11/Shell.h>
X#include <X11/CoreP.h>
X#include "ChessBoardP.h"
X
Xstatic void Cquit(), Cresign(), Cdraw(), Cyes(), Cno(), Cmessage(), Cany();
Xstatic void SendMessage(), CancelSend();
X
Xstatic struct f {
X char *name;
X void (*func)();
X Widget *widget;
X Boolean sensitive;
X} funcs[] = {
X "quit", Cquit, &c_quit, True,
X "resign", Cresign, &c_resign, False,
X "draw", Cdraw, &c_draw, False,
X "yes", Cyes, &c_yes, False,
X "no", Cno, &c_no, False,
X "send message", Cmessage, &c_message, False,
X "any", Cany, &c_any, False,
X 0, 0
X};
X
Xchar message_buf[1024];
X
Xstatic void
XCquit(w, client_data, call_data)
XWidget w;
Xcaddr_t client_data;
Xcaddr_t call_data;
X{
X exit(0);
X}
X
Xstatic void
XCresign()
X{
X do_resign();
X}
X
Xstatic void
XCdraw()
X{
X draw();
X}
X
Xstatic void
XCyes()
X{
X yes();
X}
X
Xstatic void
XCno()
X{
X no();
X}
X
Xstatic void
XCmessage()
X{
X int n;
X Arg args[10];
X Position x, y;
X
X XtSetSensitive(c_message, False);
X XtTranslateCoords(c_message, 0, 0, &x, &y);
X n = 0;
X XtSetArg(args[n], XtNx, x); n++;
X XtSetArg(args[n], XtNy, y); n++;
X XtSetValues(popup, args, n);
X XtPopup(popup, XtGrabNone);
X}
X
Xstatic void
XCany()
X{
X any();
X}
X
Xextern Widget message_wins[];
X
Xinitwidgets(w)
XWidget w;
X{
X Arg args[20];
X int n;
X XtCallbackRec callbacks[2];
X struct f *f;
X Widget t = 0;
X Widget *children;
X int numChildren;
X static String table =
X "#override\
X Ctrl<Key>J: insert-char()\n\
X <Key>0xff0a: insert-char()\n\
X Ctrl<Key>O: insert-char()\n\
X Ctrl<Key>M: no-op()\n\
X Ctrl<Key>N: insert-char()\n\
X <Key>0xff54: insert-char()\n\
X Meta<Key>Z: insert-char()\n\
X Meta<Key>\>: insert-char()\n\
X Meta<Key>I: insert-char()\n\
X <Key>0xff0d: insert-char()";
X XtTranslations tran;
X
X form = XtCreateManagedWidget("xks", formWidgetClass, w, NULL, 0);
X n = 0;
X XtSetArg(args[n], XtNsensitive, False); n++;
X message_wins[MYCOLOR] = XtCreateManagedWidget("--- color ---",
X labelWidgetClass, form, args, n);
X
X n = 0;
X XtSetArg(args[n], XtNsensitive, False); n++;
X XtSetArg(args[n], XtNfromHoriz, message_wins[MYCOLOR]); n++;
X XtSetArg(args[n], XtNresizable, True); n++;
X message_wins[TOMOVE] = XtCreateManagedWidget("white to move",
X labelWidgetClass, form, args, n);
X
X n = 0;
X XtSetArg(args[n], XtNsensitive, False); n++;
X XtSetArg(args[n], XtNfromHoriz, message_wins[TOMOVE]); n++;
X XtSetArg(args[n], XtNborderWidth, 0); n++;
X XtSetArg(args[n], XtNresizable, True); n++;
X message_wins[PAWNTRIES] = XtCreateManagedWidget("no pawntries",
X labelWidgetClass, form, args, n);
X
X n = 0;
X XtSetArg(args[n], XtNsensitive, False); n++;
X XtSetArg(args[n], XtNfromHoriz, message_wins[PAWNTRIES]); n++;
X XtSetArg(args[n], XtNborderWidth, 0); n++;
X XtSetArg(args[n], XtNresizable, True); n++;
X message_wins[CAPTURE] = XtCreateManagedWidget("piece captured",
X labelWidgetClass, form, args, n);
X
X message_wins[LEGAL] = message_wins[CAPTURE];
X
X t = 0;
X bzero(callbacks, sizeof callbacks);
X for (f = funcs; f->name; f++) {
X callbacks[0].callback = f->func;
X n = 0;
X XtSetArg(args[n], XtNfromVert, message_wins[MYCOLOR]); n++;
X if (t) {
X XtSetArg(args[n], XtNfromHoriz, t); n++;
X }
X XtSetArg(args[n], XtNcallback, callbacks); n++;
X XtSetArg(args[n], XtNsensitive, f->sensitive); n++;
X /* The following line for c_yes and c_no */
X XtSetArg(args[n], XtNresizable, True); n++;
X t = XtCreateManagedWidget(f->name, commandWidgetClass, form,
X args, n);
X *f->widget = t;
X }
X
X XtSetArg(args[0], XtNfromVert, c_quit);
X XtSetArg(args[1], XtNwidth, 512);
X message_wins[MESSAGE] = XtCreateManagedWidget("message",
X labelWidgetClass, form, args, 2);
X message_wins[OPPONENT] = message_wins[MESSAGE];
X
X n = 0;
X XtSetArg(args[n], XtNfromVert, message_wins[MESSAGE]); n++;
X XtSetArg(args[n], XtNsensitive, False); n++;
X XtSetArg(args[n], XtNborderWidth, 0); n++;
X XtSetArg(args[n], XtNresizable, True); n++;
X message_wins[CHECK] = XtCreateManagedWidget("check ",
X labelWidgetClass, form, args, n);
X
X n = 0;
X XtSetArg(args[n], XtNfromVert, message_wins[MESSAGE]); n++;
X XtSetArg(args[n], XtNfromHoriz, message_wins[CHECK]); n++;
X XtSetArg(args[n], XtNsensitive, False); n++;
X XtSetArg(args[n], XtNhorizDistance, 80); n++;
X XtSetArg(args[n], XtNborderWidth, 0); n++;
X XtSetArg(args[n], XtNresizable, True); n++;
X message_wins[PAWNWINDOW] = XtCreateManagedWidget("pawn",
X labelWidgetClass, form, args, n);
X
X n = 0;
X XtSetArg(args[n], XtNfromVert, message_wins[CHECK]); n++;
X XtSetArg(args[n], XtNvertDistance, 5); n++;
X board = XtCreateManagedWidget("board", chessBoardWidgetClass,
X form, args, n);
X
X n = 0;
X popup = XtCreatePopupShell("prompt", transientShellWidgetClass, form,
X args, n);
X XtSetArg(args[n], XtNlabel, "Message to send:"); n++;
X XtSetArg(args[n], XtNvalue, ""); n++;
X dialog = XtCreateManagedWidget("message", dialogWidgetClass, popup,
X args, n);
X XawDialogAddButton(dialog, "Send", SendMessage, dialog);
X XawDialogAddButton(dialog, "Cancel", CancelSend, dialog);
X XtSetArg(args[0], XtNchildren, &children);
X XtSetArg(args[1], XtNnumChildren, &numChildren);
X XtGetValues(dialog, args, 2);
X text = 0;
X for (n = 0; n < numChildren; n++)
X if (XtClass(children[n]) == asciiTextWidgetClass) {
X text = children[n];
X break;
X }
X if (text) {
X tran = XtParseTranslationTable(table);
X XtOverrideTranslations(text, tran);
X }
X n = 0;
X XtSetArg(args[n], XtNwidth, 200); n++;
X XtSetValues(dialog, args, n);
X}
X
Xstatic void
XSendMessage(w, dialog, call_data)
XWidget w;
XWidget dialog;
XXtPointer call_data;
X{
X char buf[1024];
X register char *cp;
X register char *dp=buf;
X Arg args[1];
X
X XtSetSensitive(c_message, True);
X for (cp = XawDialogGetValueString(dialog); *cp; cp++)
X if (*cp < ' ')
X switch (*cp) {
X case '\t':
X *dp++ = '\t';
X break;
X case '\n':
X case '\r':
X *dp++ = ' ';
X break;
X case '\7':
X *dp++ = *cp;
X break;
X default:
X *dp++ = '^';
X *cp++ = *cp|0x40;
X break;
X }
X else if (*cp == '\177') {
X *dp++ = '^';
X *dp++ = '?';
X } else
X *dp++ = *cp;
X *dp = '\0';
X if (dp > buf)
X send_message(buf);
X if (text) {
X XtSetArg(args[0], XtNstring, NULL);
X XtSetValues(text, args, 1);
X }
X XtPopdown(popup);
X}
X
Xstatic void
XCancelSend(w, dialog, call_data)
XWidget w;
XWidget dialog;
XXtPointer call_data;
X{
X XtSetSensitive(c_message, True);
X XtPopdown(popup);
X}
*-*-END-of-commands.c-*-*
echo x - connect.c
sed 's/^X//' >connect.c <<'*-*-END-of-connect.c-*-*'
X#ifndef lint
Xstatic char rcsid[] = "$Header: connect.c,v 1.1 87/12/08 14:42:23 schoch Exp $";
X#endif
X
X#include "externs.h"
X#include <sys/types.h>
X#include <sys/socket.h>
X#include <sys/param.h>
X#include <netinet/in.h>
X#include <netdb.h>
X#include <pwd.h>
X#include <errno.h>
X
Xextern int errno;
X
Xint sock; /* in main */
XFILE *inp, *out;
Xstatic struct sockaddr_in addr;
Xextern void sockopen();
Xvoid try_conn();
Xint rw;
X
Xstart_conn(opponent, port)
X char *opponent;
X u_short port;
X{
X struct hostent *host;
X struct passwd *mypasswd, *getpwuid();
X char *hishostname, *myname, *index(), *getpw(), *malloc();
X char myhostname[MAXHOSTNAMELEN+1];
X char *hisaddr, *myaddr;
X int hislen, mylen;
X u_long iaddr;
X uid_t getuid();
X u_short hashport(), hashaddr();
X char *copyhost();
X int s, i;
X auto int on=1;
X
X if (gethostname (myhostname, MAXHOSTNAMELEN) < 0)
X error ("gethostname in connectport");
X host = gethostbyname(myhostname);
X if (host == NULL) {
X errno = 0;
X error("don't know my own name.");
X }
X mylen = host->h_length;
X myaddr = copyhost(host);
X if (hishostname = index (opponent, '@')) {
X *hishostname++ = '\0'; /* separate user and host */
X if (hishostname[0] >= '0' && hishostname[0] <= '9') {
X iaddr = inet_addr(hishostname);
X hisaddr = (char *)&iaddr;
X hislen = sizeof iaddr;
X } else {
X host = gethostbyname(hishostname);
X if (host == NULL) {
X errno = 0;
X error("Unknown host");
X }
X hislen = host->h_length;
X hisaddr = copyhost(host);
X hishostname = host->h_name;
X }
X } else {
X hislen = mylen;
X hisaddr = myaddr;
X hishostname = myhostname;
X }
X mypasswd = getpwuid ((int) getuid());
X myname = mypasswd -> pw_name;
X if (iamserver == UNSET)
X if (i = strcmp (myname, opponent))
X iamserver = (i < 0);
X else if (i = comparehost(myaddr, hisaddr, mylen))
X iamserver = (i < 0);
X if ((sock = socket (AF_INET, SOCK_STREAM, 0)) < 0)
X error ("socket in connectport");
X if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &on, sizeof on) < 0)
X perror("setsockopt");
X bzero ((char *) &addr, sizeof (addr));
X if (port != 0) {
X if (port > 1000) {
X errno = 0;
X error ("bad port number");
X }
X } else if (iamserver) {
X port = hashaddr(myaddr, port, mylen);
X port = hashaddr(hisaddr, port, hislen);
X port = hashport(myname, port);
X port = hashport(opponent, port);
X } else {
X port = hashaddr(hisaddr, port, hislen);
X port = hashaddr(myaddr, port, mylen);
X port = hashport(opponent, port);
X port = hashport(myname, port);
X }
X port += 3000;
X addr.sin_family = AF_INET;
X addr.sin_port = htons (port);
X addr.sin_addr.s_addr = INADDR_ANY;
X if (iamserver) {
X if (bind (sock, &addr, sizeof (addr)) < 0)
X if (errno == EADDRINUSE && iamserver == UNSET) {
X /* hope other player is server */
X iamserver = FALSE;
X } else
X error ("bind in connectport");
X if (iamserver) {
X if (listen (sock, 0) < 0)
X error ("listen in connectport");
X rw = FREAD;
X#ifdef XKS
X sockid = XtAppAddInput(my_app, sock, XtInputReadMask,
X sockopen, &rw);
X#else
X FD_SET(sock, &readset);
X#endif
X return;
X }
X }
X bcopy (hisaddr, (char *) &addr.sin_addr, hislen);
X
X try_conn(NULL, NULL);
X}
X
X#ifdef XKS
Xvoid
Xtry_conn(data, id)
Xcaddr_t data;
XXtIntervalId *id;
X#else
Xvoid
Xtry_conn()
X#endif
X{
X int s;
X
X rw = FWRITE;
X if ((sock = socket (AF_INET, SOCK_STREAM, 0)) < 0)
X error ("socket in try_conn");
X fcntl(sock, F_SETFL, FNDELAY);
X s = connect(sock, &addr, sizeof (addr));
X if (s < 0)
X if (errno == EINPROGRESS) {
X#ifdef XKS
X sockid = XtAppAddInput(my_app, sock, XtInputWriteMask,
X sockopen, &rw);
X#else
X FD_SET(sock, &writeset);
X#endif
X return;
X } else if (errno == ECONNREFUSED)
X ;
X else
X error("connect");
X sockopen((caddr_t)&rw, (int *)0, 0);
X}
X
Xfinish_conn(rw)
X{
X int s;
X struct sockaddr_in hisaddr;
X auto int hislen = sizeof hisaddr;
X static struct timeval try_again;
X
X if (rw == FREAD) {
X s = accept(sock, &hisaddr, &hislen);
X if (s < 0)
X error("accept");
X close(sock);
X sock = s;
X } else {
X fcntl(sock, F_SETFL, 0);
X if (getpeername(sock, &hisaddr, &hislen) < 0) {
X if (errno != ENOTCONN)
X error("getpeername");
X close(sock);
X#ifdef XKS
X (void)XtAppAddTimeOut(my_app, 2000, try_conn, NULL);
X#else
X try_again.tv_sec = 2;
X try_again.tv_usec = 0;
X seltimeout = &try_again;
X#endif
X return -1;
X }
X }
X if ((s = dup(sock)) < 0)
X error("dup");
X if ((inp = fdopen(sock, "r")) == NULL)
X error("fdopen");
X if ((out = fdopen(s, "w")) == NULL)
X error("fdopen");
X setlinebuf(out);
X return 0;
X}
X
Xu_short
Xhashport (s, port)
X char *s;
X u_short port;
X{
X while (*s)
X port = (port << 1) + *s++;
X return (port & 0x7fff);
X}
X
X/*
X * addr is in network byte order.
X */
Xu_short
Xhashaddr(addr, port, len)
Xu_short port;
Xchar *addr;
X{
X
X while (len--)
X port = (port << 1) + *addr++;
X return (port & 0x7fff);
X}
X
Xchar *
Xcopyhost(host)
Xstruct hostent *host;
X{
X char *ret;
X
X ret = malloc(host->h_length);
X if (ret == NULL)
X error("malloc");
X bcopy(host->h_addr, ret, host->h_length);
X
X return ret;
X}
X
X/* Compare h1 and h2 (in network byte order). The network number is
X * more significant than the host number, thus we need to call ntohl().
X */
Xcomparehost(h1, h2, len)
Xchar *h1, *h2;
X{
X auto unsigned long l1, l2;
X
X bcopy(h1, &l1, sizeof l1);
X bcopy(h2, &l2, sizeof l2);
X l1 = ntohl(l1);
X l2 = ntohl(l2);
X
X if (l1 < l2)
X return -1;
X else if (l1 > l2)
X return 1;
X return 0;
X}
*-*-END-of-connect.c-*-*
echo x - constants.h
sed 's/^X//' >constants.h <<'*-*-END-of-constants.h-*-*'
X/*
X * $Header: constants.h,v 1.3 87/05/19 18:48:05 schoch Exp $
X */
X
X/* These next two constants are system dependent */
X
X/* file used for printing a file to the terminal (try /bin/pr) */
X#define PRINT_FILE "/usr/ucb/more"
X/* file where help will be kept */
X#define HELP_FILE "/usr/games/src/ks/help"
X
X#define ILLEGAL_PIECE -1
X#define ILLEGAL -1
X#define NOWAY -2
X#define AMBIGUOUS -3
X#define NOMOREPAWNTRIES -4
X
X#define UNSET 2
X#define RANDOM 3
X#define NIL 0
X#define MAXBUFF 100
X
X#define WHITE 0
X#define BLACK 1
X#define EMPTY 2
X#define OFFBOARD 3
X
X#define PAWN 1
X#define KING 2
X#define KNIGHT 3
X#define BISHOP 4
X#define ROOK 5
X#define QUEEN 6
X
X#define MESSAGE 0
X#define CHECK 1
X#define LEGAL 2
X#define CAPTURE 3
X#define TOMOVE 4
X#define PAWNTRIES 5
X#define MYCOLOR 6
X#define CLOCK 7
X#define PROMPT 8
X#define INPUT 9
X#define OPPONENT 10
X#define PAWNWINDOW 11
X
X#define NOPTIONS 3
X#define COLOR 0
X#define ANNOUNCETAKES 1
X#define ANNOUNCEPAWNS 2
X
X/* states */
X#define PLAYING 0
X#define OVER 1 /* game over */
X#define REVIEW 2 /* doing review */
X#define CONNECTING 3 /* no connection yet */
X
X/* keypad keys */
X#define K_UP 257
X#define K_DOWN 258
X#define K_LEFT 259
X#define K_RIGHT 260
X#define K_HOME 261
*-*-END-of-constants.h-*-*
echo x - doesc.c
sed 's/^X//' >doesc.c <<'*-*-END-of-doesc.c-*-*'
X#include <stdio.h>
X#include <curses.h>
X#include <strings.h>
X#include "constants.h"
X
Xstatic char buf[32];
Xstatic char *cp;
X
Xdoesc(c)
X{
X int value = 0;
X
X do {
X *cp++ = c;
X *cp = '\0';
X if (KU && strcmp(buf, KU) == 0)
X value = K_UP;
X if (KD && strcmp(buf, KD) == 0)
X value = K_DOWN;
X if (KL && strcmp(buf, KL) == 0)
X value = K_LEFT;
X if (KR && strcmp(buf, KR) == 0)
X value = K_RIGHT;
X if (KH && strcmp(buf, KH) == 0)
X value = K_HOME;
X
X if (value)
X cp = &buf[1];
X
X if (cp - buf > sizeof buf - 1)
X if (cp = index(buf+1, '\033')) {
X register char *ocp = buf;
X
X while (*ocp++ = *cp++)
X ;
X cp = ocp;
X } else
X cp = &buf[1];
X if (value)
X return value;
X c = 0;
X if (stdin->_cnt)
X c = getchar();
X } while (c);
X return 0;
X}
X
Xinitesc()
X{
X if (KS) {
X fputs(KS, stdout);
X fflush(stdout);
X }
X
X cp = buf;
X *cp++ = '\033';
X}
X
Xresetesc()
X{
X cp = &buf[1];
X}
*-*-END-of-doesc.c-*-*
echo x - error.c
sed 's/^X//' >error.c <<'*-*-END-of-error.c-*-*'
X#ifndef lint
Xstatic char rcsid[] = "$Header: error.c,v 1.3 87/02/12 10:57:44 schoch Exp $";
X#endif
X
X#include "externs.h"
X#include <errno.h>
X#include <signal.h>
X
Xerror (s)
X char *s;
X{
X#ifndef XKS
X move(LINES-1, 0);
X refresh();
X endwin();
X putchar('\n');
X#endif
X if (errno == EPIPE) {
X dead = TRUE;
X state_change(state == PLAYING ? OVER : state);
X } else {
X if (s != (char *) NULL)
X if (errno)
X perror (s);
X else
X fprintf(stderr, "%s\n", s);
X if (out)
X fclose(out);
X if (inp)
X fclose(inp);
X exit (0);
X }
X}
*-*-END-of-error.c-*-*
echo x - externs.h
sed 's/^X//' >externs.h <<'*-*-END-of-externs.h-*-*'
X/*
X * $Header: externs.h,v 1.1 87/12/07 17:33:40 schoch Exp $
X */
X
X#include "constants.h"
X#include <stdio.h>
X
X#ifdef XKS
X
X#include <X11/Xlib.h>
X#include <X11/Intrinsic.h>
X#include <X11/StringDefs.h>
X#define NULL 0
Xtypedef unsigned char bool;
X
X#else
X
X#include <curses.h>
X#include <sys/time.h>
X#include <sys/file.h>
X
X#endif XKS
X
X#include <errno.h>
X#include <sys/types.h>
X/* on machines without alloca () */
X/* #define alloca malloc */
X
Xstruct IN
X{
X int i;
X struct IN *n;
X};
Xtypedef struct IN *LIST;
X
Xstruct MOVE
X{
X int from;
X int to;
X struct MOVE *n;
X};
Xtypedef struct MOVE *MOVELIST;
X
Xextern u_char occupant [100]; /* what piece occupies square */
Xextern u_char whose [100]; /* which color occupies square */
Xextern u_char ghost[100]; /* opponent's "ghost" pieces */
Xextern u_char captured[32]; /* pieces captured */
Xextern u_char disp_captured[32]; /* pieces displayed as captured */
Xextern LIST dirlist [7]; /* directions a piece moves */
Xextern pawndir [2]; /* direction pawns of move */
Xextern LIST piecelocs [2]; /* locations of pieces */
Xextern int kingloc [2]; /* location of king */
Xextern MOVELIST movelist; /* record of game */
Xextern u_char ourcolor;
Xextern u_char theircolor;
Xextern char *colorname [];
Xextern int lastmovefrom;
Xextern int lastmoveto;
Xextern u_char virgin [100]; /* pieces not moved or captured */
Xextern bool drawok [2]; /* side has agreed to draw */
Xextern bool resign; /* somebody resigned */
Xextern bool dead; /* somebody died */
Xextern bool reverse; /* Show board in reverse */
Xextern bool xks; /* we are using X, not curses */
Xextern bool ptmessage; /* message window has pawntries */
Xextern u_char color; /* Who's turn it is */
Xextern u_char state; /* What state we're in */
Xextern u_char option [NOPTIONS]; /* options players must agree on*/
Xextern bool iamserver; /* am I the server player? */
Xextern FILE *inp, *out; /* socket for opponent */
Xextern int errno; /* system error numbers */
Xbool moving; /* piece being moved */
X
X#ifdef XKS
XWidget board, popup, dialog, form, text;
X/* Command widgets */
XWidget c_quit, c_resign, c_draw, c_yes, c_no, c_any, c_message;
X#define c_replay c_resign
X#define c_stop c_draw
X#define c_faster c_yes
X#define c_slower c_no
X/* Label widgets */
XWidget message_wins[];
X/* Input widget */
XWidget d_input;
XXtInputId sockid;
XFont font;
XPixmap pieces_masks[8];
XPixmap pieces_icons[8];
XGC gc;
XXtAppContext my_app;
X#else
Xextern char symbol [7]; /* symbols for printing pieces */
Xextern WINDOW *blanksq [89]; /* blank chessboard squares */
Xextern WINDOW *square [89]; /* contents of chessboard */
Xextern WINDOW *win [23]; /* message window areas */
Xextern WINDOW *backupscreen; /* used for redrawing vt220 */
Xextern WINDOW *blankscreen; /* used for redrawing vt220 */
Xextern char sqcolor [2]; /* character used for square */
Xextern bool vtterm; /* is this a vt220? */
Xextern bool dumbterm; /* are we dumb? */
Xextern bool reversescr; /* can terminal inverse video? */
Xextern int sqheight; /* height of a square */
Xextern int sqwidth; /* width of a square */
Xextern fd_set readset, writeset;
Xextern struct timeval *seltimeout;
Xextern unsigned int daemon_bits;
X#define D_MOVE 0x01
X#define D_ON 0x02
X#define D_ESC 0x04
X#define D_REPLAY 0x08
X#endif
*-*-END-of-externs.h-*-*
echo x - funcs.c
sed 's/^X//' >funcs.c <<'*-*-END-of-funcs.c-*-*'
X#ifndef lint
Xstatic char rcsid[] = "$Header: xinput.c,v 1.8 87/05/19 18:46:30 schoch Exp $";
X#endif
X
X#include "externs.h"
X#include <ctype.h>
X#include <strings.h>
X#include <sys/signal.h>
X
Xhandle_sock(sockp)
XFILE *sockp;
X{
X char instr[BUFSIZ];
X char *cp;
X int pstart, pend, i;
X
X if (fgets(instr, sizeof instr, sockp) == NULL) {
X message("Connection closed.", MESSAGE);
X dead = 1;
X state_change(state == PLAYING ? OVER : state);
X return 1;
X }
X if (cp = index(instr, '\n'))
X *cp = '\0';
X if (cp = index(instr, '\r'))
X *cp = '\0';
X i = parse_move(&pstart, &pend, theircolor, instr);
X if (i < 0) /* Message */
X return 0;
X if (i != TRUE)
X pstart = pend = 0;
X if (movetry(pstart, pend, theircolor) == 0) {
X mymove(!i);
X }
X return 0;
X}
X
X/*
X * take a line from the connection. Return:
X * TRUE: a valid (syntactically) move
X * FALSE: another operation (draw, resign, yes, no)
X * -1: no state change (say, invalid input)
X */
Xparse_move(pstart, pend, color, instr)
Xint *pstart, *pend;
Xu_char color;
Xchar *instr;
X{
X char buf[BUFSIZ];
X extern pawntries; /* in xmovetry.c */
X
X if (!strncmp (instr, "say", 3)) {
X sprintf(buf, "%s:%s", colorname[color], instr+3);
X message(buf, OPPONENT);
X Beep();
X#if OPPONENT == MESSAGE
X ptmessage = FALSE;
X#endif
X return -1;
X }
X if (state != PLAYING)
X return -1;
X if (!strcmp (instr, "draw")) {
X drawok [color] = TRUE;
X return FALSE;
X }
X if (!strcmp (instr, "resign")) {
X resign = TRUE;
X return FALSE;
X }
X if (drawok [1 - color]) {
X if (!strcmp (instr, "yes")) {
X drawok [color] = TRUE;
X } else if (!strcmp (instr, "no")) {
X ;
X } else {
X printf("error: should get yes or no.\n");
X return -1;
X }
X return FALSE;
X }
X if ((!option [ANNOUNCEPAWNS])
X && (!strcmp (instr, "any"))) {
X if (pawntries)
X message ("pawntries", PAWNTRIES);
X else
X message ("no pawntries", PAWNTRIES);
X return -1;
X }
X if (parse_algebraic_move(pstart,pend,instr) == TRUE)
X return TRUE;
X
X printf("Invalid input: %s\n", instr);
X return -1;
X}
X
X#define boardpos(col, row) ((9 - (row)) * 10 + (col))
X#define RIGHT_SIDE 2
X#define RIGHT_FILE 1
X
X/* parse an algebraic move (e2-e4), and return TRUE for non error */
Xparse_algebraic_move (pstart, pend, instr)
X int *pstart, *pend;
Xchar *instr;
X{
X
X if (instr[2] != '-')
X return FALSE;
X if (instr [0] >= 'a' && instr [0] <= 'h'
X && instr [1] >= '1' && instr [1] <= '8'
X && instr [3] >= 'a' && instr [3] <= 'h'
X && instr [4] >= '1' && instr [4] <= '8') {
X *pstart = boardpos (instr[0]-'a'+1, instr[1]-'0');
X *pend = boardpos (instr[3]-'a'+1, instr[4]-'0');
X return TRUE;
X } else
X return FALSE;
X}
X
Xdraw()
X{
X if (state != PLAYING) {
X message("You're not playing!", MESSAGE);
X return;
X }
X if (color != ourcolor) {
X message("Wait for your turn.", MESSAGE);
X return;
X }
X drawok[ourcolor] = TRUE;
X fputs("draw\r\n", out);
X movetry(0, 0, ourcolor);
X}
X
Xyes()
X{
X if (state != PLAYING) {
X message("You're not playing!", MESSAGE);
X return;
X }
X if (drawok[theircolor] != TRUE)
X return;
X drawok[ourcolor] = TRUE;
X fputs("yes\r\n", out);
X movetry(0, 0, ourcolor);
X}
X
Xno()
X{
X if (state != PLAYING) {
X message("You're not playing!", MESSAGE);
X return;
X }
X if (drawok[theircolor] != TRUE)
X return;
X drawok[ourcolor] = FALSE;
X fputs("no\r\n", out);
X movetry(0, 0, ourcolor);
X}
X
Xdo_resign()
X{
X droppiece();
X if (state != PLAYING) {
X message("The game is over!", MESSAGE);
X return;
X }
X fputs("resign\r\n", out);
X resign = TRUE;
X mclear(PAWNTRIES);
X mclear(LEGAL);
X movetry(0, 0, ourcolor);
X}
X
Xreplay()
X{
X if (state == PLAYING) {
X message("You're still playing!", MESSAGE);
X } else if (state == CONNECTING) {
X message("You haven't played yet!", MESSAGE);
X } else
X review();
X}
X
Xany()
X{
X if (state != PLAYING) {
X message("The game is over!", MESSAGE);
X return;
X }
X if (color != ourcolor) {
X message("It's not your turn.", MESSAGE);
X return;
X }
X if (option[ANNOUNCEPAWNS]) {
X message("The \"announce pawntries\" option is on!", MESSAGE);
X return;
X }
X if (pawntries)
X message ("pawntries", PAWNTRIES);
X else
X message ("no pawntries", PAWNTRIES);
X fputs("any\r\n", out);
X}
X
Xsend_message(buf)
Xchar *buf;
X{
X if (out == NULL) {
X message("You're not connected.", MESSAGE);
X return;
X }
X fprintf(out, "say %s\r\n", buf);
X}
*-*-END-of-funcs.c-*-*
echo x - icon.h
sed 's/^X//' >icon.h <<'*-*-END-of-icon.h-*-*'
X#define icon_width 64
X#define icon_height 64
Xstatic short icon_bits[] = {
X 0x0000, 0x0000, 0x0000, 0x0000,
X 0x2200, 0x0000, 0x0000, 0x0000,
X 0x1200, 0x0000, 0x0000, 0x0004,
X 0x0a00, 0x0010, 0x0400, 0x0004,
X 0x0600, 0x2103, 0x4066, 0x0004,
X 0x0a00, 0x5291, 0xa4a2, 0x0004,
X 0x1200, 0x5191, 0x6464, 0x0004,
X 0x2200, 0x6311, 0xc426, 0x0004,
X 0x0000, 0x2000, 0x0020, 0x0000,
X 0x0000, 0x1000, 0x0020, 0x0000,
X 0x0000, 0x0300, 0x0000, 0x0000,
X 0x0000, 0x0300, 0x0000, 0x0000,
X 0x0000, 0x0300, 0x0000, 0x0000,
X 0x0000, 0x0300, 0x0000, 0x0000,
X 0x0000, 0x3ff0, 0x0000, 0x0000,
X 0x0000, 0x3ff0, 0x0000, 0x0000,
X 0x0000, 0x0300, 0x0000, 0x0000,
X 0x0000, 0x0300, 0x0000, 0x0000,
X 0x8000, 0x0303, 0x0007, 0x0000,
X 0xe000, 0xe31f, 0x001f, 0x0000,
X 0xf800, 0xfb7f, 0x007f, 0x0000,
X 0xfc00, 0xffff, 0x00ff, 0x0000,
X 0xfe00, 0xffff, 0x01ff, 0x0000,
X 0xff00, 0xfcff, 0x03ff, 0x0000,
X 0xff00, 0xfcff, 0x03ff, 0x0000,
X 0xff80, 0xfcff, 0x07ff, 0x0000,
X 0xffc0, 0xfcff, 0x0fff, 0x0000,
X 0xffc0, 0xfcff, 0x0fff, 0x0000,
X 0xffc0, 0xfcff, 0x0fff, 0x0000,
X 0x7fc0, 0x7ff8, 0x0ff8, 0x0000,
X 0x7fc0, 0x3ff0, 0x0ff8, 0x0000,
X 0x3fc0, 0x3ff0, 0x1ff0, 0x0000,
X 0x1f80, 0x1fe0, 0x70e0, 0x0000,
X 0x1f80, 0x1fe0, 0xc030, 0x0000,
X 0x1f80, 0x1fe0, 0x8010, 0x0000,
X 0x1f00, 0x0fc0, 0x8018, 0x0001,
X 0x3f00, 0x0fc0, 0x0008, 0x0001,
X 0x3f00, 0x0fc0, 0x000c, 0x0003,
X 0x7e00, 0x0fc0, 0x000c, 0x0003,
X 0xfe00, 0xffff, 0x000f, 0x0001,
X 0xfc00, 0xffff, 0x801f, 0x0001,
X 0x0c00, 0x0000, 0x8010, 0x0000,
X 0x0c00, 0x0000, 0xc030, 0x0000,
X 0x0c00, 0x0303, 0x70e3, 0x0000,
X 0x0c00, 0x0303, 0x3fc3, 0x0000,
X 0x0c00, 0x0000, 0x2040, 0x0000,
X 0x0c00, 0x0000, 0x2040, 0x0000,
X 0xfc00, 0xffff, 0x607f, 0x0000,
X 0xfc00, 0xffff, 0x607f, 0x0000,
X 0x0000, 0x0000, 0x4020, 0x0000,
X 0x0000, 0x0000, 0x4020, 0x0000,
X 0x0000, 0x0000, 0xc030, 0x0000,
X 0x0000, 0x0000, 0x8010, 0x0000,
X 0x0000, 0x0000, 0x8010, 0x0000,
X 0x0000, 0x0000, 0x8010, 0x0000,
X 0x0000, 0x0000, 0x801c, 0x0003,
X 0x0000, 0x0000, 0x0007, 0x000e,
X 0x0000, 0xc000, 0x0001, 0x0038,
X 0x0000, 0x7000, 0x0000, 0x00e0,
X 0x0000, 0x1800, 0x0000, 0x0180,
X 0x0000, 0x1800, 0x0000, 0x0180,
X 0x0000, 0xf800, 0xffff, 0x01ff,
X 0x0000, 0xf800, 0xffff, 0x01ff,
X 0x0000, 0x0000, 0x0000, 0x0000};
*-*-END-of-icon.h-*-*
exit
--
Dan Heller
------------------------------------------------
O'Reilly && Associates Zyrcom Inc
Senior Writer President
argv at ora.com argv at zipcode.com
More information about the Comp.sources.x
mailing list