[comp.sources.games] v11i056: reve - an othello game, Part05/07

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

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


#! /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 5 (of 7)."
# Contents:  FILES boardstuff.c color.h events.c
#   images/button.normal.icon rev_iycp.c sunview.c
# Wrapped by billr@saab on Thu Nov  1 14:02:53 1990
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f 'FILES' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'FILES'\"
else
echo shar: Extracting \"'FILES'\" \(3095 characters\)
sed "s/^X//" >'FILES' <<'END_OF_FILE'
X
X@(#)FILES 1.3 90/10/18
X
XThis file describes all the files that make up the Reve distribution.
X
XDirectory reve: an othello game.
X--------------------------------
X
Xboardstuff.c                - various board manipulation routines.
Xevents.c                    - event handling procedures.
Xitems.c                     - procedures for manipulating reve panel items.
Xmakemove.c                  - interface to the computer strategy routines.
Xmain.c                      - includes variable declarations and main().
Xprocs.c                     - procedures associated with the panel items.
X
Xrev_eval.c                  - reve evaluation function.
Xrev_ip.c                    - return a move and a note for a given color.
Xrev_iycp.c                  - reve "fast" alpha-beta pruning routines.
X
Xcolor.h                     - colormap definitions.
Xextern.h                    - external declaractions.
Ximages.h                    - include file for all graphic images.
Xreve.h                      - macro and constant definitions.
Xpatchlevel.h                - current patchlevel for this release of reve.
X
XCHANGES                     - change history. Updated with each new patch.
XREADME                      - describes what reve is, and how to get started.
XTODO                        - bugs and suggested enhancements. Volunteers?
Xreve.6                      - the reve manual page (troff/nroff -man format).
Xreve.man                    - plain text version of the reve manual pages.
XMANIFEST                    - tells you what archive part each file was in.
XFILES                       - what you're reading now.
Xreve.edge1                  - first half of the Reve edge stability table.
Xreve.edge2                  - second half of the Reve edge stability table.
XMakefile.dist               - master Makefile used to build mp on Unix systems.
X
Xsunview.c                   - Sun SunView graphics routines.
Xtty.c                       - dumb tty "graphics" routines.
Xx11.c                       - X11 (Xlib) graphics routines.
Xxview.c                     - X11 XView tolkit graphics routines.
X
XSub-directory images: image files used with the graphics versions of reve.
X--------------------------------------------------------------------------
Ximages/black.icon           - black reve piece.
Ximages/reve.icon            - reve icon (monochrome screens and XView).
Ximages/reve.color.icon      - reve icon (color screens).
Ximages/white.icon           - white reve piece.
Ximages/button.invert.icon   - button panel item in inverted mode.
Ximages/button.normal.icon   - button panel item in normal mode.
Ximages/button.stencil.icon  - stencil for normal/inverted button panel items.
Ximages/cycle.glyph.icon     - cycle panel item in normal mode.
Ximages/cycle.linvert.icon   - cycle panel item with left side inverted.
Ximages/cycle.rinvert.icon   - cycle panel item with right side inverted.
Ximages/cycle.stencil.icon   - stencil for normal/inverted cycle panel items.
Ximages/hglass.cursor        - hour glass cursor for computer move.
Ximages/nocur.cursor         - no cursor when piece is being dragged.
END_OF_FILE
if test 3095 -ne `wc -c <'FILES'`; then
    echo shar: \"'FILES'\" unpacked with wrong size!
fi
# end of 'FILES'
fi
if test -f 'boardstuff.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'boardstuff.c'\"
else
echo shar: Extracting \"'boardstuff.c'\" \(12414 characters\)
sed "s/^X//" >'boardstuff.c' <<'END_OF_FILE'
X/*LINTLIBRARY*/
X
X/*  @(#)boardstuff.c 1.9 90/10/20
X *
X *  Various board 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 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 <ctype.h>
X
X#ifndef SYSV
X#include <sys/time.h>
X#endif /*SYSV*/
X
X#include "color.h"
X#include "reve.h"
X#include "extern.h"
X
X
Xvoid
Xanimate_move(move)
Xint move ;
X{
X  int x0, y0, x1, y1, x, y, dx, dy, ctr ;
X
X  lock_screen(IS_ON) ;
X  get_xy(move, &x1, &y1) ;
X  dx = x1 ;
X  dy = y1 ;
X  if (x1 > y1)
X    {
X      ctr = dx / 2 ;
X      x = BBORDER ;
X      y = BBORDER ;
X      draw_piece(WHITE, x, CY+y, RINV) ;
X      while (x < x1)
X        {
X#ifndef SYSV
X          set_timer() ;
X#endif /*SYSV*/
X          x0 = x ;
X          y0 = y ;
X          x += move_delta ;
X          if ((ctr -= dy) < 0)
X            {
X              ctr += dx ;
X              y += move_delta ;
X            }
X          draw_piece(WHITE, x, CY+y, RINV) ;
X          draw_piece(WHITE, x0, CY+y0, RINV) ;
X#ifndef SYSV
X          nap_upto(1) ;
X#endif /*SYSV*/
X        }
X      draw_piece(WHITE, x, CY+y, RINV) ;
X    }
X  else
X    { 
X      ctr = dy / 2 ;
X      x = BBORDER ;
X      y = BBORDER ;
X      draw_piece(WHITE, x, CY+y, RINV) ;
X      while (y < y1)
X        {
X#ifndef SYSV
X          set_timer() ;
X#endif /*SYSV*/
X          x0 = x ;
X          y0 = y ;
X          y += move_delta ;
X          if ((ctr -= dx) < 0)
X            {
X              ctr += dy ;
X              x += move_delta ;
X            }
X          draw_piece(WHITE, x, CY+y, RINV) ;
X          draw_piece(WHITE, x0, CY+y0, RINV) ;
X#ifndef SYSV
X          nap_upto(1) ;
X#endif /*SYSV*/
X        }
X      draw_piece(WHITE, x, CY+y, RINV) ;
X    }
X  lock_screen(IS_OFF) ;
X}
X
X
X/*  This routine checks to see if a move can be made for this player.
X *  If not, various checks are made to see if the game is finished.
X *  Return value indicates if a move can be made.
X */
X
Xcheck(player)
Xint player ;
X{
X  if ((!count(&board, BLACK)) || (!count(&board, WHITE)) ||
X      ((count(&board, BLACK) + count(&board, WHITE)) == 64))
X    {
X      who_wins() ;
X      last_cmode = cmode ;     /* Save previous value in case of undo. */
X      cmode = GAME_OVER ;
X      message(PANEL_MES, "Game over") ;
X      return(FALSE) ;
X    }
X  if ((move = valid_move(&board, player)) == FALSE)
X    {
X      SPRINTF(line, "%s is forced to pass",
X                    (player == BLACK) ? "Black" : "White") ;
X      message(PANEL_MES, line) ;
X      set_turn(OPPONENT(player)) ;
X      if ((move = valid_move(&board, OPPONENT(player))) == FALSE)
X        {
X          who_wins() ;
X          last_cmode = cmode ;
X          cmode = GAME_OVER ;
X          message(PANEL_MES, "Game over") ;
X        }
X      return(FALSE) ;
X    }
X  return(TRUE) ;
X}
X
X
Xvoid
Xcomputer_move(player)
Xint player ;
X{
X  for (;;)
X    if (check(player) == TRUE)
X      {
X        think(player) ;
X        if (check(OPPONENT(player)) == TRUE) break ;
X        if (cmode == GAME_OVER) break ;
X      }
X    else
X      { 
X        if (cmode != GAME_OVER) cmode = (enum cantype) ((int) cmode - 1) ;
X        return ;
X      }
X}
X
X
Xcount(board, player)    /* Count the number of player pieces on the board. */
Xint player ;
XBOARD *board ;
X{
X  int i, n ;
X
X  n = 0 ;
X  FOR_BOARD(i)
X    if (board->square[i] == player) n++ ;
X  return(n) ;
X}
X
X
Xvoid
Xdo_move(player)
Xint player ;
X{
X  int taken ;                /* Number of pieces flipped this go. */
X
X  taken = formfliplist(move, player) ;
X  update_board_image(player) ;
X  SPRINTF(line, "%s took %d %s", (player == BLACK) ? "Black" : "White",
X                          taken, (taken  == 1)     ? "piece" : "pieces") ;
X  message(PANEL_MES, line) ;
X}
X
X
Xformfliplist(move, player)
Xint move, player ;
X{        
X  int cnt, i, n, old_cnt ;
X
X  old_cnt = count(&board, player) ;
X  FOR_BOARD(i) old_board.square[i] = board.square[i] ;
X  old_board.moves_left = board.moves_left ;
X  domove(&old_board, move, &board, player) ;
X
X  n = 63 - board.moves_left ;
X  FOR_BOARD(i) moves[n].square[i] = board.square[i] ;
X  moves[n].moves_left = board.moves_left ;
X  moves[n].move = move ;
X  moves[n].note = note ;
X  moves[n].player = player ;
X
X  cnt = count(&board, player) ;
X  return(cnt - old_cnt - 1) ;
X}
X
X
Xvoid
Xinitboard()    /* Initialise the othello board. */
X{
X  static int ivals[4]   = { 27,    28,    35,    36 } ;
X  static int icolors[4] = { WHITE, BLACK, BLACK, WHITE } ;
X  int i, j , n ;
X
X  for (i = 0; i < 64; i++) moves[i].move = -1 ;
X  for (n = 0; n < 4; n++)
X    {
X      FOR_BOARD(i) moves[n].square[i] = FREE ;
X      for (j = 0; j <= n; j++) moves[n].square[ivals[j]] = icolors[j] ;
X      moves[n].player     = icolors[n] ;
X      moves[n].move       = ivals[n] ;
X      moves[n].moves_left = 63 - n ;
X    }
X
X  FOR_BOARD(i) old_board.square[i] = board.square[i] = FREE ;
X  board.square[27] = WHITE ;
X  board.square[28] = BLACK ;
X  board.square[35] = BLACK ;
X  board.square[36] = WHITE ;
X  board.moves_left = 60 ;
X}
X
X
Xvoid
Xload_game()
X{
X
X/*  Read in a game from file, and setup internal variables accordingly.
X *
X *  Notation in the games file is of the format:
X *  1, <C-4>   -     [ remarks field ]
X *  2,   -   <E-3>   [ remarks field ]
X *
X *  The move number is the field before the comma. This is just used as a
X *  consistency check. Next is the black move or the white move (surronded
X *  by '<' and '>' characters. Obviously only one piece moves per go, and
X *  the '-' character is used to signify which piece doesn't move (in case
X *  one player had to miss a turn.
X *
X *  As each position is added, the board is redisplayed, and if the game is
X *  not over, the next player can commence.
X */
X
X  char buf[MAXLINE], col, *lptr, *mptr, row ;
X  int moveno, n ;
X  FILE *fp ;
X
X  if ((fp = fopen(gamefile, "r")) == NULL)
X    {
X      SPRINTF(buf, "Couldn't open game file: %s", gamefile) ;
X      message(PANEL_MES, buf) ;
X      return ;
X    }
X
X  moveno = 0 ;
X  initboard() ;
X  last_move = -1 ;
X  init_canvas() ;
X  message(NOTES_MES, "") ;
X  while (fgets(buf, MAXLINE, fp) != NULL)
X    {
X      if (buf[0] == '\n' || buf[0] == '#') continue ;
X      moveno++ ;
X      SSCANF(buf, "%d", &n) ;
X      if (n != moveno || n > 60)
X        {
X          SPRINTF(buf, "Load error: incorrect move [%d] on line %d", n, move) ;
X          message(PANEL_MES, buf) ;
X          return ;
X        }
X      lptr = (char *) index(buf, '<') ;
X      mptr = (char *) index(buf, '-') ;
X      if (lptr == NULL || mptr == NULL)
X        {
X          SPRINTF(buf, "Load error: missing < or - on line %d", move) ;
X          message(PANEL_MES, buf) ;
X          return ;
X        }
X      if (lptr < mptr) next_player = BLACK ;    /* Black move? */
X      else             next_player = WHITE ;
X      SSCANF(lptr, "<%c-%c>", &row, &col) ;
X      if (load_move(moveno, row, col) == 0)
X        {
X          SPRINTF(buf, "Load error: invalid move <%c-%c> on line %d",
X                                    row, col, move) ;
X          message(PANEL_MES, buf) ;
X          return ;
X        }
X      SPRINTF(buf, "Loaded move %d for %s",
X                    moveno, (next_player == BLACK) ? "black" : "white") ;
X      message(PANEL_MES, buf) ;
X    }
X  FCLOSE(fp) ;
X
X  set_score() ;
X  set_turn(OPPONENT(next_player)) ;
X
X  cmode = (enum cantype) (OPPONENT(next_player) + 1) ;
X  next_player = OPPONENT(next_player) ;
X  if (check(next_player) == TRUE) return ;
X  (void) check(OPPONENT(next_player)) ;
X}
X
X
Xload_move(n, col, row)
Xint n, col, row ;
X{
X  int i, taken, x, y ;
X
X  if (row < '1' || row > '8') return(0) ;
X  if (isupper(col)) col = tolower(col) ;
X  if (col < 'a' || col > 'h') return(0) ;
X  move = (row - '1') * BOARD_SIZE + (col - 'a') ;
X  if (legal(move, next_player, &board) == FALSE) return(0) ;
X  taken = formfliplist(move, next_player) ;
X  batch(IS_ON) ;
X  FOR_BOARD(i)
X    if (board.square[i] != old_board.square[i])
X      {
X        get_xy(i, &x, &y) ;
X        draw_piece(next_player, x, CY+y, RSRC) ;
X      } 
X  batch(IS_OFF) ;
X  return(1) ;
X}
X
X
X#ifndef SYSV
Xvoid
Xnap_upto(n)          /* Sleep upto n microseconds from start of timer. */
Xint n ;
X{
X  struct timeval ctp ;
X  struct timezone ctzp ;
X  long elapsed ;     /* Number of microseconds since timer started. */
X
X  GETTIMEOFDAY(&ctp, &ctzp) ;
X  elapsed = ((ctp.tv_usec - tp.tv_usec) +
X            (ctp.tv_sec - tp.tv_sec) * 1000000L) / 1000 ;
X  if (elapsed > n) return ;
X  usleep((unsigned) (n - elapsed)) ;
X}
X#endif /*SYSV*/
X
X
Xvoid
Xsave_game()
X{
X
X/*  Save the current game status to file.
X *
X *  The notation in the saved games file is of the format:
X *  1, <C-4>   -    [ note : 12345 ]
X *  2,   -   <E-3>  [ note : 0 ]
X *
X *  The move number is the field before the comma. This is just used as a
X *  consistency check. Next is the black move or the white move (surronded
X *  by '<' and '>' characters. Obviously only one piece moves per go, and
X *  the '-' character is used to signify which piece doesn't move (in case
X *  one player had to miss a turn.
X */
X
X  char buf[MAXLINE] ;
X  int n ;
X  FILE *fp ;
X
X  if ((fp = fopen(gamefile, "w")) == NULL)
X    {
X      SPRINTF(buf, "Couldn't open game file: %s", gamefile) ;
X      message(PANEL_MES, buf) ;
X      return ;
X    }
X
X  for (n = 4; n < 64; n++)
X    {
X      if (moves[n].move == -1) break ;
X      if (moves[n].player == BLACK)
X        FPRINTF(fp, "%d,  <%c-%c>   -  [ note : %ld ]\n",
X                n-3, (moves[n].move % 8)  + 'a',
X                     (moves[n].move >> 3) + '1', moves[n].note) ;
X      else
X        FPRINTF(fp, "%d,  -   <%c-%c>  [ note : %ld ]\n",
X                n-3, (moves[n].move % 8)  + 'a',
X                     (moves[n].move >> 3) + '1', moves[n].note) ;
X    }
X  FCLOSE(fp) ;
X  SPRINTF(buf, "Current game saved in %s", gamefile) ;
X  message(PANEL_MES, buf) ;
X}
X
X
Xvoid
Xset_score()
X{
X  SPRINTF(line, "Black: %2d, White: %2d",
X                 count(&board, BLACK), count(&board, WHITE)) ;
X  message(SCORE_MES, line) ;
X}
X
X
Xvoid
Xset_turn(player)
Xint player ;
X{
X  SPRINTF(line, "%s to move", (player == BLACK) ? "Black" : "White") ;
X  message(TURN_MES, line) ;
X}
X
X
X#ifndef SYSV
Xvoid
Xset_timer()
X{
X  struct timezone tzp ;
X
X  GETTIMEOFDAY(&tp, &tzp) ;
X}
X#endif /*SYSV*/
X
X
Xvoid
Xshow_suggestion()
X{
X  enum optype rop ;
X
X  if (suggestion != -1)
X    {
X      rop = RCLR ;
X      color = (iscolor[(int) cur_dpyno]) ? C_LBROWN : C_WHITE ;
X      if (iscolor[(int) cur_dpyno]) rop = RSRC ;
X      draw_line(suggest_x-5, CY+suggest_y-5,
X                suggest_x+5, CY+suggest_y+5, rop, color) ;
X      draw_line(suggest_x-5, CY+suggest_y+5,
X                suggest_x+5, CY+suggest_y-5, rop, color) ;
X      suggestion = -1 ;
X    }
X}
X
X
Xvoid
Xupdate_board_image(player)
Xint player ;
X{
X  int flips, i, piece, x, y ;
X 
X  show_suggestion() ;
X  for (flips = 0; flips < 4; flips++)
X    {
X      batch(IS_ON) ;
X      FOR_BOARD(i)
X        {
X          if (board.square[i] != old_board.square[i])
X            {
X              get_xy(i, &x, &y) ;
X              if (i == move) piece = board.square[i] ;
X              else
X                piece = (flips % 2) ? board.square[i] : board.square[i] * -1 ;
X              draw_piece(piece, x, CY+y, RSRC) ;
X            } 
X        }
X      batch(IS_OFF) ;
X      PAUSE ;
X    }
X  set_score() ;
X  set_turn(OPPONENT(player)) ;
X  message(TURN_MES, line) ;
X  if (show_notes)
X    if ((player == BLACK && items[(int) BLACK_PLAYS].value == COMPUTER) ||
X        (player == WHITE && items[(int) WHITE_PLAYS].value == COMPUTER))
X      {
X        SPRINTF(line, "%s: <%c-%c> note : %ld",
X                (player == BLACK) ? "Black" : "White",
X                (move & 7) + 'a', (move >> 3) + '1', note) ;
X        message(NOTES_MES, line) ;
X      }
X}
X
X
Xvoid
Xwho_wins()
X{
X  int cs, ps ;
X
X  ps = count(&board, WHITE) ;
X  cs = count(&board, BLACK) ;
X  if (ps > cs)
X    {
X      SPRINTF(line, "White wins %d-%d", ps, cs) ;
X      message(SCORE_MES, line) ;
X    }
X  else if (ps == cs)
X    {
X      SPRINTF(line,"A tie %d-%d", ps, cs) ;
X      message(SCORE_MES, line) ;
X    }
X  else
X    {
X      SPRINTF(line, "Black wins %d-%d", cs, ps) ;
X      message(SCORE_MES, line) ;
X    }
X}
END_OF_FILE
if test 12414 -ne `wc -c <'boardstuff.c'`; then
    echo shar: \"'boardstuff.c'\" unpacked with wrong size!
fi
# end of 'boardstuff.c'
fi
if test -f 'color.h' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'color.h'\"
else
echo shar: Extracting \"'color.h'\" \(1518 characters\)
sed "s/^X//" >'color.h' <<'END_OF_FILE'
X 
X/*  @(#)color.h 1.3 90/09/24
X *
X *  Colormap 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 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#define  OTH_COLOR      "othcolor"
X#define  OTH_COLORSIZE  8
X
X#define  C_WHITE    0
X#define  C_LGREY    1
X#define  C_LBROWN   2
X#define  C_BEIGE    3
X#define  C_DBROWN   4
X#define  C_BLACK    5
X#define  C_SPARE6   6
X#define  C_SPARE7   7
X
X#define oth_colorsetup(r, g, b) \
X        (r)[C_WHITE] = 255 ;  (g)[C_WHITE] = 255 ;  (b)[C_WHITE] = 255 ; \
X        (r)[C_LGREY] = 200 ;  (g)[C_LGREY] = 200 ;  (b)[C_LGREY] = 200 ; \
X        (r)[C_LBROWN] = 200 ; (g)[C_LBROWN] = 150 ; (b)[C_LBROWN] = 100 ; \
X        (r)[C_BEIGE] = 255 ;  (g)[C_BEIGE] = 240 ;  (b)[C_BEIGE] = 220 ; \
X        (r)[C_DBROWN] = 185 ; (g)[C_DBROWN] = 145 ; (b)[C_DBROWN] = 100 ; \
X        (r)[C_BLACK] = 0 ;    (g)[C_BLACK] = 0 ;    (b)[C_BLACK] = 0 ; \
X        (r)[C_SPARE6] = 0 ;   (g)[C_SPARE6] = 0 ;   (b)[C_SPARE6] = 0 ; \
X        (r)[C_SPARE7] = 0 ;   (g)[C_SPARE7] = 0 ;   (b)[C_SPARE7] = 0 ;
END_OF_FILE
if test 1518 -ne `wc -c <'color.h'`; then
    echo shar: \"'color.h'\" unpacked with wrong size!
fi
# end of 'color.h'
fi
if test -f 'events.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'events.c'\"
else
echo shar: Extracting \"'events.c'\" \(11388 characters\)
sed "s/^X//" >'events.c' <<'END_OF_FILE'
X/*LINTLIBRARY*/
X
X/*  @(#)events.c 1.7 90/10/18
X *
X *  Procedures for handling various events in 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
X#include <stdio.h>
X#include "reve.h"
X#include "color.h"
X#include "extern.h"
X
X
Xvoid
Xcheck_button_down(item)
Xenum panel_type item ;
X{
X  int n ;
X
X  n = (int) item ;
X  if (items[n].x == -1) return ;
X  if ((curx >  items[n].x) && (curx < (items[n].x + items[n].width)) &&
X      (cury >  items[n].y) && (cury < (items[n].y + items[n].height)))
X    {
X      down = nextc ;
X      itemno = n ;
X      but_inverted = itemno ;
X      draw_button((enum panel_type) itemno, C_LGREY, BUT_INVERT) ;
X    }
X}
X
X
Xvoid
Xcheck_cycle_down(item)
Xenum panel_type item ;
X{
X  int ix, n, reply ;
X
X  n = (int) item ;
X  ix = items[n].x + (3 * BWIDTH) + (2 * BGAP) - CWIDTH ;
X       if ((curx > ix) && (curx < (ix + (items[n].width / 2))) &&
X           (cury > items[n].y) && (cury < (items[n].y + items[n].height)) &&
X            nextc != RIGHT_DOWN)
X    {
X      direction = INCREMENT ;
X      down = nextc ;
X      itemno = n ;
X      draw_cycle((enum panel_type) n, C_LGREY, CY_LINVERT) ;
X    }
X  else if ((curx > ix) && (curx < (ix + items[n].width)) &&
X           (cury > items[n].y) && (cury < (items[n].y + items[n].height)) &&
X            nextc != RIGHT_DOWN)
X    {
X      direction = DECREMENT ;
X      down = nextc ;
X      itemno = n ;
X      draw_cycle((enum panel_type) n, C_LGREY, CY_RINVERT) ;
X    }
X  else if ((curx > ix) && (curx < (ix + items[n].width)) &&
X           (cury > items[n].y) && (cury < (items[n].y + items[n].height)))
X    {
X      direction = NONE ;
X      down = RIGHT_DOWN ;
X      itemno = n ;
X      reply = do_menu((enum panel_type) itemno) ;
X      if (reply)
X        {                                                   
X          nextc = RIGHT_UP ;                                
X          handle_item(reply - 1) ;
X          draw_cycle((enum panel_type) itemno, C_LGREY, CY_NORMAL) ;
X        }
X    }
X}
X
X
Xvoid
Xcheck_item_down()
X{
X  int n ;
X
X  for (n = 0; n < MAXITEMS; n++)
X    switch (items[n].type)
X      {
X        case P_BUTTON  : check_button_down((enum panel_type) n) ;
X                         break ;
X        case P_CYCLE   : check_cycle_down((enum panel_type) n) ;
X                         break ;
X        case P_MESSAGE : /* do nothing. */ ;
X      }
X}
X
X
Xvoid
Xcheck_item_up()
X{
X  if ((nextc == LEFT_UP   && down == LEFT_DOWN)   ||
X      (nextc == MIDDLE_UP && down == MIDDLE_DOWN) ||
X      (nextc == RIGHT_UP  && down == RIGHT_DOWN))
X    {
X      if (items[itemno].type == P_BUTTON && but_inverted == -1) return ;
X      handle_item(items[itemno].value) ;
X      if (items[itemno].type == P_BUTTON && items[itemno].x != -1)
X        draw_button((enum panel_type) itemno, C_LGREY, BUT_NORMAL) ;
X      else if (items[itemno].type == P_CYCLE)
X        draw_cycle((enum panel_type) itemno, C_LGREY, CY_NORMAL) ;
X    } 
X}
X
X
Xvoid
Xdo_action()
X{
X  switch (nextc)
X    {
X      case MOUSE_MOVING : draw_piece(next_player, piece_x, piece_y, RINV) ;
X                          piece_x = curx - PIECE_RAD ;
X                          piece_y = cury - PIECE_RAD ;
X                          draw_piece(next_player, piece_x, piece_y, RINV) ;
X                          break ;
X                          
X      case ENTER_WINDOW : 
X      case EXIT_WINDOW  : set_cursor(CANVASCUR) ;
X                          draw_piece(next_player, piece_x, piece_y, RINV) ;
X                          cmode = (enum cantype) ((int) cmode - 1) ;
X                          break ;
X                          
X      case LEFT_DOWN    : 
X      case LEFT_UP      :
X      case MIDDLE_DOWN  :
X      case MIDDLE_UP    :
X      case RIGHT_DOWN   :
X      case RIGHT_UP     : set_cursor(CANVASCUR) ;
X                          do_selection(nextc) ;
X    }                 
X}
X
X
Xvoid
Xdo_cycle_key(item, ch)
Xenum panel_type item ;
Xint ch ;
X{
X  int val ;
X
X  if (!validkey)
X    {
X      validkey = cur_ch ;
X      message(PANEL_MES, items[(int) item].text) ;
X    }
X  else
X    {
X      val = -1 ;
X      switch (item)
X        {
X          case BLACK_PLAYS :
X               WHITE_PLAYS : if (item == BLACK_PLAYS) curx = 0 ;
X                             else curx = BBORDER + (3*(BWIDTH+BGAP)) ;
X                             switch (ch)
X                               {
X                                 case 'c' :
X                                 case 'C' : val = 1 ;
X                                            items[(int) item].value = val ;
X                                            set_cycle(item,
X                                                      player_values[val]) ;
X                                            break ;
X                                 case 'h' :
X                                 case 'H' : val = 0 ;
X                                            items[(int) item].value = val ;
X                                            set_cycle(item,
X                                                      player_values[val]) ;
X                                            break ;
X                                 default  : return ;
X                               }
X          case DIFFICULTY     : if (ch >= '1' && ch <= '9') val = ch - '1' ;
X                                items[(int) item].value = val ;
X                                set_cycle(item, diff_values[val]) ;
X                                break ;
X          case NOTES          : switch (ch)
X                               {
X                                 case 'n' :
X                                 case 'N' : val = 0 ;
X                                            items[(int) item].value = val ;
X                                            set_cycle(item, notes_values[val]) ;
X                                            break ;
X                                 case 'y' :
X                                 case 'Y' : val = 1 ;
X                                            items[(int) item].value = val ;
X                                            set_cycle(item, notes_values[val]) ;
X                                            break ;
X                                 default  : return ;
X                               }
X        }
X      if (val != -1)
X        {
X          validkey = 0 ;
X          message(PANEL_MES, "") ;
X          items[(int) item].value = item_value = val ;
X          direction = NONE ;
X          (*items[(int) item].func)() ;
X        }
X    }
X}
X
X
Xvoid
Xdo_key_move(n1, n2)
Xint n1, n2 ;
X{
X  move = (n2 - '1') * BOARD_SIZE + (n1 - 'a') ;
X  next_player = (int) cmode - 1 ;
X  cmode = (enum cantype) ((int) cmode + 1) ;
X  make_move() ;
X  validkey = 0 ;
X}
X
X
Xvoid
Xget_xy(n, x, y)      /* Return piece coordinates given board index. */
Xint n, *x,*y ;
X{
X  *x = (n & 7) * CELL_SIZE + BBORDER + PIECE_MARGIN ;
X  *y = (n >> 3) * CELL_SIZE + BBORDER + PIECE_MARGIN ;
X}
X
X
Xvoid
Xhandle_board_event()
X{
X  switch (cmode)
X    {
X      case WHITE_START  :
X      case BLACK_START  : next_player = (int) cmode - 1 ;
X                          if (nextc == LEFT_DOWN || nextc == MIDDLE_DOWN ||
X                              nextc == RIGHT_DOWN)
X                            {
X                              set_cursor(NOCURSOR) ;
X                              piece_x = curx - BBORDER - (PIECE_RAD) ;
X                              piece_y = cury - BBORDER - (PIECE_RAD) ;
X                              draw_piece(next_player, piece_x, piece_y, RINV) ;
X                              cmode = (enum cantype) ((int) cmode + 1) ;
X                            }
X                          break ;
X      case WHITE_MOVING :
X      case BLACK_MOVING : do_action() ;
X    }
X}
X
X
Xvoid
Xhandle_event()
X{
X  process_event() ;
X
X       if (nextc == FRAME_REPAINT) init_canvas() ;
X  else if (nextc == KEYBOARD)      handle_key() ;
X  else if (nextc == EXIT_WINDOW && but_inverted != -1)
X    {
X      draw_button((enum panel_type) but_inverted, C_LGREY, BUT_NORMAL) ;
X      but_inverted = -1 ;
X      down = 0 ;
X    }
X  else if (cury > (CY + BBORDER)) handle_board_event() ;
X  else if (nextc == LEFT_UP || nextc == MIDDLE_UP || nextc == RIGHT_UP)
X    check_item_up() ;
X  else if (nextc == LEFT_DOWN || nextc == MIDDLE_DOWN || nextc == RIGHT_DOWN)
X    check_item_down() ;
X}
X
X
Xvoid
Xhandle_item(val)
Xint val ;
X{
X  items[itemno].value = item_value = val ;
X  (*items[itemno].func)() ;
X  but_inverted = -1 ;
X  down = 0 ;
X}
X
X
Xvoid
Xhandle_key()     /* Process the latest key that the user has pressed. */
X{
X  char str[9] ;  /* To display half move position. */
X  int nextc ;
X
X  if (tinput)
X    {
X      get_filename() ;
X      return ;
X    }
X  if (cur_ch == ESCAPE) validkey = 0 ;
X  if (validkey)
X    {
X      nextc = cur_ch ;
X      cur_ch = validkey ;
X    }
X  switch (cur_ch)
X    {
X      case 'B' : do_cycle_key(BLACK_PLAYS, nextc) ;    /* Cycle items. */
X                 break ;
X      case 'D' : do_cycle_key(DIFFICULTY,  nextc) ;
X                 break ;
X      case 'N' : do_cycle_key(NOTES,       nextc) ;
X                 break ;
X      case 'W' : do_cycle_key(WHITE_PLAYS, nextc) ;
X                 break ;
X
X      case 'l' : last() ;                              /* Button items. */
X                 break ;
X      case 'L' : curx = 0 ;
X                 draw_textfield() ;
X                 break ;
X      case 'n' : new_game() ;
X                 break ;
X      case 'S' : curx = BBORDER + (2*(BWIDTH+BGAP)) ;
X                 draw_textfield() ;
X                 break ;
X      case 's' : suggest() ;
X                 break ;
X      case 'u' : undo() ;
X                 break ;
X
X      case 'q' : destroy_frame() ;
X                 exit(0) ;
X
X      case '1' :
X      case '2' :
X      case '3' :
X      case '4' :
X      case '5' :
X      case '6' :
X      case '7' :
X      case '8' : if (!validkey)
X                   {
X                     validkey = cur_ch ;
X                     SPRINTF(str, "Move: %c", cur_ch) ;
X                     message(PANEL_MES, str) ;
X                   }
X                 else if (nextc >= 'a' && nextc <= 'h')
X                   {
X                     SPRINTF(str, "Move: %c%c", cur_ch, nextc) ;
X                     message(PANEL_MES, str) ;
X                     do_key_move(nextc, cur_ch) ;
X                   }
X                 else validkey = 0 ;
X                 break ;
X      case 'a' :
X      case 'b' :
X      case 'c' :
X      case 'd' :
X      case 'e' :
X      case 'f' :
X      case 'g' :
X      case 'h' : if (!validkey)
X                   {
X                     validkey = cur_ch ;
X                     SPRINTF(str, "Move: %c", cur_ch) ;
X                     message(PANEL_MES, str) ;
X                   }
X                 else if (nextc >= '1' && nextc <= '8')
X                   {
X                     SPRINTF(str, "Move: %c%c", cur_ch, nextc) ;
X                     message(PANEL_MES, str) ;
X                     do_key_move(cur_ch, nextc) ;
X                   }
X                 else validkey = 0 ;
X                 break ;
X      default  : message(PANEL_MES, "") ;
X                 validkey = 0 ;
X    }
X}
END_OF_FILE
if test 11388 -ne `wc -c <'events.c'`; then
    echo shar: \"'events.c'\" unpacked with wrong size!
