[comp.sources.games] v11i052: reve - an othello game, Part01/07

billr@saab.CNA.TEK.COM (Bill Randle) (11/02/90)

Submitted-by: Rich Burridge <rburridge@sun.COM>
Posting-number: Volume 11, Issue 52
Archive-name: reve/Part01
Environment: SunView, XView, X11, termcap

	[Starting with this posting I have added a new archive header
	 line: "Environment: " which is a comma separated list of
	 keywords describing some of the environment requirements
	 (where known). -br]

[[from the author...
This is version 1.1 of Reve (an othello game). This version works under
SunView, XView, X11 and on dumb tty terminals.

See the manual pages for a detailed description of the rules of Othello.

Reve has nine levels of difficulty. Levels 1-3 should be useful to beginners,
levels 4-6 would satisfy amateurs, and the higher levels will give experts a
good game. Level 8 (30 minutes) is the tournament level.

Reve is being released to comp.sources.games now, because Yves Gallot will
be leaving his current job in December, and is moving to a new location in
France, which won't be quite so well connected to the net. We want to get
as much feedback as possible before then.

See the TODO file for a list of features and enhancements that haven't been
implemented yet, plus a list of the known bugs.

Permission is given to distribute these sources, as long as the
introductory messages are not removed, and no monies are exchanged.

You are forbidden from using Reve as is, or in a modified state, in
any tournaments, without the permission of the authors.

We are intending to entry Reve in the University of Waterloo Computer
Science Club Seventh Annual Computer Othello Tournament in November.

With this program, rather then generate a plethora of patches when bugs
are found, I'll generate one official patch per month. Each week, I will
post to comp.sources.games.bugs a list of bugs found, and enhancements
added since the last patch (just in case you are experiencing the same
problem).

Suggestions for furthur improvement would be most welcome, plus bugs,
comments and flames.

Rich Burridge           richb@Aus.Sun.COM
Yves Gallot             galloty@cernvax.cern.ch
]]

#! /bin/sh
# This is a shell archive.  Remove anything before this line, then unpack
# it by saving it into a file and typing "sh file".  To overwrite existing
# files, type "sh file -c".  You can also feed this as standard input via
# unshar, or by typing "sh <file", e.g..  If this archive is complete, you
# will see the following message at the end:
#		"End of archive 1 (of 7)."
# Contents:  README MANIFEST extern.h images images/button.stencil.icon
#   main.c xview.c
# Wrapped by billr@saab on Thu Nov  1 14:02:48 1990
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f 'README' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'README'\"
else
echo shar: Extracting \"'README'\" \(9021 characters\)
sed "s/^X//" >'README' <<'END_OF_FILE'
X
X/*  @(#)README 1.8 90/10/20
X *
X *  Copyright (C) 1990 - Rich Burridge & Yves Gallot.
X *  All rights reserved.
X *
X *  Permission is given to distribute these sources, as long as the
X *  introductory messages are not removed, and no monies are exchanged.
X *
X *  You are forbidden from using Reve as is, or in a modified state, in
X *  any tournaments, without the permission of the authors.
X *
X *  No responsibility is taken for any errors on inaccuracies inherent
X *  either to the comments or the code of this program, but if reported
X *  (see README file), then an attempt will be made to fix them.
X */
X
XReve  -  README  -  October 1990.
X
X-----------------------------------------------------------------------
XCONTENTS:
X
X1. What is Reve?
X2. Getting started.
X3. Strategy used by Reve.
X4. Acknowledgements.
X-----------------------------------------------------------------------
X
X1. What is Reve?
X----------------
X
XThis is version 1.1 of Reve (an othello game). This version works under
XSunView, XView, X11 and on dumb tty terminals.
X
XSee the manual pages for a detailed description of the rules of Othello.
X
XReve has nine levels of difficulty. Levels 1-3 should be useful to beginners,
Xlevels 4-6 would satisfy amateurs, and the higher levels will give experts a
Xgood game. Level 8 (30 minutes) is the tournament level.
X
X2. Getting started.
X-------------------
X
XInitially there is no Makefile file present in the reve source directory.
XYou will need to copy Makefile.dist to Makefile, then adjust accordingly.
X
XYou need to specify one of the following four options to compile reve:
X
X 1/     make sunview      - to make the SunView version.
X 2/     make tty          - to make the dumb tty version.
X 3/     make x11          - to make the X11 version.
X 4/     make xview        - to make the XView version.
X
XThis should then be followed by a "make install". You might need super-user
Xpermission to do this successfully. The "make install" will concatenate the
Xtwo halves of the Reve edge stability table together, before installing them.
X
XThe manual pages describe the rules of Reve in detail.
X
XThe Makefile compilation details are setup to default to compiling the
XSunView version of reve on a Sun4 running SunOS v4.1. Note that there are
Xvarious compilation definitions that might need uncommenting if you are
Xtrying to compile and run it on any other machine or graphics environment
Xor operating system.
X
XThese are:
X 
XEDGENAMEFILE - alternate location for the Reve edge table.
XEDGENAME     - alternate location for the Reve edge table.
XNOINDEX      - uncomment if you don't have the index() function.
XNOSELECT     - uncomment if your machine doesn't have the select() call.
XNO_USLEEP    - uncomment if you don't have the usleep(3) call.
XSELTYPE      - uncomment for old select(2) calls.
XSIGRET       - uncomment if your signal function expects an integer function.
XSYSV         - uncomment if you are running Unix System V.
XX11INCDIR    - X11 only: location of the X11 #include files.
XX11LIBDIR    - X11 only: location of the X11 libraries.
XXVIEWINCDIR  - XView only: location of the XView #include files.
XXVIEWLIBDIR  - XView only: location of the XView libraries.
X
XSee the Makefile for a detailed description of each of these definitions.
X 
XIf you need to make other changes in order to get reve to compile and run
Xon your system, please let us know the details (see email addresses below),
Xand we will try to include them into a future version.
X
XSee the TODO file for the list of known problems and ideas for future
Xenhancements.
X
X3. Strategy used by Reve.
X-------------------------
X
XReve is a "classical Othello program", using state of the art othello
Xstrategy. It does not include Bayesian learning [Bill, 1989].
X
XReferences : "A World-Championship-Level Othello Program", Paul S.Rosenbloom,
X             Artificial Intelligence 19(1982), 279-320.
X             "The Development of a World Class Othello Program", Kai-Fu Lee
X             and Sanjoy Mahajan, Art. Int. 43(1990) 21-36.
X
X
XHere is a listing of a high level Reve vs Reve match.
X
X                Reve vs Reve example.
X
X      nt : note Reve gives to the position.
X      profmax : Depth Reve looks forward.
X      nbtotnodes : Accumulated number of final nodes evaluated.
X
X 1, <C-4>, nt : 0,        profmax : 1,  nbtotnodes : 0
X 2, <E-3>, nt : 5107,     profmax : 9,  nbtotnodes : 168236
X 3, <F-4>, nt : 31284,    profmax : 9,  nbtotnodes : 459892
X 4, <C-5>, nt : 7392,     profmax : 9,  nbtotnodes : 692337
X 5, <D-6>, nt : -7392,    profmax : 8,  nbtotnodes : 843560
X 6, <C-3>, nt : -29267,   profmax : 8,  nbtotnodes : 1305926
X 7, <C-6>, nt : 8574,     profmax : 8,  nbtotnodes : 1461111
X 8, <F-5>, nt : -38130,   profmax : 8,  nbtotnodes : 1630589
X 9, <E-6>, nt : 7020,     profmax : 8,  nbtotnodes : 1882791
X10, <D-3>, nt : -36894,   profmax : 8,  nbtotnodes : 2136012
X11, <F-3>, nt : 4819,     profmax : 8,  nbtotnodes : 2684014
X12, <F-6>, nt : -4819,    profmax : 7,  nbtotnodes : 3331165
X13, <E-2>, nt : 34302,    profmax : 7,  nbtotnodes : 3539609
X14, <G-4>, nt : -5858,    profmax : 7,  nbtotnodes : 4229607
X15, <G-3>, nt : 5858,     profmax : 6,  nbtotnodes : 4390818
X16, <E-1>, nt : -11790,   profmax : 7,  nbtotnodes : 5137455
X17, <D-2>, nt : 11790,    profmax : 6,  nbtotnodes : 5418077
X18, <F-2>, nt : -46674,   profmax : 6,  nbtotnodes : 5570855
X19, <F-1>, nt : 15648,    profmax : 6,  nbtotnodes : 5766803
X20, <C-1>, nt : -15648,   profmax : 5,  nbtotnodes : 5825491
X21, <D-1>, nt : 52994,    profmax : 7,  nbtotnodes : 6365630
X22, <G-1>, nt : -52994,   profmax : 6,  nbtotnodes : 6556423
X23, <H-5>, nt : 5229,     profmax : 6,  nbtotnodes : 6656104
X24, <H-4>, nt : -3054,    profmax : 7,  nbtotnodes : 7221420
X25, <G-5>, nt : 3054,     profmax : 6,  nbtotnodes : 7313040
X26, <H-6>, nt : -845,     profmax : 7,  nbtotnodes : 7615130
X27, <H-3>, nt : 26592,    profmax : 7,  nbtotnodes : 8026020
X28, <C-2>, nt : -26592,   profmax : 6,  nbtotnodes : 8123951
X29, <H-7>, nt : 5691,     profmax : 6,  nbtotnodes : 8226483
X30, <G-6>, nt : -13265,   profmax : 7,  nbtotnodes : 8301302
X31, <E-7>, nt : 21196,    profmax : 7,  nbtotnodes : 8498532
X32, <D-7>, nt : -19960,   profmax : 7,  nbtotnodes : 8700743
X33, <C-8>, nt : 30104,    profmax : 8,  nbtotnodes : 9672532
X34, <E-8>, nt : -30104,   profmax : 7,  nbtotnodes : 9953691
X35, <D-8>, nt : 63346,    profmax : 8,  nbtotnodes : 10817345
X36, <B-8>, nt : -63346,   profmax : 7,  nbtotnodes : 11038102
X37, <F-7>, nt : 50472,    profmax : 8,  nbtotnodes : 11346042
X38, <C-7>, nt : -11415,   profmax : 8,  nbtotnodes : 11495189
X39, <B-6>, nt : 61958,    profmax : 8,  nbtotnodes : 11783153
X40, <A-5>, nt : 3313,     profmax : 8,  nbtotnodes : 12069521
X41, <B-3>, nt : -585518,  profmax : 9,  nbtotnodes : 12484782
X42, <B-5>, nt : -50483,   profmax : 9,  nbtotnodes : 12680889
X43, <A-6>, nt : -1469439, profmax : 9,  nbtotnodes : 12791711
X44, <A-4>, nt : 2250360,  profmax : 10, nbtotnodes : 13053695
X45, <B-4>, nt : 3,        profmax : 16, nbtotnodes : 13217789
X46, <F-8>, nt : -3,       profmax : 15, nbtotnodes : 13408870
X47, <B-2>, nt : 3,        profmax : 14, nbtotnodes : 13471036
X48, <A-7>, nt : -3,       profmax : 13, nbtotnodes : 13492740
X49, <G-7>, nt : 3,        profmax : 12, nbtotnodes : 13500234
X50, <B-7>, nt : -3,       profmax : 11, nbtotnodes : 13503151
X51, <B-1>, nt : 3,        profmax : 10, nbtotnodes : 13503785
X52, <A-1>, nt : -3,       profmax : 9,  nbtotnodes : 13504016
X53, <A-8>, nt : 3,        profmax : 8,  nbtotnodes : 13504094
X54, <A-2>, nt : -3,       profmax : 7,  nbtotnodes : 13504146
X55, <A-3>, nt : 3,        profmax : 6,  nbtotnodes : 13504159
X56, <H-8>, nt : -3,       profmax : 5,  nbtotnodes : 13504167
X57, <G-8>, nt : 3,        profmax : 4,  nbtotnodes : 13504171
X58, <H-2>, nt : 0,        profmax : 1,  nbtotnodes : 13504171
X59, <G-2>, nt : 0,        profmax : 1,  nbtotnodes : 13504171
X
X
X4. Acknowledgements.
X--------------------
X
XThe previous version of this program was posted to comp.sources.games
Xunder the name othello2. That version was a rework of the SunView
Xgraphics front-end from Ed Falk, Sun Microsystems, CA. It contained
Xcomputer strategy and remarks code from Chris Miller.
X
XThe graphics code was abstracted, and graphics drivers were added for
XX11 (Xlib), the XView toolkit, and a dumb tty version.
X
XThis version has virtually the same graphical interface. The remarks code
Xhas been removed, and the computer strategy is written by Yves Gallot,
Xfrom CERN in Geneva.
X
XThanks go to Valerie Haecky, Daniel Yang, Eric R. Jorgensen, John Rosauer,
XSteve Misrack, Hugues Leroy, Linton Miller, Mike Stump, D. Hugh Redelmeier,
XScott W. Danielson, Gary D. Kline, Kjetil Torgrim Homme, Peter Johansson,
XAlfred Nathaniel, Arnold Gill, Martin Chudley, W Mat Waites, Keith Moore,
XJohn Eras and Heather Rose for bug reports and/or bug fixes plus suggested
Xenhancements.
X
XSuggestions for furthur improvement would be most welcome, plus bugs,
Xcomments and flames.
X
XRich Burridge           richb@Aus.Sun.COM
XYves Gallot             galloty@cernvax.cern.ch
END_OF_FILE
if test 9021 -ne `wc -c <'README'`; then
    echo shar: \"'README'\" unpacked with wrong size!
