home *** CD-ROM | disk | FTP | other *** search
-
- /* @(#)reve.h 1.26 91/11/13
- *
- * Definitions used by the reve program.
- *
- * Copyright (C) 1990, 1991 - Rich Burridge & Yves Gallot.
- * All rights reserved.
- *
- * Permission is granted to copy this source, for redistribution
- * in source form only, provided the news headers in "substantially
- * unaltered format" are retained, the introductory messages are not
- * removed, and no monies are exchanged.
- *
- * Permission is also granted to copy this source, without the
- * news headers, for the purposes of making an executable copy by
- * means of compilation, provided that such copy will not be used
- * for the purposes of competition in any othello tournaments, without
- * prior permission from the authors.
- *
- * No responsibility is taken for any errors on inaccuracies inherent
- * either to the comments or the code of this program, but if reported
- * (see README file), then an attempt will be made to fix them.
- */
-
- #include <stdio.h>
- #include <sys/types.h>
-
- #ifdef SYSV
- #include <string.h>
- #include <sys/times.h>
- #else
- #include <strings.h>
- #include <sys/time.h>
- #endif /*SYSV*/
-
- /* For all function declarations, if ANSI then use a prototype. */
-
- #if defined(__STDC__)
- #define P(args) args
- #else /* ! __STDC__ */
- #define P(args) ()
- #endif /* STDC */
-
- #define ALARM (void) alarm /* To make lint happy. */
- #define CLOSE (void) close
- #define DUP2 (void) dup2
- #define FCLOSE (void) fclose
- #define FFLUSH (void) fflush
- #define FGETS (void) fgets
- #define FSEEK (void) fseek
- #define FPRINTF (void) fprintf
- #define GETHOSTNAME (void) gethostname
- #define GETTIMEOFDAY (void) gettimeofday
- #define IOCTL (void) ioctl
- #define KILL (void) kill
- #define MEMCPY (void) memcpy
- #define PCLOSE (void) pclose
- #define PIPE (void) pipe
- #define POLL (void) poll
- #define PRINTF (void) printf
- #define PUTC (void) putc
- #define READ (void) read
- #define SSCANF (void) sscanf
- #define SELECT (void) select
- #define SETJMP (void) setjmp
- #define SIGNAL (void) signal
- #define SPRINTF (void) sprintf
- #define STRCAT (void) strcat
- #define STRCPY (void) strcpy
- #define STRNCAT (void) strncat
- #define STRNCPY (void) strncpy
- #define WRITE (void) write
-
- #define BBORDER 15 /* Width of the reve border. */
- #define BOARD_SIZE 8 /* 8x8 playing board */
- #define BGAP 10 /* Width of the gap between buttons. */
- #define BHEIGHT 32 /* Height of a reve button item. */
- #define BWIDTH 64 /* Width of a reve button item. */
- #define CGAP 4 /* Size of the gap for a cycle item. */
- #define CHEIGHT 20 /* Height of a reve cycle item. */
- #define CHOICEGAP 5 /* Gap between choices in a choice item. */
- #define CLHEIGHT 32 /* Height of a reve clock item. */
- #define CLWIDTH 64 /* Width of a reve clock item. */
- #define CWIDTH 32 /* Width of a reve cycle item. */
- #define MAXBOARDSIZE 750 /* Maximum size of reve game board. */
- #define MAXPRAD 32 /* Maximum game board piece radius. */
- #define MINBOARDSIZE 200 /* Minimum size of reve game board. */
- #define NOBUTS 6 /* Number of reve buttons. */
- #define NOPROWS 11 /* Number of rows of items on property win. */
- #define PIECE_MARGIN 8
- #define PIECE_RAD (CELL_SIZE / 2 - PIECE_MARGIN)
- #define SHEIGHT 16 /* Height of a game board special symbol. */
- #define SWIDTH 16 /* Width of a game board special symbol. */
-
- #define BOARD_DIM (8 * CELL_SIZE) + (2 * BBORDER)
- #define CELL_SIZE 54
- #define NOROWS 7 /* Number of rows of reve items. */
- #define PANEL_HEIGHT ((NOROWS*BHEIGHT) + ((NOROWS-1)*BGAP) + (2*BBORDER))
- #define PANEL_WIDTH ((NOBUTS*BWIDTH) + ((NOBUTS-1)*BGAP) + (2*BBORDER))
-
- /* States that the the Reve squares can be in. */
- #define BLACK (-1) /* Piece definitions. */
- #define FREE 0
- #define WHITE 1
- #define JPJ 2 /* A square where the computer can play. */
- #define TPJ (-2) /* A square where the opponent can play. */
-
- #define FALSE 0 /* Boolean definitions. */
- #define TRUE 1
-
- #define HUMAN 0 /* Player definitions. */
- #define COMPUTER 1
-
- #define BACKSPACE 8 /* Used for filename construction. */
- #define DEL 127
- #define LINEFEED 13
- #define RETURN 10
-
- #define CTL(n) n - 96 /* Control characters. */
- #define ESCAPE 27 /* ASCII escape character. */
- #define EQUAL(a, b) !strncmp(a, b, strlen(b))
- #define FOR_BOARD(i) for (i = 0; i < 64; i++)
- #define HELP_COLS 80 /* Number of columns in help window. */
- #define HELP_ROWS 60 /* Number of rows in help window. */
- #define ICONHEIGHT 64 /* Height in pixels for reve icon. */
- #define ICONWIDTH 64 /* Width in pixels of reve icon. */
- #define INC argc-- ; argv++ ;
- #define INIT_DEPTH 1
- #define ISMOVE(pos, player) \
- (nextmove(pos, NOMOVE, (BOARD *) NULL, player) != NOMOVE)
- #define MAXCHOICES 7 /* Limit on number of choices for cyclic. */
- #define MAXCURSORS 3 /* Maximum number of cursor types. */
- #define MAXDIFF 9 /* Number of levels of difficulty. */
- #define MAXFONTS 4 /* Maximum number of font types. */
- #define MAXIMAGES 13 /* Maximum number of image types. */
- #define MAXITEMS 33 /* Number of different panel items. */
-
- #ifndef MAXLINE
- #define MAXLINE 120 /* Length of character strings. */
- #endif /*!MAXLINE*/
-
- #define MAXPAGES 12 /* Maximum number of pages in reve help file. */
- #define MAX_PROFMAX 60 /* Maximum search depth. */
- #define NIVEAUMAX 25 /* Maximum possible depth. */
-
- #ifdef NOINDEX
- #define index strchr
- #endif /*NOINDEX*/
-
- #define NOMOVE -1
- #define OPPONENT(p) p * -1
-
- #ifdef SYSV
-
- /* SysV (at least 5.2) does not support usleep. Makes little difference. */
-
- #ifdef sco
- #define PAUSE nap(500) /* 0.5 seconds */
- #else /*sco*/
- #define PAUSE sleep(1)
- #endif /*sco*/
- #else /*SYSV*/
- #define PAUSE usleep(500000) /* 0.5 second. */
- #endif /*SYSV*/
-
- #define PROPS_HEIGHT ((NOPROWS*BHEIGHT) + ((NOPROWS-1)*BGAP) + (2*BBORDER))
- #define PROPS_WIDTH ((NOBUTS*BWIDTH) + ((NOBUTS-1)*BGAP) + (2*BBORDER))
- #define PSIZE 40 /* Diameter of playing piece. */
-
- #define B_COLOR(c) (iscolor ? c : C_BLACK)
- #define W_COLOR(c) (iscolor ? c : C_WHITE)
-
- #define TICKHEIGHT 16 /* Height of the tick toggle box. */
- #define TICKWIDTH 16 /* Width of the tick toggle box. */
-
- #ifndef EDGENAME
- #define EDGENAME "reve.edgetable"
- #endif /*!EDGENAME*/
-
- #ifndef HELPNAME
- #define HELPNAME "reve.help"
- #endif /*!HELPNAME*/
-
- #ifndef REVEPROC
- #define REVEPROC "reve_proc"
- #endif /*!REVEPROC*/
-
- #ifndef INT_SIGNAL
- #define SIGRET void
- #else
- #define SIGRET int
- #endif /*!INT_SIGNAL*/
-
- #define VINVUL 50
-
- #define CP_WHITE 0 /* Computer plays: choices. */
- #define CP_BLACK 1
- #define CP_NEITHER 2
- #define CP_BOTH 3
-
- /* Aliases for the property sheet item values. */
- #define ANIMATION items[(int) OPT_ANIM].value
- #define DO_BESTMOVE items[(int) OPT_BEST].value
- #define DO_LAST items[(int) OPT_LAST].value
- #define SHOW_NOTES items[(int) OPT_EVAL].value
- #define DO_NUMBER items[(int) OPT_NUM].value
- #define QUICKGAME items[(int) OPT_FLIP].value
- #define SHOW_LEGAL items[(int) OPT_MOVE].value
- #define DO_CLOCK items[(int) OPT_CLK].value
-
- /* Various pseudo events used by the Reve program. */
- #define BOARD_REPAINT 100 /* Game board window needs repainting. */
- #define PANEL_REPAINT 101 /* Control panel window needs repainting. */
- #define PROPS_REPAINT 102 /* Property window needs repainting. */
- #define HELP_REPAINT 103 /* Help window needs repainting. */
- #define ENTER_WINDOW 104 /* Mouse has entered the reve window. */
- #define EXIT_WINDOW 105 /* Mouse has exited reve window. */
- #define LEFT_DOWN 106 /* Left mouse button was depressed. */
- #define LEFT_UP 107 /* Left mouse button was debounced. */
- #define MIDDLE_DOWN 108 /* Middle mouse button was depressed. */
- #define MIDDLE_UP 109 /* Middle mouse button was debounced. */
- #define RIGHT_DOWN 110 /* Right mouse button was depressed. */
- #define RIGHT_UP 111 /* Right mouse button was debounced. */
- #define KEYBOARD 112 /* Keyboard character has been pressed. */
- #define MOUSE_MOVING 113 /* Mouse is moving. */
- #define IGNORE_EVENT 114 /* No interest in this event. */
-
- /* Batch, last move, locking or show all direction (ON or OFF). */
- enum bltype { IS_OFF, IS_ON } ;
-
- /* Reve move status. */
- enum cantype { BLACK_START, BLACK_MOVING,
- WHITE_START, WHITE_MOVING, GAME_OVER } ;
-
- /* Current cursor type. */
- enum curtype { CANVASCUR, HOURGLASS, NOCURSOR } ;
-
- enum disp_type { XBLACK, XBOTH, XWHITE } ; /* Possible displays. */
-
- enum font_type { BFONT, GFONT, HFONT, NFONT} ; /* Text font definitions. */
-
- enum gr_type { GSUNVIEW, GTTY, GX11, GXVIEW } ; /* Graphical systems. */
-
- /* Different types of graphic images. */
- enum image_type { BUT_NORMAL, BUT_INVERT, BUT_STENCIL,
- CY_NORMAL, CY_LINVERT, CY_RINVERT, CY_STENCIL,
- TOGGLE_ON, TOGGLE_OFF, P_WHITE, P_BLACK,
- S_MOVE, S_SUGGEST } ;
-
- /* Different types of panel items. */
- enum item_type { P_BUTTON, P_CHOICE, P_CLOCK, P_CYCLE, P_MESSAGE, P_TOGGLE } ;
-
- /* XView reve_proc move operations. */
- enum move_type { M_BEST, M_MOVE, M_PROFMAX, M_SUGGESTION, M_TIME } ;
-
- /* Different panel items. */
- enum panel_type { LOAD_BUT, MOVES_BUT, NEW_GAME_BUT, HELP_BUT,
- REDO_BUT, PROPS_BUT, SAVE_BUT, SUGGEST_BUT,
- PRINT_BUT, STOP_BUT, UNDO_BUT, CANCEL_BUT,
- QUIT_BUT, BLACK_PLAYS, WHITE_PLAYS, BLACK_CLOCK,
- WHITE_CLOCK, PANEL_MES,
- EVAL_MES, SCORE_MES, TURN_MES, COMP_CHOICE,
- DIFF_CHOICE, MAX_DEPTH, OPT_ANIM, OPT_BEST,
- OPT_LAST, OPT_EVAL, OPT_NUM, OPT_FLIP,
- OPT_MOVE, OPT_CLK, HELP_PAGE } ;
-
- /* X resources used by reve. */
- enum res_type { R_ANIMATE, R_BESTMOVE, R_BOARDSIZE, R_CLOCK,
- R_DIFFICULTY,
- R_LAST, R_LEGALMOVE, R_LOG, R_NOTES,
- R_NUMBER, R_QUICK, R_PANELC, R_BOARDC,
- R_BOARDBC, R_GRIDC, R_TEXTC, R_ITEMC,
- R_BSTONEC, R_WSTONEC, R_PROPS, R_HELP,
- R_BFONT, R_GFONT, R_HFONT, R_NFONT,
- R_BSTONEN, R_WSTONEN, R_PCMD, R_OPPICON,
- R_OPPBELL, R_OPPRAISE } ;
-
- enum set_type { INCREMENT, DECREMENT, NONE } ; /* Cycle directions. */
-
- enum optype { RCLR, RINV, RSRC } ; /* Rasterop codes. */
-
- enum playtype { PLAY_BLACK, PLAY_WHITE } ; /* What the computer is playing. */
-
- enum win_type { W_BOARD, W_HELP, W_PANEL, W_PROPS } ; /* Window types. */
-
- extern char *getenv(), *getlogin(), *index(), *malloc() ;
- extern void exit() ;
-
- typedef struct {
- int square[64] ;
- int player ;
- int move ;
- int moves_left ;
- long note ;
- time_t timeleft ;
- } BOARD ;
-
- struct iteminfo { /* Item information record. */
- enum win_type wtype ; /* Which window the item goes in. */
- enum item_type type ; /* Item type. */
- int lx ; /* X position of the label for this item. */
- int ly ; /* Y position of the label for this item. */
- char label[30] ; /* Label for this item (possibly NULL). */
- int x ; /* X position of this panel item. */
- int y ; /* Y position of this panel item. */
- int width ; /* Width of this panel item. */
- int height ; /* Height of this panel item. */
- char text[60] ; /* Text string associated with this item. */
- int value ; /* Current value of item. */
- char **options ; /* Pointer to list of choice strings. */
- int nopts ; /* Number of options in list. */
- void (*func)() ; /* Function to obey for this panel item. */
- } ;
-
- struct reve_in { /* Input supplied on standard input to reve_proc. */
- enum move_type type ;
- int board[64] ;
- int player ;
- int level ;
- time_t timeleft ;
- } ;
-
- struct reve_out { /* Results written to standard output by reve_proc. */
- enum move_type type ;
- int move ;
- int note ;
- int depth ;
- } ;
-
- FILE *find_file P((char *)) ;
-
- char *get_resource P((enum res_type)) ;
- char *getuserhost P(()) ;
-
- int check P((int)) ;
- int count P((BOARD *, int)) ;
- int formfliplist P((int, int)) ;
- int fork_child P(()) ;
- int get_bool_resource P((enum res_type, int *)) ;
- int get_int_resource P((enum res_type, int *)) ;
- int get_str_resource P((enum res_type, char *)) ;
- int get_strwidth P((enum font_type, char *)) ;
- int init_ws_type P(()) ;
- int is_local P(()) ;
- int legal P((int, int, BOARD *)) ;
- int jejoueen P((int, int, int)) ;
- int jepeuxjouer P((int)) ;
- int load_move P((int, int)) ;
- int main P((int, char **)) ;
- int play_reve P((int *, int, int, int *, long *)) ;
- int sandwich P((int)) ;
- int tujouesen P((int, int, int)) ;
- int tupeuxjouer P((int)) ;
- int valid_move P((BOARD *, int)) ;
-
- long evalue P((int)) ;
-
- void animate_move P((int)) ;
- void batch P((enum bltype)) ;
- void beep P(()) ;
- void check_button_down P((enum panel_type)) ;
- void check_choice_down P((enum panel_type)) ;
- void check_cycle_down P((enum panel_type)) ;
- void check_item_down P(()) ;
- void check_item_up P(()) ;
- void check_toggle_down P((enum panel_type)) ;
- void close_reve P(()) ;
- void color_area P((enum win_type, int, int, int, int, int)) ;
- void connect_io P(()) ;
- void create_menu P(()) ;
- void destroy_reve P(()) ;
- void display_help P(()) ;
- void display_time P((int)) ;
- void do_action P(()) ;
- void do_edit P(()) ;
- void do_help P(()) ;
- void do_key P((int, int)) ;
- void do_key_move P((int, int)) ;
- void do_move P((int)) ;
- void do_opponent_move P((int)) ;
- void do_props P(()) ;
- void do_selection P((int)) ;
- void do_stop P(()) ;
- void do_suggest P((int, int, int, enum bltype)) ;
- void domove P((BOARD *, int, BOARD *, int)) ;
- void done P(()) ;
- void draw_button P((enum win_type, enum panel_type,
- int, enum image_type)) ;
- void draw_choice P((enum win_type, enum panel_type, int)) ;
- void draw_clock P((enum win_type, enum panel_type, int)) ;
- void draw_cycle P((enum win_type, enum panel_type,
- int, enum image_type)) ;
- void draw_cycle_item P((enum win_type, enum panel_type,
- int, enum image_type)) ;
- void draw_filename P((char *)) ;
- void draw_image P((enum win_type, int, int, int, int,
- enum image_type)) ;
- void draw_line P((enum win_type, int, int, int, int,
- enum optype, int)) ;
- void draw_outline P((int, enum bltype)) ;
- void draw_piece P((int, int, int, enum optype)) ;
- void draw_rect P((enum win_type, int, int, int, int,
- enum optype, int)) ;
- void draw_square P((int, enum bltype, int)) ;
- void draw_stencil P((enum win_type, int, int, int, int, enum optype,
- int, enum image_type, enum image_type)) ;
- void draw_symbol P((enum image_type, int, enum bltype)) ;
- void draw_text P((enum win_type, int, int, enum font_type,
- int, char *)) ;
- void draw_textfield P(()) ;
- void draw_toggle P((enum win_type, enum panel_type, int)) ;
- void end_msgs P(()) ;
- void generate_graphics P((int, char **)) ;
- void get_addrs P((char *, char *)) ;
- void get_display P((int, char **)) ;
- void get_filename P(()) ;
- void get_options P((int, char **)) ;
- void get_xy P((int, int *, int *)) ;
- void getparam P((char *, char **, char *)) ;
- void handle_board_event P(()) ;
- void handle_event P(()) ;
- void handle_item P((int)) ;
- void handle_key P(()) ;
- void init_canvas P(()) ;
- void init_clocks P(()) ;
- void init_edge_table P(()) ;
- void init_help_file P((char *)) ;
- void init_fonts P(()) ;
- void init_graphics P((int *, char **)) ;
- void initboard P(()) ;
- void initialise P(()) ;
- void invite_remote P(()) ;
- void load_and_move P(()) ;
- void load_game P(()) ;
- void load_resources P(()) ;
- void lock_screen P((enum bltype)) ;
- void make_canvas P(()) ;
- void make_frame P((int, char **)) ;
- void make_help_window P((int, char **)) ;
- void make_icon P(()) ;
- void make_message P((enum win_type, enum panel_type)) ;
- void make_move P(()) ;
- void make_pieces P((int, int)) ;
- void message P((enum panel_type, char *)) ;
- void nap_upto P((int)) ;
- void new_game P(()) ;
- void open_ctl P(()) ;
- void open_reve P(()) ;
- void open_socket P(()) ;
- void opponent_move P((int)) ;
- void opt_toggle P((int *)) ;
- void paint_all P(()) ;
- void paint_board P(()) ;
- void paint_help P(()) ;
- void paint_help_text P(()) ;
- void paint_panel P(()) ;
- void paint_prop_sheet P(()) ;
- void position_popup P(()) ;
- void print_game P(()) ;
- void process_event P(()) ;
- void raise_reve P(()) ;
- void read_resources P(()) ;
- void read_from_reve P((int)) ;
- void read_from_sock P((int)) ;
- void read_str P((char **, char *)) ;
- void redo P(()) ;
- void redo_move P((int)) ;
- void remove_textfield P(()) ;
- void reset_clock P((int)) ;
- void reset_time P((time_t)) ;
- void save_game_to P((FILE *)) ;
- void save_game P(()) ;
- void set_computer P((int)) ;
- void set_config P((enum disp_type)) ;
- void set_cursor P((enum curtype)) ;
- void set_cycle P((enum win_type, enum panel_type, char *)) ;
- void set_display_types P(()) ;
- void set_eval P((int, int, long)) ;
- void set_frame P((enum win_type, int)) ;
- void set_option P(()) ;
- void set_score P(()) ;
- void set_timer P(()) ;
- void set_turn P((int)) ;
- void show_all P((enum bltype)) ;
- void show_all_moves P(()) ;
- void show_best P((int, long)) ;
- void show_last P((int, enum bltype)) ;
- void show_number P((int, int, enum bltype)) ;
- void start_msgs P(()) ;
- void start_tool P((enum disp_type)) ;
- void suggest P(()) ;
- void think P(()) ;
- void undo P(()) ;
- void undo_move P((int)) ;
- void update_board_image P((int, int)) ;
- void update_clock P((int, int)) ;
- void update_pieces P((int, int)) ;
- void usage P(()) ;
- void who_wins P(()) ;
- void write_to_reve P((enum move_type, int *, int, int)) ;
- void write_to_sock P((int, int)) ;
-