fi
# end of 'events.c'
fi
if test -f 'images/button.normal.icon' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'images/button.normal.icon'\"
else
echo shar: Extracting \"'images/button.normal.icon'\" \(1933 characters\)
sed "s/^X//" >'images/button.normal.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,0x0C00,0x0000,0x0000,0x0030,
X	0x1000,0x0000,0x0000,0x0008,0x2000,0x0000,0x0000,0x0004,
X	0x4000,0x0000,0x0000,0x0002,0x4000,0x0000,0x0000,0x0002,
X	0x8000,0x0000,0x0000,0x0003,0x8000,0x0000,0x0000,0x0003,
X	0x8000,0x0000,0x0000,0x0003,0x8000,0x0000,0x0000,0x0003,
X	0x8000,0x0000,0x0000,0x0003,0x8000,0x0000,0x0000,0x0003,
X	0x8000,0x0000,0x0000,0x0003,0x8000,0x0000,0x0000,0x0003,
X	0x8000,0x0000,0x0000,0x0003,0x8000,0x0000,0x0000,0x0003,
X	0x8000,0x0000,0x0000,0x0003,0x8000,0x0000,0x0000,0x0003,
X	0x8000,0x0000,0x0000,0x0003,0x8000,0x0000,0x0000,0x0003,
X	0x8000,0x0000,0x0000,0x0003,0x8000,0x0000,0x0000,0x0003,
X	0x8000,0x0000,0x0000,0x0003,0x8000,0x0000,0x0000,0x0003,
X	0x8000,0x0000,0x0000,0x0003,0x8000,0x0000,0x0000,0x0007,
X	0x4000,0x0000,0x0000,0x0006,0x4000,0x0000,0x0000,0x000E,
X	0x2000,0x0000,0x0000,0x001C,0x1000,0x0000,0x0000,0x0038,
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.normal.icon'`; then
    echo shar: \"'images/button.normal.icon'\" unpacked with wrong size!