fi
# end of 'README'
fi
if test -f 'MANIFEST' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'MANIFEST'\"
else
echo shar: Extracting \"'MANIFEST'\" \(1417 characters\)
sed "s/^X//" >'MANIFEST' <<'END_OF_FILE'
X   File Name		Archive #	Description
X-----------------------------------------------------------
X CHANGES                    6	
X FILES                      5	
X MANIFEST                   1	This shipping list
X Makefile.dist              6	
X README                     1	
X TODO                       7	
X boardstuff.c               5	
X color.h                    5	
X events.c                   5	
X extern.h                   1	
X images                     1	
X images.h                   6	
X images/black.icon          7	
X images/button.invert.icon  7	
X images/button.normal.icon  5	
X images/button.stencil.icon  1	
X images/cycle.glyph.icon    7	
X images/cycle.linvert.icon  7	
X images/cycle.rinvert.icon  7	
X images/cycle.stencil.icon  7	
X images/hglass.cursor       7	
X images/nocur.cursor        7	
X images/reve.color.icon     4	
X images/reve.icon           7	
X images/white.icon          7	
X items.c                    7	
X main.c                     1	
X makemove.c                 4	
X patchlevel.h               4	
X procs.c                    7	
X rev_eval.c                 6	
X rev_ip.c                   7	
X rev_iycp.c                 5	
X reve.6                     6	
X reve.edge1                 3	
X reve.edge2                 2	
X reve.h                     6	
X reve.man                   6	
X sunview.c                  5	
X tty.c                      4	
X x11.c                      4	
X xview.c                    1	
END_OF_FILE
if test 1417 -ne `wc -c <'MANIFEST'`; then
    echo shar: \"'MANIFEST'\" unpacked with wrong size!