fi
# end of 'images/button.normal.icon'
fi
if test -f 'rev_iycp.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'rev_iycp.c'\"
else
echo shar: Extracting \"'rev_iycp.c'\" \(12937 characters\)
sed "s/^X//" >'rev_iycp.c' <<'END_OF_FILE'
X
X/*  @(#)rev_iycp.c 1.3 90/09/24
X *
X *  Copyright (C) 1990 - Yves Gallot - 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 "reve.h"
X
Xextern int damier[NIVEAUMAX][64] ;
Xextern int tacouleur, macouleur ;
Xextern int vp0, vo0 ;
X
X/*  Functions used by the "fast" alpha-beta pruning.
X *  - JePeuxJouer( niv ) and TuPeuxJouer( niv ) :
X *    Test if I Can Play or You Can Play on the Board number niv ( which is
X *    current board at depth niv ). "I" is for macouleur value ( my color )
X *    and "You" for tacouleur value ( your color ). Return TRUE or FALSE.
X *    If TRUE, put JPJ on every squares where I Can Play, or TPJ on every
X *    squares where You Can Play.
X *  - JeJoueen( x, y, niv ) and TuJouesen( x, y, niv ) :
X *    I Play square (x, y) on Board number niv and You Play square (x, y)
X *    on Board number niv. It puts piece color macouleur or tacouleur and
X *    returns pieces that must be.
X */
X
Xjepeuxjouer(niv)
Xint niv ;
X{
X  register int *d ;
X  register int x, y, posx, posy, pos8x, poscr, flag ;
X
X  d = damier[niv] ;
X  flag = FALSE ;
X  vp0 = 0 ;
X
X  for (posx = 0; posx < 8; posx++)
X    {
X      pos8x = posx << 3 ;
X      for (posy = 0; posy < 8; posy++)
X        {
X          poscr = pos8x + posy;  
X          if  ((d[poscr] == TPJ) || (d[poscr] == JPJ)) d[poscr] = FREE ;
X          if (d[poscr] == FREE)
X            {
X
X              for (x = posx + 1;
X                   (x < 7) && (d[(x << 3) + posy] == tacouleur);
X                   x++) ;
X              if ((x != posx + 1) && (d[(x << 3) + posy] == macouleur))
X                {
X                  flag = TRUE ;
X                  d[poscr] = JPJ ;
X                  vp0++ ;
X                  goto endloopj ;
X                } 
X
X              for (x = posx - 1;
X                   (x > 0) && (d[(x << 3) + posy] == tacouleur);
X                   x--) ;
X              if ((x != posx - 1) && (d[(x << 3) + posy] == macouleur))
X                {
X                  flag = TRUE ;
X                  d[poscr] = JPJ ;
X                  vp0++ ;
X                  goto endloopj ;
X                } 
X
X              for (y = posy + 1;
X                   (y < 7) && (d[pos8x + y] == tacouleur);
X                   y++) ;
X              if ((y != posy + 1) && (d[pos8x + y] == macouleur))
X                {
X                  flag = TRUE ;
X                  d[poscr] = JPJ ;
X                  vp0++ ;
X                  goto endloopj ;
X                } 
X
X              for (y = posy - 1;
X                   (y > 0) && (d[pos8x + y] == tacouleur);
X                   y--) ;
X              if ((y != posy - 1) && (d[pos8x + y] == macouleur))
X                {
X                  flag = TRUE ;
X                  d[poscr] = JPJ ;
X                  vp0++ ;
X                  goto endloopj ;
X                } 
X
X              for (x = posx + 1,  y = posy + 1; 
X                   (x < 7) && (y < 7) && (d[(x << 3) + y] == tacouleur);
X                   x++, y++) ;
X              if ((x != posx + 1) && (d[(x << 3) + y] == macouleur))
X                {
X                  flag = TRUE ;
X                  d[poscr] = JPJ ;
X                  vp0++ ;
X                  goto endloopj ;
X                }
X
X              for (x = posx - 1,  y = posy + 1; 
X                   (x > 0) && (y < 7) && (d[(x << 3) + y] == tacouleur);
X                   x--, y++) ;
X              if ((x != posx - 1) && (d[(x << 3) + y] == macouleur))
X                {
X                  flag = TRUE ;
X                  d[poscr] = JPJ ;
X                  vp0++ ;
X                  goto endloopj ;
X                }
X
X              for (x = posx + 1,  y = posy - 1; 
X                   (x < 7) && (y > 0) && (d[(x << 3) + y] == tacouleur);
X                   x++, y--) ;
X              if ((x != posx + 1) && (d[(x << 3) + y] == macouleur))
X                {
X                  flag = TRUE ;
X                  d[poscr] = JPJ ;
X                  vp0++ ;
X                  goto endloopj ;
X                }
X
X              for (x = posx - 1,  y = posy - 1; 
X                   (x > 0) && (y > 0) && (d[(x << 3) + y] == tacouleur);
X                   x--, y--) ;
X              if ((x != posx - 1) && (d[(x << 3) + y] == macouleur))
X                {
X                  flag = TRUE ;
X                  d[poscr] = JPJ ;
X                  vp0++ ;
X                }
Xendloopj: ; 
X            }
X        }
X    }
X  return flag ;
X}
X
X
Xjejoueen(px, py, niv)
Xint px, py, niv ;
X{
X  register int *d ;
X  register int x, y, posx, posy, pos8x ;
X
X  posx = px ;
X  posy = py ;
X  pos8x = posx << 3 ;
X
X  d = damier[niv] ;
X
X  d[pos8x + posy] = macouleur ;
X
X  for (x = posx + 1; (x < 7) && (d[(x << 3) + posy] == tacouleur); x++) ;
X  if ((x != posx + 1) && (d[(x << 3) + posy] == macouleur))
X    {
X      for (x = posx + 1; d[(x << 3) + posy] == tacouleur; x++)
X        d[(x << 3) + posy] = macouleur ;
X    }
X
X  for (x = posx - 1; (x > 0) && (d[(x << 3) + posy] == tacouleur); x--) ;
X  if ((x != posx - 1) && (d[(x << 3) + posy] == macouleur))
X    {
X      for (x = posx - 1; d[(x << 3) + posy] == tacouleur; x--)
X        d[(x << 3) + posy] = macouleur ;
X    }
X
X  for (y = posy + 1; (y < 7) && (d[pos8x + y] == tacouleur); y++) ;
X  if ((y != posy + 1) && (d[pos8x + y] == macouleur))
X    {
X      for (y = posy + 1; d[pos8x + y] == tacouleur; y++)
X        d[pos8x + y] = macouleur ;
X    }
X
X  for (y = posy - 1; (y > 0) && (d[pos8x + y] == tacouleur); y--) ;
X  if ((y != posy - 1) && (d[pos8x + y] == macouleur))
X    {
X      for (y = posy - 1; d[pos8x + y] == tacouleur; y--)
X        d[pos8x + y] = macouleur ;
X    }
X
X  for (x = posx + 1, y = posy + 1;
X       (x < 7) && (y < 7) && (d[(x << 3) + y] == tacouleur); x++, y++) ;
X  if ((x != posx + 1) && (d[(x << 3) + y] == macouleur))
X    {
X      for (x = posx + 1, y = posy + 1; d[(x << 3) + y] == tacouleur; x++, y++)
X        d[(x << 3) + y] = macouleur ;
X    }
X
X  for (x = posx - 1, y = posy + 1;
X       (x > 0) && (y < 7) && (d[(x << 3) + y] == tacouleur); x--, y++) ;
X  if ((x != posx - 1) && (d[(x << 3) + y] == macouleur))
X    {
X      for (x = posx - 1, y = posy + 1; d[(x << 3) + y] == tacouleur; x--, y++)
X        d[(x << 3) + y] = macouleur ;
X    }
X
X  for (x = posx + 1, y = posy - 1;
X       (x < 7) && (y > 0) && (d[(x << 3) + y] == tacouleur); x++, y--) ;
X  if ((x != posx + 1) && (d[(x << 3) + y] == macouleur))
X    {
X      for (x = posx + 1, y = posy - 1; d[(x << 3) + y] == tacouleur; x++, y--)
X        d[(x << 3) + y] = macouleur ;
X    }
X
X  for (x = posx - 1, y = posy - 1;
X       (x > 0) && (y > 0) && (d[(x << 3) + y] == tacouleur); x--, y--) ;
X  if ((x != posx - 1) && (d[(x << 3) + y] == macouleur))
X    {
X      for (x = posx - 1, y = posy - 1; d[(x << 3) + y] == tacouleur; x--, y--)
X        d[(x << 3) + y] = macouleur ;
X    }
X}
X
X
Xtupeuxjouer(niv)
Xint niv ;
X{
X  register int *d ;
X  register int x, y, posx, posy, pos8x, poscr, flag ;
X
X  d = damier[niv] ;
X  flag = FALSE ;
X  vo0 = 0 ;
X
X  for (posx = 0; posx < 8; posx++)
X    {
X      pos8x = posx << 3 ;
X      for (posy = 0; posy < 8; posy++)
X        {
X          poscr = pos8x + posy ;
X          if ((d[poscr] == TPJ) || (d[poscr] == JPJ)) d[poscr] = FREE ;
X          if (d[poscr] == FREE)
X            {
X              for (x = posx + 1;
X                   (x < 7) && (d[(x << 3) + posy] == macouleur);
X                   x++) ;
X              if ((x != posx + 1) && (d[(x << 3) + posy] == tacouleur))
X                {
X                  flag = TRUE ;
X                  d[poscr] = TPJ ;
X                  vo0++ ;
X                  goto endloopt ;
X                } 
X
X              for (x = posx - 1;
X                   (x > 0) && (d[(x << 3) + posy] == macouleur) ;
X                   x--) ;
X              if ((x != posx - 1) && (d[(x << 3) + posy] == tacouleur))
X                {
X                  flag = TRUE ;
X                  d[poscr] = TPJ ;
X                  vo0++ ;
X                  goto endloopt ;
X                } 
X
X              for (y = posy + 1;
X                   (y < 7) && (d[pos8x + y] == macouleur);
X                   y++) ;
X              if ((y != posy + 1) && (d[pos8x + y] == tacouleur))
X                {
X                  flag = TRUE ;
X                  d[poscr] = TPJ ;
X                  vo0++ ;
X                  goto endloopt ;
X                } 
X
X              for (y = posy - 1;
X                   (y > 0) && (d[pos8x + y] == macouleur);
X                   y--) ;
X              if ((y != posy - 1) && (d[pos8x + y] == tacouleur))
X                {
X                  flag = TRUE ;
X                  d[poscr] = TPJ ;
X                  vo0++ ;
X                  goto endloopt ;
X                } 
X
X              for (x = posx + 1,  y = posy + 1; 
X                   (x < 7) && (y < 7) && (d[(x << 3) + y] == macouleur);
X                   x++, y++);
X              if ((x != posx + 1) && (d[(x << 3) + y] == tacouleur))
X                {
X                  flag = TRUE ;
X                  d[poscr] = TPJ ;
X                  vo0++ ;
X                  goto endloopt ;
X                }
X
X              for (x = posx - 1,  y = posy + 1; 
X                   (x > 0) && (y < 7) && (d[(x << 3) + y] == macouleur);
X                   x--, y++) ;
X              if ((x != posx - 1) && (d[(x << 3) + y] == tacouleur))
X                {
X                  flag = TRUE ;
X                  d[poscr] = TPJ ;
X                  vo0++ ;
X                  goto endloopt ;
X                }
X
X              for (x = posx + 1,  y = posy - 1; 
X                   (x < 7) && (y > 0) && (d[(x << 3) + y] == macouleur);
X                   x++, y--) ;
X              if ((x != posx + 1) && (d[(x << 3) + y] == tacouleur))
X                {
X                  flag = TRUE ;
X                  d[poscr] = TPJ ;
X                  vo0++ ;
X                  goto endloopt ;
X                }
X
X              for (x = posx - 1,  y = posy - 1; 
X                   (x > 0) && (y > 0) && (d[(x << 3) + y] == macouleur) ;
X                   x--, y-- ) ;
X              if ((x != posx - 1) && (d[(x << 3) + y] == tacouleur))
X                {
X                  flag = TRUE ;
X                  d[poscr] = TPJ ;
X                  vo0++ ;
X                }
Xendloopt: ;
X            }
X        } 
X    }
X  return(flag) ;
X}
X
X
Xtujouesen(px, py, niv)
Xint px, py, niv ;
X{
X  register int *d ;
X  register int x, y, posx, posy, pos8x ;
X
X  posx = px ;
X  posy = py ;
X
X  pos8x = posx << 3 ;
X  d = damier[niv] ;
X  d[pos8x + posy] = tacouleur ;
X
X  for (x = posx + 1; (x < 7) && (d[(x << 3) + posy] == macouleur); x++) ;
X  if ((x != posx + 1) && (d[(x << 3) + posy] == tacouleur))
X    {
X      for (x = posx + 1; d[(x << 3) + posy] == macouleur; x++)
X        d[(x << 3) + posy] = tacouleur ;
X    }
X
X  for (x = posx - 1; (x > 0) && (d[(x << 3) + posy] == macouleur); x--) ;
X  if ((x != posx - 1) && (d[(x << 3) + posy] == tacouleur))
X    {
X      for (x = posx - 1; d[(x << 3) + posy] == macouleur; x--)
X        d[(x << 3) + posy] = tacouleur ;
X    }
X
X  for (y = posy + 1; (y < 7) && (d[pos8x + y] == macouleur); y++) ;
X  if ((y != posy + 1) && (d[pos8x + y] == tacouleur))
X    {
X      for (y = posy + 1; d[pos8x + y] == macouleur; y++)
X        d[pos8x + y] = tacouleur ;
X    }
X
X  for (y = posy - 1; (y > 0) && (d[pos8x + y] == macouleur); y--) ;
X  if ((y != posy - 1) && (d[pos8x + y] == tacouleur))
X    {
X      for (y = posy - 1; d[pos8x + y] == macouleur; y--)
X        d[pos8x + y] = tacouleur ;
X    }
X
X  for (x = posx + 1, y = posy + 1;
X       (x < 7) && (y < 7) && (d[(x << 3) + y] == macouleur);
X       x++, y++) ;
X  if ((x != posx + 1) && (d[(x << 3) + y] == tacouleur))
X    {
X      for (x = posx + 1, y = posy + 1; d[(x << 3) + y] == macouleur; x++, y++)
X        d[(x << 3) + y] = tacouleur ;
X    }
X
X  for (x = posx - 1, y = posy + 1;
X       (x > 0) && (y < 7) && (d[(x << 3) + y] == macouleur);
X       x--, y++) ;
X  if ((x != posx - 1) && (d[(x << 3) + y] == tacouleur))
X    {
X      for (x = posx - 1, y = posy + 1; d[(x << 3) + y] == macouleur; x--, y++)
X        d[(x << 3) + y] = tacouleur ;
X    }
X
X  for (x = posx + 1, y = posy - 1;
X       (x < 7) && (y > 0) && (d[(x << 3) + y] == macouleur);
X       x++, y--) ;
X  if ((x != posx + 1) && (d[(x << 3) + y] == tacouleur))
X    {
X      for (x = posx + 1, y = posy - 1; d[(x << 3) + y] == macouleur; x++, y--)
X        d[(x << 3) + y] = tacouleur ;
X    }
X
X  for (x = posx - 1, y = posy - 1;
X       (x > 0) && (y > 0) && (d[(x << 3) + y] == macouleur);
X       x--, y--) ;
X  if ((x != posx - 1) && (d[(x << 3) + y] == tacouleur))
X    {
X      for (x = posx - 1, y = posy - 1; d[(x << 3) + y] == macouleur; x--, y--)
X        d[(x << 3) + y] = tacouleur ;
X    }
X}
END_OF_FILE
if test 12937 -ne `wc -c <'rev_iycp.c'`; then
    echo shar: \"'rev_iycp.c'\" unpacked with wrong size!