fi
# end of 'MANIFEST'
fi
if test -f 'extern.h' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'extern.h'\"
else
echo shar: Extracting \"'extern.h'\" \(4678 characters\)
sed "s/^X//" >'extern.h' <<'END_OF_FILE'
X
X/*  @(#)extern.h 1.7 90/10/18
X *
X *  Contains the external variable definitions used by reve.
X *
X *  Copyright (C) 1990 - Rich Burridge & Yves Gallot.
X *  All rights reserved.
X *
X *  Permission is given to distribute these sources, as long as the
X *  introductory messages are not removed, and no monies are exchanged.
X *
X *  You are forbidden from using Reve as is, or in a modified state, in
X *  any tournaments, without the permission of the authors.
X *
X *  No responsibility is taken for any errors on inaccuracies inherent
X *  either to the comments or the code of this program, but if reported
X *  (see README file), then an attempt will be made to fix them.
X */
X
Xextern int bfont_height ;  /* Height in pixels for bold font. */
Xextern int but_inverted ;  /* Value of panel item inverted. */
Xextern int color ;         /* Current color value. */
Xextern int cur_ch ;        /* Current character pressed. */
Xextern int curx ;          /* Current mouse X position. */
Xextern int cury ;          /* Current mouse Y position. */
Xextern int depth ;         /* Depth of search for computers move. */
Xextern int down ;          /* Indicates is a mouse button is down. */
Xextern int first_move ;    /* Set if computer plays first move. */
Xextern int iconic ;        /* Start as an icon if set. */
Xextern int inv_video ;     /* Set if displaying in inverse video. */
Xextern int iscolor[] ;     /* Set if this is a color screen. */
Xextern int itemno ;        /* Current panel item being processed. */
Xextern int item_value ;    /* Value for current panel item. */
Xextern int ix ;            /* Initial X position of the icon. */
Xextern int iy ;            /* Initial Y position of the icon. */
Xextern int last_move ;     /* Last valid computer move. */
Xextern int loadgame ;      /* Set if there is a game file to load. */
Xextern int lsval ;         /* Set to 'l' or 's', if loading or saving. */
Xextern int move ;          /* Current move being evaluated. */
Xextern int move_delta ;    /* Delta for piece animation. */
Xextern int nextc ;         /* Current event identifier. */
Xextern int next_player ;   /* Next player (BLACK or WHITE) to move. */
Xextern int nfont_height ;  /* Height in pixels for normal font. */
Xextern int piece_x ;       /* Current X position of moving piece. */
Xextern int piece_y ;       /* Current Y position of moving piece */
Xextern int play_computer ; /* Set if playing against the computer. */
Xextern int posspec ;       /* Set if -Wp or -g option is present (for X11) */
Xextern int s_flip ;
Xextern int s_move ;
Xextern int s_opponent ;
Xextern int s_player ;
Xextern int s_row ;
Xextern int s_col ;
Xextern int show_notes ;    /* If set, display notes value from play_reve. */
Xextern int suggestion ;    /* Positive if a suggested move. */
Xextern int suggest_x ;     /* X position of suggested move. */
Xextern int suggest_y ;     /* Y position of suggested move. */
Xextern int tinput  ;       /* Set, when getting text input for load/save. */
Xextern int tx, ty ;        /* Position of text field. */
Xextern int tw, th ;        /* Size of text field. */
Xextern int validkey ;      /* Set if half way though a valid multiple key. */
Xextern int wx ;            /* Initial X position of the window. */
Xextern int wy ;            /* Initial Y position of the window. */ 
X
Xextern long note ;         /* Note value for current computer move. */
X
Xextern char *diff_values[] ;     /* Values for cyclic difficulty button. */
Xextern char *comp_values[] ;     /* Values for computer plays button. */
Xextern char gamefile[] ;         /* Name of file for load/save. */
Xextern char geometry[MAXDPY][MAXLINE] ;   /* X11 geometry information. */
Xextern char line[] ;
Xextern char *notes_values[] ;    /* Values for cyclic notes item. */
Xextern char *player_values[] ;   /* Values for cyclic black/white item. */
Xextern char progname[] ;         /* The name of this program. */
Xextern char revtable[] ;         /* Table for reversing bits in a byte. */
X
Xextern char black_dpy[] ;        /* Black piece display information. */
Xextern char white_dpy[] ;        /* White piece display information. */
X
Xextern FILE *rem_fp ;
Xextern struct timeval tp ;        /* Used by the nap_upto routine. */
X
Xextern struct iteminfo items[] ;  /* Information records for button items. */
X
Xextern BOARD board ;              /* The current reve board. */
Xextern BOARD old_board ;          /* The previous reve board. */
Xextern BOARD *s_pos ;
Xextern BOARD moves[64] ;          /* Complete array of board moves. */
X
Xextern enum cantype cmode, last_cmode ;
Xextern enum disp_type dtype ;
Xextern enum dpy_type cur_dpyno ;
Xextern enum set_type direction ;  /* Incremental direction for cycle item. */
END_OF_FILE
if test 4678 -ne `wc -c <'extern.h'`; then
    echo shar: \"'extern.h'\" unpacked with wrong size!
fi
# end of 'extern.h'
fi
if test ! -d 'images' ; then
    echo shar: Creating directory \"'images'\"
    mkdir 'images'
fi
if test -f 'images/button.stencil.icon' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'images/button.stencil.icon'\"
else
echo shar: Extracting \"'images/button.stencil.icon'\" \(1933 characters\)
sed "s/^X//" >'images/button.stencil.icon' <<'END_OF_FILE'
X/* Format_version=1, Width=64, Height=64, Depth=1, Valid_bits_per_item=16
X */
X	0x03FF,0xFFFF,0xFFFF,0xFFC0,0x0FFF,0xFFFF,0xFFFF,0xFFF0,
X	0x1FFF,0xFFFF,0xFFFF,0xFFF8,0x3FFF,0xFFFF,0xFFFF,0xFFFC,
X	0x7FFF,0xFFFF,0xFFFF,0xFFFE,0x7FFF,0xFFFF,0xFFFF,0xFFFE,
X	0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,
X	0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,
X	0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,
X	0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,
X	0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,
X	0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,
X	0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,
X	0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,
X	0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,
X	0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,
X	0x7FFF,0xFFFF,0xFFFF,0xFFFE,0x7FFF,0xFFFF,0xFFFF,0xFFFE,
X	0x3FFF,0xFFFF,0xFFFF,0xFFFC,0x1FFF,0xFFFF,0xFFFF,0xFFF8,
X	0x0FFF,0xFFFF,0xFFFF,0xFFF0,0x03FF,0xFFFF,0xFFFF,0xFFC0,
X	0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
X	0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
X	0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
X	0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
X	0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
X	0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
X	0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
X	0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
X	0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
X	0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
X	0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
X	0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
X	0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
X	0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
X	0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
X	0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000
END_OF_FILE
if test 1933 -ne `wc -c <'images/button.stencil.icon'`; then
    echo shar: \"'images/button.stencil.icon'\" unpacked with wrong size!