fi
# end of 'rev_iycp.c'
fi
if test -f 'sunview.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'sunview.c'\"
else
echo shar: Extracting \"'sunview.c'\" \(11208 characters\)
sed "s/^X//" >'sunview.c' <<'END_OF_FILE'
X/*LINTLIBRARY*/
X
X/*  @(#)sunview.c 1.5 90/10/15
X *
X *  SunView 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 "color.h"
X#include "reve.h"
X#include "extern.h"
X#include "images.h"
X#include <suntool/sunview.h>
X#include <suntool/canvas.h>
X
Xenum gr_type gtype = GSUNVIEW ;      /* Graphics type. */
X
X#define  CURSOR_SET          (void) cursor_set
X#define  ICON_SET            (void) icon_set
X#define  MENU_SET            (void) menu_set
X#define  PW_LOCK             (void) pw_lock
X#define  PW_ROP              (void) pw_rop
X#define  PW_SETCMSNAME       (void) pw_setcmsname
X#define  PW_STENCIL          (void) pw_stencil
X#define  PW_PUTCOLORMAP      (void) pw_putcolormap
X#define  PW_REVERSEVIDEO     (void) pw_reversevideo
X#define  PW_TTEXT            (void) pw_ttext
X#define  PW_UNLOCK           (void) pw_unlock
X#define  PW_VECTOR           (void) pw_vector
X#define  PW_WRITEBACKGROUND  (void) pw_writebackground
X#define  WINDOW_DONE         (void) window_done
X#define  WINDOW_SET          (void) window_set
X
X#define  NORMALFONT          "/usr/lib/fonts/fixedwidthfonts/screen.r.12"
X#define  BOLDFONT            "/usr/lib/fonts/fixedwidthfonts/screen.b.12"
X
Xmpr_static(button_stencil_pr, 64, 64, 1, button_stencil_image) ;
Xmpr_static(button_invert_pr,  64, 64, 1, button_invert_image) ;
Xmpr_static(button_normal_pr,  64, 64, 1, button_normal_image) ;
Xmpr_static(cycle_glyph_pr,    64, 64, 1, cycle_glyph_image) ;
Xmpr_static(cycle_stencil_pr,  64, 64, 1, cycle_stencil_image) ;
Xmpr_static(cycle_linvert_pr,  64, 64, 1, cycle_linvert_image) ;
Xmpr_static(cycle_rinvert_pr,  64, 64, 1, cycle_rinvert_image) ;
Xmpr_static(icon_pr,           64, 64, 1, icon_image) ;
Xmpr_static(cicon_pr,          64, 64, 8, cicon_image) ;
Xmpr_static(white_icon_pr,     64, 64, 1, white_image) ;
Xmpr_static(black_icon_pr,     64, 64, 1, black_image) ;
X
Xmpr_static(hglass_pr,         16, 16, 1, hglass_image) ;
Xmpr_static(nocur_pr,          16, 16, 1, nocur_image) ;
X
XCanvas canvas ;
XCursor cursor[MAXCURSORS] ;
XEvent *cur_event ;
XFrame frame ;
XIcon reve_icon ;
XMenu menus[MAXMENUS] ;
XPixfont *font[MAXFONTS] ;
XPixrect *images[MAXIMAGES] ;
XPixwin *cpw ;
X
Xvoid pw_batch() ;
Xint opvals[3] ;         /* Pixrect rasterop values. */
X
X
Xvoid
Xbatch(state)            /* Turn graphics batching on or off. */
Xenum bltype state ;
X{
X  switch (state)
X    {
X      case IS_ON  : pw_batch_on(cpw) ;
X                    break ;
X      case IS_OFF : pw_batch_off(cpw) ;
X    }
X}
X
X
X/*ARGSUSED*/
Xvoid
Xcanvas_proc(canvas, event)
XCanvas canvas ;
XEvent *event ;
X{
X  cur_event = event ;
X  process_event() ;       /* Determine what kind of event it is. */
X  handle_event() ;        /* And do the appropriate action. */
X}
X
X
Xvoid
Xclose_frame()        /* Iconise reve window. */
X{
X  WINDOW_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  PW_WRITEBACKGROUND(cpw, x, y, width, height, PIX_SRC | PIX_COLOR(color)) ;
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] = menu_create(MENU_FONT, font[(int) NFONT], 0) ;
X  do
X    {
X      if (values[i] != NULL)
X        MENU_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 panel_type mtype ;
X{
X  int menuno ;
X
X  menuno = (int) mtype - (int) BLACK_PLAYS ;
X  return((int) menu_show(menus[menuno], canvas,
X                          canvas_window_event(canvas, cur_event), 0)) ;
X}
X
X
Xvoid
Xdraw_image(x, y, width, height, image)
Xint x, y, width, height ;               
Xenum image_type image ;   
X{                        
X  PW_ROP(cpw, x, y, width, height, PIX_SRC | PIX_DST,
X         images[(int) image], 0, 0) ;
X}
X
X
Xvoid
Xdraw_line(x1, y1, x2, y2, op, color)
Xint x1, y1, x2, y2, color ;
Xenum optype op ;
X{
X  int rop ;
X
X  rop = opvals[(int) op] ;
X  PW_VECTOR(cpw, x1, y1, x2, y2, rop | PIX_COLOR(color), 1) ;
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 rop ;
X
X  rop = opvals[(int) op] | PIX_COLOR(color) ;
X  PW_STENCIL(cpw, x, y, width, height, rop,
X             images[(int) stencil], 0, 0, images[(int) image], 0, 0) ;
X}
X
X
Xvoid
Xdraw_text(x, y, ftype, color, str)
Xenum font_type ftype ;
Xint x, y, color ;
Xchar *str ;
X{
X  PW_TTEXT(cpw, x, y, PIX_SRC | PIX_COLOR(color), font[(int) ftype], str) ;
X}
X
X
XPixfont *
Xget_font(name)
Xchar *name ;
X{
X  Pixfont *f ;
X
X  f = pf_open(name) ;
X  if (f == NULL) f = pf_default() ;
X  if (f == NULL)
X    {
X      perror("couldn't get the default font.") ;
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  struct pr_size size ;
X
X  size = pf_textwidth(strlen(str), font[(int) ftype], str) ;
X  return(size.x) ;
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]->pf_defaultsize.y ;
X  nfont_height = font[(int) NFONT]->pf_defaultsize.y ;
X}
X
X
Xinit_ws_type()
X{
X  if (getenv("WINDOW_PARENT") == NULL)
X    {
X      FPRINTF(stderr,"%s: Not a native SunView window\n", progname) ;
X      return -1 ;
X    }
X  move_delta = 5 ;      /* Delta for computer animate move. */
X  cur_dpyno = DPY1 ;
X  return 0 ;
X}
X
X
Xstatic void
Xload_colors()      /* Create and load reve color map. */
X{
X  Pixwin *frame_pw ;
X  char colorname[CMS_NAMESIZE] ;
X  u_char red[OTH_COLORSIZE], green[OTH_COLORSIZE], blue[OTH_COLORSIZE] ;
X
X  iscolor[(int) cur_dpyno] = (cpw->pw_pixrect->pr_depth == 8) ? 1 : 0 ;
X  SPRINTF(colorname, "%s%D", OTH_COLOR, getpid()) ;
X  PW_SETCMSNAME(cpw, colorname) ;
X
X  oth_colorsetup(red, green, blue) ;
X  PW_PUTCOLORMAP(cpw, 0, OTH_COLORSIZE, red, green, blue) ;
X  if (inv_video) PW_REVERSEVIDEO(cpw, 0, OTH_COLORSIZE) ;
X
X  if (iscolor)
X    {
X      frame_pw = (Pixwin *) window_get(frame, WIN_PIXWIN) ;
X      PW_SETCMSNAME(frame_pw, colorname) ;
X      PW_PUTCOLORMAP(frame_pw, 0, OTH_COLORSIZE, red, green, blue) ;
X    }
X}
X
X
Xvoid
Xlock_screen(state)   /* Turn graphics locking on or off. */
Xenum bltype state ;
X{
X  static struct rect r = { 0, 0, TOTAL_WIDTH+1, TOTAL_WIDTH+1 } ;
X
X  switch (state)
X    {
X      case IS_ON  : PW_LOCK(cpw, &r) ;
X                    break ;
X      case IS_OFF : PW_UNLOCK(cpw) ;
X    }
X}
X
X
Xvoid
Xmake_canvas()               /* Create canvas for game board. */
X{
X  canvas = window_create(frame, CANVAS,
X                         CANVAS_RETAINED, FALSE,
X                         WIN_HEIGHT,      TOTAL_HEIGHT,
X                         WIN_WIDTH,       TOTAL_WIDTH,
X                         WIN_CONSUME_PICK_EVENTS,
X                           MS_LEFT, MS_MIDDLE, MS_RIGHT,
X                           LOC_MOVE, LOC_DRAG, LOC_TRAJECTORY,
X                           LOC_WINENTER, LOC_WINEXIT,
X                           0,
X                         WIN_CONSUME_KBD_EVENTS,
X                           KBD_USE, KBD_DONE, WIN_ASCII_EVENTS, WIN_UP_EVENTS,
X                           0,
X                         WIN_EVENT_PROC, canvas_proc,
X                         0) ;
X  cpw = (Pixwin *) window_get(canvas, CANVAS_PIXWIN) ;
X  cursor[(int) CANVASCUR] = window_get(canvas, WIN_CURSOR) ;
X  CURSOR_SET(cursor[(int) CANVASCUR], CURSOR_OP, PIX_SRC ^ PIX_DST, 0) ;
X  cursor[(int) HOURGLASS] = cursor_create(CURSOR_IMAGE, &hglass_pr, 0) ;
X  CURSOR_SET(cursor[(int) HOURGLASS], CURSOR_OP, PIX_SRC ^ PIX_DST, 0) ;
X  cursor[(int) NOCURSOR]  = cursor_create(CURSOR_IMAGE, &nocur_pr, 0) ;
X  CURSOR_SET(cursor[(int) NOCURSOR], CURSOR_OP, PIX_SRC ^ PIX_DST, 0) ;
X  load_colors() ;
X
X  images[(int) BUT_STENCIL] = &button_stencil_pr ;
X  images[(int) BUT_INVERT]  = &button_invert_pr ;
X  images[(int) BUT_NORMAL]  = &button_normal_pr ;
X  images[(int) CY_NORMAL]   = &cycle_glyph_pr ;
X  images[(int) CY_STENCIL]  = &cycle_stencil_pr ;
X  images[(int) CY_LINVERT]  = &cycle_linvert_pr ;
X  images[(int) CY_RINVERT]  = &cycle_rinvert_pr ;
X  images[(int) P_WHITE]     = &white_icon_pr ;
X  images[(int) P_BLACK]     = &black_icon_pr ;
X}
X
X
Xvoid
Xmake_frame(argc, argv)      /* Create reve window. */
Xint argc ;
Xchar *argv[] ;
X{
X  opvals[(int) RCLR] = PIX_CLR ;
X  opvals[(int) RSRC] = PIX_SRC ;
X  opvals[(int) RINV] = PIX_SRC ^ PIX_DST ;
X
X  frame = window_create((Window) NULL,     FRAME,
X                         FRAME_ICON,       reve_icon,
X                         FRAME_LABEL,      line,
X                         FRAME_NO_CONFIRM, TRUE,
X                         WIN_ERROR_MSG,    "Can't create window.",
X                         FRAME_ARGS,       argc, argv,
X                         0) ;
X}
X
X
Xvoid
Xmake_icon()
X{
X  reve_icon = icon_create(ICON_IMAGE, &icon_pr, 0) ;
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 (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    }
X  else if (event_is_ascii(cur_event))
X    {
X      cur_ch = id ;
X      nextc = KEYBOARD ;
X    }
X  else if (id == KBD_DONE || id == LOC_WINEXIT ||
X           id == WIN_STOP || id == LOC_RGNEXIT) nextc = EXIT_WINDOW ;
X  else if (id == LOC_WINENTER || id == LOC_RGNENTER) nextc = ENTER_WINDOW ;
X  else if (id == LOC_MOVE || id == LOC_DRAG || id == LOC_TRAJECTORY)
X    nextc = MOUSE_MOVING ;
X  else if (id == WIN_REPAINT) nextc = FRAME_REPAINT ;
X}
X
X
Xvoid
Xset_cursor(ctype)
Xenum curtype ctype ;
X{
X  WINDOW_SET(canvas, WIN_CURSOR, cursor[(int) ctype], 0) ;
X}
X
X
X/*ARGSUSED*/
Xvoid
Xstart_tool(dtype)      /* Display window and start the notifier. */
Xenum disp_type dtype ;
X{
X  if (iscolor)
X    {
X      reve_icon = (Icon) window_get(frame, FRAME_ICON) ;
X      ICON_SET(reve_icon, ICON_IMAGE, &cicon_pr, 0) ;
X      WINDOW_SET(frame, FRAME_ICON, reve_icon, 0) ;
X    }
X  window_fit(frame) ;
X  window_main_loop(frame) ;
X}
END_OF_FILE
if test 11208 -ne `wc -c <'sunview.c'`; then
    echo shar: \"'sunview.c'\" unpacked with wrong size!
fi
# end of 'sunview.c'
fi
echo shar: End of archive 5 \(of 7\).
cp /dev/null ark5isdone
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