fi
# end of 'images/button.stencil.icon'
fi
if test -f 'main.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'main.c'\"
else
echo shar: Extracting \"'main.c'\" \(22172 characters\)
sed "s/^X//" >'main.c' <<'END_OF_FILE'
X
X/*  @(#)main.c 1.9 90/10/20
X *
X *  Main routine for the reve program.
X *
X *  Copyright (C) 1990 - Rich Burridge & Yves Gallot.
X *  All rights reserved.
X *
X *  Permission is given to distribute these sources, as long as the
X *  introductory messages are not removed, and no monies are exchanged.
X *
X *  You are forbidden from using Reve as is, or in a modified state, in
X *  any tournaments, without the permission of the authors.
X *
X *  No responsibility is taken for any errors on inaccuracies inherent
X *  either to the comments or the code of this program, but if reported
X *  (see README file), then an attempt will be made to fix them.
X */
X
X#include <stdio.h>
X#include <strings.h>
X#include <sys/time.h>
X#include "color.h"
X#include "reve.h"
X#include "patchlevel.h"
X
X/* Text values for the cyclic buttons. */
Xchar *diff_values[] = { "1", "2", "3", "4", "5", "6", "7", "8", "9", NULL } ;
Xchar *notes_values[] = { "off", "on", NULL } ;
Xchar *player_values[] = { "human", "computer", NULL } ;
X
Xenum cantype cmode, last_cmode ;
Xenum disp_type dtype ;
Xenum dpy_type cur_dpyno ;
Xenum set_type direction ;   /* Incremental direction for cycle item. */
X
Xint tx, ty, tw, th ;    /* Position and size of text field. */
X
Xint piece_x ;           /* Current X position of moving piece. */
Xint piece_y ;           /* Current Y position of moving piece */
X
Xint bfont_height ;      /* Height in pixels for bold font. */
Xint but_inverted ;      /* Value of panel item inverted. */
Xint color ;             /* Current color value. */
Xint cur_ch ;            /* Current character pressed. */
Xint curx ;              /* Current mouse X position. */
Xint cury ;              /* Current mouse Y position. */
Xint depth ;             /* Depth of search for computers move. */
Xint down ;              /* Indicates is a mouse button is down. */
Xint first_move = 0 ;    /* Set if computer plays first move. */
Xint iconic ;            /* Set if window is currently iconic. */
Xint inv_video = 0 ;     /* Set if displaying in inverse video. */
Xint isblack ;           /* Set if human to play the black pieces. */
Xint iscolor[MAXDPY] ;   /* Set if this is a color screen. */
Xint iswhite ;           /* Set if human to play the white pieces. */
Xint itemno ;            /* Current panel item being processed. */
Xint item_value ;        /* Value for current panel item. */
Xint ix ;                /* Initial X position of the icon. */
Xint iy ;                /* Initial Y position of the icon. */
Xint last_move ;         /* Last valid computer move. */
Xint loadgame = 0 ;      /* Set if there is a game file to load. */
Xint lsval = 0 ;         /* Set to 'l' or 's', if loading or saving. */
Xint move ;              /* Current move being evaluated. */
Xint move_delta ;        /* Delta for piece animation. */
Xint nextc ;             /* Current event identifier. */
Xint next_player ;       /* Next player (BLACK or WHITE) to move. */
Xint nfont_height ;      /* Height in pixels for normal font. */
Xint play_computer ;     /* Set if playing against the computer. */
Xint posspec ;           /* Set if -Wp or -g option is present (for X11) */
Xint show_notes ;        /* If set, display notes value from play_reve. */
Xint suggestion = -1 ;   /* Positive if a suggested move. */
Xint suggest_x ;         /* X position of suggested move. */
Xint suggest_y ;         /* Y position of suggested move. */
Xint tinput = 0 ;        /* Set, when getting text input for load/save. */
Xint validkey ;          /* Set if half way though a valid multiple key. */
Xint wx ;                /* Initial X position of the window. */
Xint wy ;                /* Initial Y position of the window. */
X
X/*  Globals for passing arguments to "sandwich";
X *  this is to save time putting arguments on and off the
X *  stack in a very heavily used piece of code
X */
X
Xint s_flip ;
Xint s_move ;
Xint s_opponent ;
Xint s_player ;
Xint s_row ;
Xint s_col ;
X
Xstruct timeval tp ;        /* Used by the nap_upto routine. */
X
XBOARD old_board ;          /* The previous reve board. */
XBOARD board ;              /* The current reve board. */
XBOARD *s_pos ;
X
XBOARD moves[64] ;          /* Complete array of board moves. */
X
Xstruct iteminfo items[MAXITEMS] = {                     /* Panel items. */
X
X/*   type   x   y   width   height   text   value   function */
X
X{ P_BUTTON,  BBORDER + (0*(BWIDTH+BGAP)), BBORDER + (0*(BHEIGHT+BGAP)),
X             BWIDTH, BHEIGHT, "last",     0, last },
X
X{ P_BUTTON,  BBORDER + (1*(BWIDTH+BGAP)), BBORDER + (0*(BHEIGHT+BGAP)),
X             BWIDTH, BHEIGHT, "load",     0, draw_textfield },
X
X{ P_BUTTON,  BBORDER + (2*(BWIDTH+BGAP)), BBORDER + (0*(BHEIGHT+BGAP)),
X             BWIDTH, BHEIGHT, "new game", 0, new_game },
X
X{ P_BUTTON,  BBORDER + (3*(BWIDTH+BGAP)), BBORDER + (0*(BHEIGHT+BGAP)),
X             BWIDTH, BHEIGHT, "save",     0, draw_textfield },
X
X{ P_BUTTON,  BBORDER + (4*(BWIDTH+BGAP)), BBORDER + (0*(BHEIGHT+BGAP)),
X             BWIDTH, BHEIGHT, "suggest",  0, suggest },
X
X{ P_BUTTON,  BBORDER + (5*(BWIDTH+BGAP)), BBORDER + (0*(BHEIGHT+BGAP)),
X             BWIDTH, BHEIGHT, "undo",     0, undo },
X
X{ P_BUTTON,  BBORDER + (0*(BWIDTH+BGAP)), BBORDER + (1*(BHEIGHT+BGAP)),
X             BWIDTH, BHEIGHT, "done",     0, done },
X
X{ P_BUTTON,  -1,                          -1,   /* Not normally active. */
X             BWIDTH, BHEIGHT, "cancel",  0, remove_textfield },
X
X{ P_BUTTON,  BBORDER + (5*(BWIDTH+BGAP)), BBORDER + (1*(BHEIGHT+BGAP)),
X             BWIDTH, BHEIGHT, "quit",     0, quit },
X
X{ P_CYCLE,   BBORDER + (0*(BWIDTH+BGAP)), BBORDER + (2*(BHEIGHT+BGAP)),
X             CWIDTH, CHEIGHT, "Black:", 0, init_player },
X
X{ P_CYCLE,   BBORDER + (3*(BWIDTH+BGAP)), BBORDER + (2*(BHEIGHT+BGAP)),
X             CWIDTH, CHEIGHT, "White:", 1, init_player },
X
X{ P_CYCLE,   BBORDER + (0*(BWIDTH+BGAP)), BBORDER + (3*(BHEIGHT+BGAP)),
X             CWIDTH, CHEIGHT, "Difficulty:", INIT_DEPTH, difficulty },
X
X{ P_CYCLE,   BBORDER + (3*(BWIDTH+BGAP)), BBORDER + (3*(BHEIGHT+BGAP)),
X             CWIDTH, CHEIGHT, "Notes:",      FALSE,      init_notes },
X
X{ P_MESSAGE, BBORDER + (0*(BWIDTH+BGAP)), BBORDER + (4*(BHEIGHT+BGAP)),
X             0, 0, "Use left mouse button to move", 0, NULL },
X
X{ P_MESSAGE, BBORDER + (3*(BWIDTH+BGAP)), BBORDER + (4*(BHEIGHT+BGAP)),
X             0, 0, "",                                   0, NULL },
X
X{ P_MESSAGE, BBORDER + (0*(BWIDTH+BGAP)), BBORDER + (5*(BHEIGHT+BGAP)),
X             0, 0, "White:  2, Black:  2",               0, NULL },
X
X{ P_MESSAGE, BBORDER + (3*(BWIDTH+BGAP)), BBORDER + (5*(BHEIGHT+BGAP)),
X             0, 0, "",                                   0, NULL },
X} ;
X
Xchar geometry[MAXDPY][MAXLINE] ;       /* X11 geometry information. */
X
Xchar *black_dpy ;              /* Black piece display information. */
Xchar edgefile[MAXLINE] ;       /* Location of the reve edge table file. */
Xchar gamefile[MAXLINE] ;       /* Name of file for load/save. */
Xchar line[40] ;
Xchar progname[MAXLINE] ;       /* The name of this program. */
Xchar *white_dpy ;              /* White piece display information. */
X
X/* REVE global variables */
X
Xint damier[NIVEAUMAX][64] ;  /* Boards at different depth level */
Xint tacouleur, macouleur ;   /* Your and my colors during evaluation */
Xint mnb, profmax ;           /* Number of moves played, current max. depth */
Xint vp0, vo0 ;               /* Current mobility components */
Xlong c1, c2, c3 ;            /* Constants used in evaluation function */
Xlong edges[6561] ;           /* Edges Stability Table */
Xlong note ;                  /* Note value for current computer move. */
X
Xextern enum gr_type gtype ;                     /* Graphics type. */ 
X
X
Xmain(argc, argv)
Xint argc ;
Xchar *argv[] ;
X{
X  STRCPY(progname, argv[0]) ;   /* Save program name for later use. */
X  STRCPY(gamefile, "reve.game") ;
X  SPRINTF(line, " Reve.  V1.1.%1d", PATCHLEVEL) ;
X  initialise() ;                /* Initialise variables used by reve. */
X  get_options(argc, argv) ;     /* Read command line options. */
X  init_edge_table(edgefile) ;   /* Load reve edge table values. */
X  set_display_types() ;         /* Work out what displays to initialise. */
X  if (init_ws_type())           /* Determine window system type. */
X    {
X      FPRINTF(stderr,"Error initialising window system.\n") ;
X      exit(1) ;
X    }
X  make_icon() ;
X  make_frame(argc, argv) ;      /* Create reve window/icon. */
X  make_canvas() ;               /* Create drawing canvas. */
X  init_fonts() ;                /* Load normal and bold fonts. */
X  create_menu(BLACK_PLAYS, player_values) ;
X  create_menu(WHITE_PLAYS, player_values) ;
X  create_menu(DIFFICULTY,  diff_values) ;
X  create_menu(NOTES,       notes_values) ;
X  initboard() ;
X  set_cursor(CANVASCUR) ;
X  start_tool(dtype) ;           /* Event handling loop. */
X  exit(0) ;
X/*NOTREACHED*/
X}
X
X
Xvoid
Xget_options(argc, argv)   /* Read and process command line options. */
Xint argc ;
Xchar *argv[] ;
X{
X  char next[MAXLINE] ;    /* The next command line parameter. */
X
X  INC ;
X  while (argc > 0)
X    {
X      if (argv[0][0] == '-')
X        switch (argv[0][1])
X          {
X            case 'b' : isblack = 1 ;
X                       if (*argv != NULL && argv[0][0] != '-')
X                         {
X                           INC ;
X                           black_dpy = *argv ;
X                         }
X                       break ;
X            case 'c' : play_computer = 1 ;    /* Play against the computer. */
X                       break ;
X            case 'd' : INC ;
X                       getparam(next, argv, "-d needs difficulty") ;
X                       depth = atoi(next) ;
X                       if (depth < 1 || depth > MAXDIFF) depth = INIT_DEPTH ;
X                       items[(int) DIFFICULTY].value = depth - 1 ;
X                       break ;
X            case 'e' : INC ;
X                       getparam(edgefile, argv, "-e needs an edgetable file") ;
X                       break ;
X            case 'g' : INC ;                 /* X11 geometry information. */
X                       getparam(geometry[0], argv,
X                                "-g needs geometry information") ;
X                       break ;
X            case 'i' : inv_video = 1 ;       /* Display in inverse video. */
X                       break ;
X            case 'l' : INC ;                 /* Reve game file to load. */
X                       getparam(gamefile, argv, "-l needs a game file") ;
X                       loadgame = 1 ;        /* Game file to load. */
X                       break ;
X            case 'n' : show_notes = 1 ;      /* Display computer notes. */
X                       items[(int) NOTES].value = 1 ;
X                       break ;
X            case '?' :
X            case 'v' : usage() ;
X
X            case 'w' : iswhite = 1 ;
X                       if (*argv != NULL && argv[0][0] != '-')
X                         {
X                           INC ;
X                           white_dpy = *argv ;
X                         }
X                       break ;
X
X/*  SunView windowing arguments. -Wp, -WP and -Wi are used in the X11
X *  implementation to initially position the window and icon.
X */          
X             
X            case 'W' : switch (argv[0][2])
X                         {
X                           case 'H' : break ;   /* -WH, no sub-args follow */
X                           case 'i' : iconic = 1 ;
X                                      break ;   /* -Wi, start as an icon. */
X                           case 'g' :           /* -Wg, set default color. */
X                           case 'n' : break ;   /* -Wn, no label at all */
X                           case 'h' :           /* -Wh, height */
X                           case 'I' :           /* -WI "icon filename" */
X                           case 'l' :           /* -Wl "some window label" */
X                           case 'L' :           /* -Wl "some icon label" */
X                           case 't' :           /* Font filename */
X                           case 'T' :           /* Icon font filename */
X                           case 'w' : INC ;     /* Width, in columns. */
X                                      break ;
X                           case 'p' : INC ;     /* -Wp xnum ynum */
X                                      getparam(next, argv,
X                                               "-Wp needs x coordinate") ;
X                                      wx = atoi(next) ;
X                                      INC ;
X                                      getparam(next, argv,
X                                               "-Wp needs y coordinate") ;
X                                      wy = atoi(next) ;
X                                      posspec = 1 ;
X                                      break ;
X                           case 'P' : INC ;      /* -WP xnum ynum */
X                                      getparam(next, argv,
X                                               "-WP needs x coordinate") ;
X                                      ix = atoi(next) ;
X                                      INC ;
X                                      getparam(next, argv,
X                                               "-WP needs y coordinate") ;
X                                      iy = atoi(next) ;
X                                      break ;
X                           case 's' : INC ; INC ;  /* -Ws xnum ynum */
X                                      break ;
X                           case 'b' :              /* -Wb r g b (bg color spec)
X*/
X                           case 'f' : INC ; INC ; INC ;  /* Same, fg color */
X                                      break ;
X                           default :  FPRINTF(stderr,"%s: -W%c unknown argument\n",
X                                                      progname, argv[0][2]) ;
X                                      break ;
X                         }
X                       break ;
X            default  : usage() ;
X          }
X      INC ;
X    }
X}
X
X
Xvoid
Xgetparam(s, argv, errmes)
Xchar *s, *argv[], *errmes ;
X{
X  if (*argv != NULL && argv[0][0] != '-') STRCPY(s, *argv) ;
X  else
X    { 
X      FPRINTF(stderr,"%s: %s as next argument.\n", progname, errmes) ;
X      exit(1) ;
X    }
X}
X
X
Xvoid
Xinit_canvas()
X{
X  char s1[2], sa[2] ;
X  int adjust, d, i, n, x, y ;
X 
X  d = (int) cur_dpyno ;
X  color_area(0, 0, TOTAL_WIDTH, TOTAL_HEIGHT, C_WHITE) ;
X  if (iscolor[d])
X    {
X      color_area(0, 0, TOTAL_WIDTH, CY, C_BEIGE) ;
X      color_area(0, CY, TOTAL_WIDTH, TOTAL_WIDTH, C_DBROWN) ;
X      color_area(0 + BBORDER, CY + BBORDER, BOARD_SIZE * CELL_SIZE,
X                 BOARD_SIZE * CELL_SIZE, C_LBROWN) ;
X    }
X  make_panel() ;                /* Create panel and panel items. */
X
X  if (tinput) draw_textfield() ;
X
X  batch(IS_ON) ;
X  for (n = 0; n <= BOARD_SIZE; n++)
X    {
X      color = (iscolor[d]) ? C_LGREY : C_BLACK ;
X      if (n == 0 || n == BOARD_SIZE) color = C_BLACK ;
X      if (color == C_LGREY) adjust = 1 ;
X      else adjust = 0 ;
X      draw_line((n*CELL_SIZE)+BBORDER, CY+BBORDER+adjust,   /* Vertical. */
X                (n*CELL_SIZE)+BBORDER,
X                 CY+BBORDER+(BOARD_SIZE*CELL_SIZE)-adjust, RSRC, color) ;
X      draw_line(BBORDER+adjust, CY+BBORDER+(n*CELL_SIZE),   /* Horizontal. */
X                BBORDER+(BOARD_SIZE*CELL_SIZE)-adjust,
X                CY+BBORDER+(n*CELL_SIZE), RSRC, color) ;
X    }
X  batch(IS_OFF) ;
X  batch(IS_ON) ;
X  for (i = 0; i < BOARD_SIZE; i++)
X    {
X      color = (iscolor[d]) ? C_WHITE : C_BLACK ;
X      SPRINTF(s1, "%c", 'a' + i) ;
X      draw_text(BBORDER + (i * CELL_SIZE) + (CELL_SIZE / 2) - 2,
X                CY + BBORDER - 4, BFONT, color, s1) ;
X      draw_text(BBORDER + (i * CELL_SIZE) + (CELL_SIZE / 2) - 2,
X                CY + (2 * BBORDER) + (BOARD_SIZE * CELL_SIZE) - 4,
X                BFONT, color, s1) ;
X      SPRINTF(sa, "%c", '1' + i) ;
X      draw_text(BBORDER / 2 - 2, CY + BBORDER + (i * CELL_SIZE) +
X                (CELL_SIZE / 2) + 2, BFONT, color, sa) ;
X      draw_text(BBORDER + (BOARD_SIZE * CELL_SIZE) + (BBORDER / 2) - 2,
X                CY + BBORDER + (i * CELL_SIZE) + (CELL_SIZE / 2) + 2,
X                BFONT, color, sa) ;
X    }
X  batch(IS_OFF) ;
X  show_suggestion() ;
X  batch(IS_ON) ;
X  FOR_BOARD(i)
X    if (board.square[i])
X      {
X        get_xy(i, &x, &y) ;
X        draw_piece(board.square[i], x, CY+y, RSRC) ;
X      }
X  batch(IS_OFF) ;
X  set_score() ;
X  message(TURN_MES, "Black to move.") ;
X
X  if (loadgame)
X    {
X      loadgame = 0 ;
X      load_game() ;
X    }
X
X  if (first_move)
X    {
X      first_move = 0 ;
X      next_player = BLACK ;
X      computer_move(next_player) ;
X    }
X}
X
X
Xvoid
Xinitialise()        /* Initialise various variable used by reve. */
X{
X  cury = wx = wy = ix = iy = 0 ;
X  play_computer = 1 ;                 /* Default is human vs computer. */
X  iconic        = 0 ;                 /* Initially an open window. */
X  last_move     = -1 ;
X  next_player   = BLACK ;
X  but_inverted  = -1 ;
X  validkey      = 0 ;
X  cmode         = BLACK_START ;
X  show_notes    = FALSE ;
X  isblack       = 0 ;
X  iswhite       = 0 ;
X  depth         = INIT_DEPTH ;
X  items[(int) DIFFICULTY].value = depth - 1 ;
X
X  black_dpy = NULL ;              /* X11 black piece display information. */
X  white_dpy = NULL ;              /* X11 white piece display information. */
X  STRCPY(geometry,  "") ;         /* X11 geometry information. */
X  STRCPY(edgefile, EDGENAME) ;
X}
X
X
Xvoid
Xinit_edge_table(edgefile)     /* Load reve edge table values. */
Xchar *edgefile ;
X{
X  char buf[MAXLINE], *getenv(), name[MAXLINE], *paths, *ptr ;
X  int i, line ;
X  FILE *fp = NULL ;
X
X  i = 0 ;
X  if ((fp = fopen(edgefile, "r")) == NULL)
X    {
X      paths = getenv("PATH") ;
X      if ((ptr = paths) && edgefile[0] != '/')
X        for (;;)
X          if (*ptr == ':' || *ptr == 0)
X            {
X              if (*ptr == 0) break ;
X              name[i++] = '/' ;
X              name[i] = 0 ;
X              STRCAT(name, edgefile) ;
X              if ((fp = fopen(name, "r")) != NULL) break ;
X              if (*ptr == '\0') break ;
X              ptr++ ;
X              i = 0 ;
X            }
X          else name[i++] = *ptr++ ;
X    }
X
X  if (fp == NULL)
X    {
X      FPRINTF(stderr, "Cannot open Edge Stability Table file\n") ;
X      exit(1) ;
X    }
X  line = 0 ;
X  while (fgets(buf, MAXLINE, fp) != NULL)
X    {
X      line++ ;
X      if (buf[0] == '\n' || buf[0] == '#') continue ;
X      if ((ptr = index(buf, '[')) == NULL)
X        {
X          FPRINTF(stderr, "Cannot read edge table file at line %d\n", line) ;
X          exit(1) ;
X        }
X      SSCANF(ptr+1, "%d", &i) ;
X      if ((ptr = index(buf, '=')) == NULL)
X        {
X          FPRINTF(stderr, "Cannot read edge table file at line %d\n", line) ;
X          exit(1) ;
X        }
X      SSCANF(ptr+1, "%ld", &edges[i]) ;
X    }
X  FCLOSE(fp) ;
X  for (i = 0 ; i < 3281; i++) edges[6560 - i] = - edges[i] ;
X}
X
X
X/*  Setup the display information for the black and white displays.
X *  There are a fair number of combinations allowed. This table hopefully
X *  gives the setup information for each combination.
X *
X * | BLACK            WHITE     COMPUTER
X * |------------------------------------
X * |0 SET               -          -      both on black display.
X * |1  -               SET         -      both on white display.
X * |2  -                -          -      both on default display.
X * |3 SET   (same)     SET         -      both on black display.
X * |4 SET (different)  SET         -      black display and white display.
X * |-------------------------------------------------------------------------
X * |5 SET               -         SET     human plays black on black display.
X * |6  -               SET        SET     human plays white on white display.
X * |7  -                -         SET     human plays black on default display.
X * |8 SET   (same)     SET        SET     both on black display (no computer).
X * |9 SET (different)  SET        SET     black display and white display
X * |                                      (no computer).
X */
X
Xvoid
Xset_display_types()
X{
X       if (isblack && iswhite) dtype = XBOTH ;
X  else if (isblack)            dtype = XBLACK ;
X  else if (iswhite)            dtype = XWHITE ;
X
X  if (black_dpy != NULL && white_dpy != NULL)
X    {
X      if (!strcmp(black_dpy, white_dpy)) dtype = XBOTH ;            /*3 & 8*/
X      else                               dtype = XTWO ;             /*4 & 9*/
X      return ;
X    }    
X 
X  if (play_computer)
X    {
X           if (isblack && black_dpy != NULL && white_dpy == NULL)
X        dtype = XBLACK ;                                                /*5*/
X      else if (iswhite && white_dpy != NULL && black_dpy == NULL)
X        dtype = XWHITE ;                                                /*6*/
X      else if (!iswhite && !isblack && black_dpy == NULL && white_dpy == NULL)
X        dtype = XBLACK ;                                                /*7*/
X    }
X  else
X    {
X           if (black_dpy != NULL && white_dpy == NULL) dtype = XBOTH ;  /*0*/
X      else if (black_dpy == NULL && white_dpy != NULL) dtype = XBOTH ;  /*1*/
X      else if (black_dpy == NULL && white_dpy == NULL) dtype = XBOTH ;  /*2*/
X    }
X
X  isblack = iswhite = 0 ;
X       if (dtype == XBLACK)                 isblack = 1 ;
X  else if (dtype == XWHITE)                 iswhite = first_move = 1 ;
X  else if (dtype == XTWO || dtype == XBOTH) isblack = iswhite    = 1 ;
X  items[(int) BLACK_PLAYS].value = (isblack == 0) ;
X  items[(int) WHITE_PLAYS].value = (iswhite == 0) ;
X}
X
X
Xvoid
Xthink(player)
Xint player ;
X{
X  set_cursor(HOURGLASS) ;
X  play_reve(board.square, player, depth, &move, &note) ;
X  set_cursor(CANVASCUR) ;
X  animate_move(move) ;
X  do_move(player) ;
X  last_move = move ;
X  cmode = (enum cantype) (OPPONENT(player) + 1) ;
X}
X
X
Xvoid
Xusage()
X{
X  FPRINTF(stderr, "%s version 1.1.%1d\n\n", progname, PATCHLEVEL) ;
X  FPRINTF(stderr, "Usage: %s: [-b [display] ] [-c]\n", progname) ;
X  FPRINTF(stderr, "\t[-d difficulty] [-e edgefile] [-g geometry]\n") ;
X  FPRINTF(stderr, "\t[-l gamefile] [-v] [-w [display] ] [-?] [-Wi]\n") ;
X  FPRINTF(stderr, "\t[-Wp x y] [-WP x y]\n") ;
X}
X
X
X#ifdef NO_USLEEP
Xusleep(x)        /* Suspend execution for interval in microseconds. */
Xunsigned x ;
X{
X  struct timeval st_delay ;
X
X  st_delay.tv_usec = x ;
X  st_delay.tv_sec = 0 ;
X  (void) select(32, NULL, NULL, NULL, &st_delay) ;
X}	
X#endif /*NO_USLEEP*/
X
END_OF_FILE
if test 22172 -ne `wc -c <'main.c'`; then
    echo shar: \"'main.c'\" unpacked with wrong size!
fi
# end of 'main.c'
fi
if test -f 'xview.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'xview.c'\"
else
echo shar: Extracting \"'xview.c'\" \(14806 characters\)
sed "s/^X//" >'xview.c' <<'END_OF_FILE'
X/*LINTLIBRARY*/
X
X/*  @(#)xview.c 1.4 90/10/08
X *
X *  XView dependent graphics routines used by reve.
X *
X *  Copyright (c) 1990 - Rich Burridge & Yves Gallot.
X *  All rights reserved.
X *
X *  Permission is given to distribute these sources, as long as the
X *  introductory messages are not removed, and no monies are exchanged.
X *
X *  You are forbidden from using Reve as is, or in a modified state, in
X *  any tournaments, without the permission of the authors.
X *
X *  No responsibility is taken for any errors or inaccuracies inherent
X *  either to the comments or the code of this program, but if reported
X *  (see README file), then an attempt will be made to fix them.
X */
X
X#include <stdio.h>
X#include "reve.h"
X#include "color.h"
X#include "extern.h"
X#include "images.h"
X#include <xview/xview.h>
X#include <xview/canvas.h>
X#include <xview/cms.h>
X#include <xview/cursor.h>
X#include <xview/svrimage.h>
X#include <xview/xv_xrect.h>
X#include <X11/Xlib.h>
X
Xenum gr_type gtype = GXVIEW ;      /* Graphics type. */
X
X#define  XV_SET       (void) xv_set
X#define  WINDOW_DONE  (void) window_done
X
X#define  BOLDFONT     "lucidasanstypewriter-bold-12"
X#define  DEFFONT      "fixed"
X#define  NORMALFONT   "lucidasanstypewriter-12"
X
Xstatic void menu_proc() ;
X
Xmpr_static(icon_pr,  64, 64, 1, icon_image) ;
Xmpr_static(cicon_pr, 64, 64, 8, cicon_image) ;
X
XCanvas canvas ;
XCanvas_paint_window cpw ;
XEvent *cur_event ;
XFrame frame ;
XIcon reve_icon ;
XMenu menus[MAXMENUS] ;
XNotify_value destroy() ;
XServer_image hglass_pr, nocur_pr ;
XXv_Cursor cursor[MAXCURSORS] ;
X
XDisplay *dpy ;                  /* Display id of reve frame. */
XDrawable images[MAXIMAGES] ;    /* Various graphics images used by reve. */
XDrawable make_server_image() ;
XDrawable xid ;                  /* Xid for reve canvas. */
XGC gc ;                         /* Graphics context for text and lines. */
XGC ropgc ;                      /* Graphics context for rops. */
XGC stencilgc ;                  /* Graphics context for stencils. */
XWindow root ;
XXFontStruct *font[MAXFONTS] ;   /* Xlib handles to the fonts. */
XXGCValues gc_val ;              /* Used to setup graphics context values. */
Xint gc_flags ;                  /* Used to set up graphics context flags. */
Xint screen ;                    /* Default graphics display screen. */
Xunsigned long backgnd ;         /* Default background color. */
Xunsigned long foregnd ;         /* Default foreground color. */
Xunsigned long gc_mask ;         /* Mask for setting graphic context values. */
Xunsigned long palette[OTH_COLORSIZE] ;     /* Xlib color palette. */
X
Xint opvals[3] ;         /* Pixrect rasterop values. */
Xint started ;           /* Set just before window is displayed. */
X
X
Xvoid
Xbatch(state)            /* Turn graphics batching on or off. */
Xenum bltype state ;
X{
X  XV_SET(xv_default_server, SERVER_SYNC, 1, 0) ;
X}
X
X
X/*ARGSUSED*/
Xvoid
Xcanvas_proc(window, event)
XXv_window window ;
XEvent *event ;
X{
X  if (!started) return ;
X  cur_event = event ;
X  process_event() ;       /* Determine what kind of event it is. */
X  handle_event() ;        /* And do the appropriate action. */
X
X  if (nextc == LEFT_UP || nextc == MIDDLE_UP || nextc == RIGHT_UP)
X    XV_SET(frame, FRAME_BUSY, FALSE, 0) ;
X}
X
X
Xvoid
Xclose_frame()        /* Iconise reve window. */
X{
X  XV_SET(frame, FRAME_CLOSED, TRUE, 0) ;
X}
X
X
Xvoid
Xcolor_area(x, y, width, height, color)
Xint x, y, width, height, color ;
X{
X  int d ;
X
X  d = (int) cur_dpyno ;
X  if (iscolor[d]) gc_val.foreground = palette[color] ;
X  else
X    { 
X      if (color == C_WHITE) gc_val.foreground = backgnd ;
X      else gc_val.foreground = foregnd ;
X    }
X  gc_val.function = GXcopy ;
X  gc_mask = GCForeground | GCFunction ;
X  XChangeGC(dpy, gc, gc_mask, &gc_val) ;
X  XFillRectangle(dpy, xid, gc,
X                 x, y, (unsigned int) width, (unsigned int) height) ;
X}
X
X
Xvoid
Xcreate_menu(mtype, values)    /* Create popup menus for cycle items. */
Xenum panel_type mtype ;
Xchar *values[] ;
X{
X  int i = 0 ;
X  int menuno ;     /* Current menu number. */
X  int more = 1 ;   /* Cleared when current menu is complete.*/
X
X  menuno = (int) mtype - (int) BLACK_PLAYS ;
X  menus[menuno] = xv_create(XV_NULL,          MENU_COMMAND_MENU,
X                            MENU_NOTIFY_PROC, menu_proc,
X                            0) ;
X  do
X    {
X      if (values[i] != NULL)
X        XV_SET(menus[menuno], MENU_STRING_ITEM, values[i], i+1, 0) ;
X      else more = 0 ;
X      i++ ;
X    }
X  while (more) ;
X}
X
X
Xvoid
Xdestroy_frame()        /* Destroy reve window. */
X{
X  WINDOW_DONE(frame) ;
X}
X
X
Xdo_menu(mtype)      /* Popup appropriate cycle menu and get value. */
Xenum item_type mtype ;
X{
X  int menuno ;
X
X  menuno = (int) mtype - (int) BLACK_PLAYS ;
X  menu_show(menus[menuno], canvas, cur_event, 0) ;
X  return(0) ;
X}
X
X
Xvoid
Xdraw_image(x, y, width, height, image)
Xint x, y, width, height ;
Xenum image_type image ;
X{
X  gc_mask = GCStipple | GCTileStipXOrigin | GCTileStipYOrigin ;
X  gc_val.stipple = images[(int) image] ;
X  gc_val.ts_x_origin = x ;
X  gc_val.ts_y_origin = y ;
X  XChangeGC(dpy, ropgc, gc_mask, &gc_val) ;
X  XFillRectangle(dpy, xid, ropgc, x, y, width, height) ;
X}
X 
X 
Xvoid
Xdraw_line(x1, y1, x2, y2, op, color)
Xint x1, y1, x2, y2, color ;
Xenum optype op ;
X{
X  int d ;
X
X  d = (int) cur_dpyno ;
X  if (iscolor[d]) gc_val.foreground = palette[color] ;
X  else            gc_val.foreground = foregnd ;
X  gc_val.function = opvals[(int) op] ;
X  XChangeGC(dpy, gc, GCForeground | GCFunction, &gc_val) ;
X  XDrawLine(dpy, xid, gc, x1, y1, x2, y2) ;
X}
X
X
Xvoid
Xdraw_stencil(x, y, width, height, op, color, stencil, image)
Xint x, y, width, height, color ;
Xenum optype op ;
Xenum image_type stencil, image ;
X{
X  int d ;
X
X  d = (int) cur_dpyno ;
X  if (iscolor[d]) gc_val.foreground = palette[color] ;
X  else            gc_val.foreground = foregnd ;
X  gc_val.function = opvals[(int) op] ;
X  gc_val.clip_x_origin = x ;
X  gc_val.clip_y_origin = y ;
X  gc_val.clip_mask = images[(int) stencil] ;
X  gc_val.stipple = images[(int) image] ;
X  gc_val.ts_x_origin = x ;
X  gc_val.ts_y_origin = y ;
X  gc_mask = GCForeground | GCFunction | GCClipMask |
X            GCClipXOrigin | GCClipYOrigin |
X            GCStipple | GCTileStipXOrigin | GCTileStipYOrigin ;
X  XChangeGC(dpy, stencilgc, gc_mask, &gc_val) ;
X  XFillRectangle(dpy, xid, stencilgc, x, y, width, height) ;
X}
X
X
Xvoid
Xdraw_text(x, y, ftype, color, str)
Xenum font_type ftype ;
Xint x, y, color ;
Xchar *str ;
X{
X  int d ;
X
X  d = (int) cur_dpyno ;
X  if (iscolor[d]) gc_val.foreground = palette[color] ;
X  else
X    {
X      if (color == C_WHITE) gc_val.foreground = backgnd ;
X      else gc_val.foreground = foregnd ;
X    }
X  gc_val.font = font[(int) ftype]->fid ;
X  gc_val.function = GXcopy ;
X  XChangeGC(dpy, gc, GCFont | GCForeground | GCFunction, &gc_val) ;
X  XDrawString(dpy, xid, gc, x, y, str, strlen(str)) ;
X}
X
X
XXFontStruct *
Xget_font(name)
Xchar *name ;
X{
X  XFontStruct *f ;
X
X  if (!(f = XLoadQueryFont(dpy, name)))
X    if (!(f = XLoadQueryFont(dpy, DEFFONT)))
X      {
X        FPRINTF(stderr, "%s: couldn't get the default font.", progname) ;
X        exit(1) ;
X      }
X  return(f) ;
X}
X
X
Xget_strwidth(ftype, str)    /* Get width in pixels of string value. */
Xenum font_type ftype ;
Xchar *str ;
X{
X  return(XTextWidth(font[(int) ftype], str, strlen(str))) ;
X}
X
X
Xvoid
Xinit_fonts()         /* Open the normal and bold fonts. */
X{
X  font[(int) BFONT] = get_font(BOLDFONT) ;
X  font[(int) NFONT] = get_font(NORMALFONT) ;
X  bfont_height = font[(int) BFONT]->max_bounds.ascent +
X                 font[(int) BFONT]->max_bounds.descent ;
X  nfont_height = font[(int) NFONT]->max_bounds.ascent +
X                 font[(int) NFONT]->max_bounds.descent ;
X}
X
X
Xinit_ws_type()
X{
X  move_delta = 10 ;
X  cur_dpyno = DPY1 ;
X  started = 0 ;       /* Kludge to correctly handle repaints. */
X  return 0 ;
X}
X
X
Xstatic void
Xload_colors()      /* Create and load reve color map. */
X{
X  XColor ccol ;
X  u_char red[OTH_COLORSIZE], green[OTH_COLORSIZE], blue[OTH_COLORSIZE] ;
X  int i, numcolors ;
X
X  if (iscolor[(int) cur_dpyno])
X    {
X      oth_colorsetup(red, green, blue) ;
X      numcolors = 0 ;
X      for (i = 0; i < OTH_COLORSIZE; i++)
X        {
X          ccol.flags = DoRed | DoGreen | DoBlue ;
X          ccol.red = (unsigned short) (red[i] << 8) ;
X          ccol.green = (unsigned short) (green[i] << 8) ;
X          ccol.blue = (unsigned short) (blue[i] << 8) ;
X          if (XAllocColor(dpy, DefaultColormap(dpy, screen), &ccol) == True)
X            palette[numcolors++] = ccol.pixel ;
X        }
X      if (numcolors < 2)
X        {
X          FPRINTF(stderr, "%s: cannot allocate colors.\n", progname) ;
X          exit(1) ;
X        }
X    }
X}
X
X
Xvoid
Xlock_screen(state)     /* Turn graphics locking on or off - null routine. */
Xenum bltype state ;
X{}
X
X
Xvoid
Xmake_canvas()               /* Create canvas for game board. */
X{
X  canvas = xv_create(frame,               CANVAS,
X                     CANVAS_RETAINED,     FALSE,
X                     OPENWIN_AUTO_CLEAR,  FALSE,
X                     XV_HEIGHT,           TOTAL_HEIGHT,
X                     XV_WIDTH,            TOTAL_WIDTH,
X                     CANVAS_PAINTWINDOW_ATTRS,
X                       WIN_CONSUME_EVENTS,
X                         MS_LEFT, MS_MIDDLE, MS_RIGHT,
X                         WIN_ASCII_EVENTS, KBD_USE, KBD_DONE,
X                         LOC_MOVE, LOC_DRAG,
X                         LOC_WINENTER, LOC_WINEXIT,
X                         WIN_LEFT_KEYS, WIN_TOP_KEYS,
X                         WIN_RIGHT_KEYS, WIN_REPAINT,
X                         0,
X                       WIN_EVENT_PROC,    canvas_proc,
X                       0,
X                     0) ;
X  cpw = canvas_paint_window(canvas) ;
X  cursor[(int) CANVASCUR] = xv_get(cpw, WIN_CURSOR) ;
X
X  dpy = (Display *) xv_get(frame, XV_DISPLAY) ;
X  xid = (Drawable) xv_get(cpw, XV_XID) ;
X
X  screen = DefaultScreen(dpy) ;
X  root = RootWindow(dpy, screen) ;
X  foregnd = BlackPixel(dpy, screen) ;
X  backgnd = WhitePixel(dpy, screen) ;
X
X  gc_mask = GCForeground | GCBackground | GCGraphicsExposures ;
X  gc_val.foreground = foregnd ;
X  gc_val.background = backgnd ;
X  gc_val.graphics_exposures = False ;
X  gc = XCreateGC(dpy, root, gc_mask, &gc_val) ;
X
X  ropgc = XCreateGC(dpy, root, gc_mask, &gc_val) ;
X  XSetFillStyle(dpy, ropgc, FillStippled) ;
X
X  stencilgc = XCreateGC(dpy, root, gc_mask, &gc_val) ;
X  XSetFillStyle(dpy, stencilgc, FillOpaqueStippled) ;
X
X  hglass_pr = xv_create(XV_NULL,           SERVER_IMAGE,
X                        XV_WIDTH,          16,
X                        XV_HEIGHT,         16,
X                        SERVER_IMAGE_BITS, hglass_image,
X                        0) ;
X  cursor[(int) HOURGLASS] = xv_create(XV_NULL,      CURSOR,
X                                      CURSOR_IMAGE, hglass_pr,
X                                      0) ;
X  nocur_pr = xv_create(XV_NULL,           SERVER_IMAGE,
X                       XV_WIDTH,          16,
X                       XV_HEIGHT,         16,
X                       SERVER_IMAGE_BITS, nocur_image,
X                       0) ;
X  cursor[(int) NOCURSOR] = xv_create(XV_NULL,      CURSOR,
X                                     CURSOR_IMAGE, nocur_pr,
X                                     0) ;
X  load_colors() ;
X
X  images[(int) BUT_STENCIL] = make_server_image(button_stencil_image) ;
X  images[(int) BUT_INVERT]  = make_server_image(button_invert_image) ;
X  images[(int) BUT_NORMAL]  = make_server_image(button_normal_image) ;
X  images[(int) CY_NORMAL]   = make_server_image(cycle_glyph_image) ;
X  images[(int) CY_STENCIL]  = make_server_image(cycle_stencil_image) ;
X  images[(int) CY_LINVERT]  = make_server_image(cycle_linvert_image) ;
X  images[(int) CY_RINVERT]  = make_server_image(cycle_rinvert_image) ;
X  images[(int) P_WHITE]     = make_server_image(white_image) ;
X  images[(int) P_BLACK]     = make_server_image(black_image) ;
X}
X
X
Xvoid
Xmake_frame(argc, argv)      /* Create reve window. */
Xint argc ;
Xchar *argv[] ;
X{
X  opvals[(int) RCLR] = GXclear ;
X  opvals[(int) RSRC] = GXcopy ;
X  opvals[(int) RINV] = GXxor ;
X
X  xv_init(XV_INIT_ARGS, argc, argv, 0) ;
X  frame = xv_create(XV_NULL,                  FRAME,
X                    FRAME_ICON,               reve_icon,
X                    FRAME_LABEL,              line,
X                    FRAME_NO_CONFIRM,         TRUE,
X                    FRAME_SHOW_RESIZE_CORNER, FALSE,
X                    WIN_ERROR_MSG,            "Can't create window.",
X                    0) ;
X  iscolor[(int) cur_dpyno] = ((int) xv_get(frame, WIN_DEPTH) > 1) ? 1 : 0 ;
X}
X
X
Xvoid
Xmake_icon()
X{
X  reve_icon = xv_create(XV_NULL,    ICON,
X                        ICON_IMAGE, &icon_pr,
X                        0) ;
X}
X
X
XDrawable
Xmake_server_image(image)
Xunsigned short image[] ;
X{
X  Server_image temp ;
X
X  temp = xv_create(XV_NULL,           SERVER_IMAGE,
X                   XV_WIDTH,          64,
X                   XV_HEIGHT,         64,
X                   SERVER_IMAGE_BITS, image,
X                   0) ;
X  return((int) xv_get(temp, XV_XID)) ;
X}
X
X
Xstatic void
Xmenu_proc(menu, menu_item)
XMenu menu ;
XMenu_item menu_item ;
X{
X  int choice ;
X
X  choice = (int) menu_get(menu_item, MENU_VALUE) ;
X  if (choice) handle_item(choice - 1) ;
X}
X
X
Xvoid
Xprocess_event()       /* Process the next canvas event. */
X{
X  int id ;
X
X  id = (event_id(cur_event)) ;
X  curx = event_x(cur_event) ;
X  cury = event_y(cur_event) ;
X 
X       if (id == KBD_DONE    || id == LOC_WINEXIT) nextc = EXIT_WINDOW ;
X  else if (id == LOC_WINENTER)                     nextc = ENTER_WINDOW ;
X  else if (id == LOC_MOVE    || id == LOC_DRAG)    nextc = MOUSE_MOVING ;
X  else if (id == WIN_REPAINT || id == WIN_RESIZE)  nextc = FRAME_REPAINT ;
X  else if (id == WIN_REPAINT || id == WIN_RESIZE)  nextc = FRAME_REPAINT ;
X  else if (event_is_button(cur_event) && event_is_down(cur_event))
X    {
X           if (id == MS_LEFT)   nextc = LEFT_DOWN ;
X      else if (id == MS_MIDDLE) nextc = MIDDLE_DOWN ;
X      else if (id == MS_RIGHT)  nextc = RIGHT_DOWN ;
X    }
X  else if (event_is_button(cur_event) && event_is_up(cur_event))
X    {
X           if (id == MS_LEFT)   nextc = LEFT_UP ;
X      else if (id == MS_MIDDLE) nextc = MIDDLE_UP ;
X      else if (id == MS_RIGHT)  nextc = RIGHT_UP ;
X      XV_SET(frame, FRAME_BUSY, TRUE, 0) ;
X    }
X  else if (event_is_ascii(cur_event))
X    {
X      cur_ch = id ;
X      nextc = KEYBOARD ;
X    }
X}
X
X
Xvoid
Xset_cursor(ctype)
Xenum curtype ctype ;
X{
X  if (ctype == NOCURSOR) return ;
X  XV_SET(cpw, WIN_CURSOR, cursor[(int) ctype], 0) ;
X  XV_SET(xv_default_server, SERVER_SYNC, 1, 0) ;
X}
X
X
X/*ARGSUSED*/
Xvoid
Xstart_tool(dtype)      /* Display window and start the notifier. */
Xenum disp_type dtype ;
X{
X  if (iscolor[(int) cur_dpyno])
X    {
X      reve_icon = (Icon) xv_get(frame, FRAME_ICON) ;
X      XV_SET(reve_icon,
X             ICON_IMAGE, &cicon_pr,
X             0) ;
X      XV_SET(frame, FRAME_ICON, reve_icon, 0) ;
X    }
X  window_fit(frame) ;
X  started = 1 ;
X  xv_main_loop(frame) ;
X}
END_OF_FILE
if test 14806 -ne `wc -c <'xview.c'`; then
    echo shar: \"'xview.c'\" unpacked with wrong size!
fi
# end of 'xview.c'
fi
echo shar: End of archive 1 \(of 7\).
cp /dev/null ark1isdone
MISSING=""
for I in 1 2 3 4 5 6 7 ; do
    if test ! -f ark${I}isdone ; then
	MISSING="${MISSING} ${I}"
    fi
done
if test "${MISSING}" = "" ; then
    echo You have unpacked all 7 archives.
    rm -f ark[1-9]isdone
else
    echo You still need to unpack the following archives:
    echo "        " ${MISSING}
fi
##  End of shell archive.
exit 0