home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1994 March / Source_Code_CD-ROM_Walnut_Creek_March_1994.iso / compsrcs / games / volume13 / xmake5 / part02 < prev    next >
Encoding:
Internet Message Format  |  1992-01-12  |  55.7 KB

  1. Path: uunet!zephyr.ens.tek.com!master!saab!billr
  2. From: billr@saab.CNA.TEK.COM (Bill Randle)
  3. Newsgroups: comp.sources.games
  4. Subject: v13i011:  xmake5 - connect five-in-a-row game, Part02/03
  5. Message-ID: <2161@masterCNA.TEK.COM>
  6. Date: 13 Dec 91 22:21:33 GMT
  7. Sender: news@masterCNA.TEK.COM
  8. Lines: 1704
  9. Approved: billr@saab.CNA.TEK.COM
  10.  
  11. Submitted-by: hsiehch@SPUNKY.CS.NYU.EDU (Chih-Hung Hsieh)
  12. Posting-number: Volume 13, Issue 11
  13. Archive-name: xmake5/Part02
  14. Environment: C++, X11, curses
  15.  
  16.  
  17.  
  18. #! /bin/sh
  19. # This is a shell archive.  Remove anything before this line, then unpack
  20. # it by saving it into a file and typing "sh file".  To overwrite existing
  21. # files, type "sh file -c".  You can also feed this as standard input via
  22. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  23. # will see the following message at the end:
  24. #        "End of archive 2 (of 3)."
  25. # Contents:  Makefile bdconst.h debug.inc drawing.c helptext.C make5.C
  26. #   make5.xbm record.c select.C xmake5.6 xmake5.doc
  27. # Wrapped by billr@saab on Fri Dec 13 14:14:56 1991
  28. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  29. if test -f 'Makefile' -a "${1}" != "-c" ; then 
  30.   echo shar: Will not clobber existing file \"'Makefile'\"
  31. else
  32. echo shar: Extracting \"'Makefile'\" \(2688 characters\)
  33. sed "s/^X//" >'Makefile' <<'END_OF_FILE'
  34. X#! /bin/sh
  35. X#
  36. X# Makefile for xmake5 and cmake5.
  37. X#
  38. X# The folllowing directory and file names could be changed.
  39. X
  40. XSCOREDIR = ./Score
  41. X#     where to put the high score file and its locker
  42. X
  43. XSCORE_F = $(SCOREDIR)/Make5.Score
  44. X#     the high score file
  45. X
  46. XLOCK_F  = $(SCOREDIR)/Make5.Score.lock
  47. X#     the locker for the high score file, to prevent concurrent write
  48. X
  49. XBINDIR   = ./Bin
  50. X#     where to put the executable "xmake5" and "cmake5"
  51. X
  52. XMANDIR   = ./Man
  53. X#     where to put the man pages: "xmake5.6" and "cmake5.6"
  54. X
  55. XMAILER   = /usr/ucb/mail -s Make5.Record
  56. X#     the program that mails move records from cmake5
  57. X
  58. XCC    = cc
  59. XCPP    = CC
  60. X#     You might want to use "gcc" and "g++".
  61. X
  62. X# ----------------------------------------------------------------
  63. X# Usually, you do not have to change anything below.
  64. X
  65. X
  66. XFILE_DEF = -DSCORE_FILE='"$(SCORE_F)"' \
  67. X       -DLOCK_FILE='"$(LOCK_F)"'  \
  68. X       -DMAIL_COMMAND='"$(MAILER)"'
  69. X
  70. XXLIB    = -lXaw -lXmu -lXt -lXext -lX11
  71. X
  72. XDEBUG    = -O
  73. X
  74. XSOURCE    = xmake5.c drawing.c xmake5.h record.c cmake5.C \
  75. X          make5.xbm board.xbm printhelp.c helptext.C \
  76. X      make5.C  select.C  debug.inc bdconst.h   initbd.C \
  77. X      line_val.inc Makefile COPYRIGHT README \
  78. X      XMake5.ad xmake5.doc xmake5.6 cmake5.6 
  79. X
  80. X
  81. XOBJS    = xmake5.o drawing.o record.o make5.o select.o initbd.o helptext.o
  82. X
  83. XOBJS2    = cmake5.o record.o make5.o select.o initbd.o 
  84. X
  85. X.SUFFIXES: .C
  86. X
  87. X.C.o:
  88. X    $(CPP) $(DEBUG) -c $*.C
  89. X    
  90. X.c.o:
  91. X    $(CC)  $(DEBUG) -c $*.c
  92. X    
  93. Xall:        cmake5  xmake5  xmake5.doc  $(SCORE_F) 
  94. X
  95. X$(BINDIR):
  96. X    mkdir $(BINDIR)
  97. X
  98. X$(MANDIR):
  99. X    mkdir $(MANDIR)
  100. X
  101. X$(SCOREDIR):
  102. X    mkdir $(SCOREDIR)
  103. X
  104. Xxmake5.doc:    printhelp
  105. X    printhelp > xmake5.doc
  106. X
  107. Xcmake5:        $(OBJS2)
  108. X    $(CPP) $(DEBUG) -o cmake5 $(OBJS2) -lcurses -ltermcap
  109. X    strip cmake5
  110. X    chmod 04755 cmake5
  111. X
  112. X$(SCORE_F):    $(SCOREDIR)
  113. X    echo "Name      Level  Steps  min:sec     time      date" \
  114. X        > $(SCORE_F)
  115. X    echo "-----------------------------------------------------" \
  116. X        >> $(SCORE_F)
  117. X    chmod 0644 $(SCORE_F)
  118. X
  119. Xprinthelp:    printhelp.o helptext.o
  120. X    $(CPP) -o printhelp printhelp.o helptext.o 
  121. X    strip printhelp
  122. X
  123. Xxmake5:        $(OBJS)
  124. X    $(CPP) $(DEBUG) -o xmake5 $(OBJS) $(XLIB)
  125. X    strip xmake5
  126. X    chmod 04755 xmake5
  127. X
  128. Xrecord.o:    record.c 
  129. X    $(CC) $(DEBUG) -c $(FILE_DEF) record.c
  130. X
  131. Xcmake5.o:    cmake5.C
  132. Xxmake5.o:    xmake5.c make5.xbm xmake5.h
  133. Xdrawing.o:    drawing.c  board.xbm xmake5.h
  134. Xmake5.o:    make5.C bdconst.h
  135. Xselect.o:    select.C debug.inc bdconst.h
  136. Xinitbd.o:    initbd.C line_val.inc bdconst.h
  137. X
  138. Xxmake5.shar:    $(SOURCE)
  139. X    shar $(SOURCE) > xmake5.shar
  140. X
  141. Xcleanup:
  142. X    /bin/rm *.o cmake5 xmake5 printhelp
  143. X
  144. Xinstall:    $(BINDIR) $(MANDIR) cmake5 xmake5 cmake5.6 xmake5.6
  145. X    /bin/cp xmake5    cmake5    $(BINDIR)
  146. X    /bin/cp xmake5.6  cmake5.6  $(MANDIR)
  147. X    chmod 04755 $(BINDIR)/xmake5    $(BINDIR)/cmake5
  148. X    chmod 0444  $(MANDIR)/xmake5.6  $(MANDIR)/cmake5.6
  149. END_OF_FILE
  150. if test 2688 -ne `wc -c <'Makefile'`; then
  151.     echo shar: \"'Makefile'\" unpacked with wrong size!
  152. fi
  153. # end of 'Makefile'
  154. fi
  155. if test -f 'bdconst.h' -a "${1}" != "-c" ; then 
  156.   echo shar: Will not clobber existing file \"'bdconst.h'\"
  157. else
  158. echo shar: Extracting \"'bdconst.h'\" \(2343 characters\)
  159. sed "s/^X//" >'bdconst.h' <<'END_OF_FILE'
  160. X// FILE:        bdconst.h
  161. X
  162. Xconst int
  163. X  max_side_lev = 31 ,  max_index = 496 ,
  164. X  max_line_lev = 20 ,  max_pt_lev = 27 ,
  165. X  wall = '#',  blank = '.' ,  black = 'X' , white = 'O' ,
  166. X  bdwidth = 21 ,  bdlength = 440 ;
  167. X
  168. Xextern const int weight5[5], dirx[8];
  169. X
  170. Xconst int x_index_range = bdlength+1;
  171. X
  172. Xtypedef int   x_index;          // 0..bdlength ;
  173. Xtypedef char  side_lev_range;   // 0..max_side_lev ;
  174. Xtypedef int   line_index;       // 0..max_index ;
  175. Xtypedef char  line_lev_range;   // 1..max_line_lev ;
  176. Xtypedef char  pt_lev_range;     // 1..max_pt_lev ;
  177. Xtypedef line_lev_range  line_val_type[max_index+1];
  178. X
  179. Xextern int weight31[31];
  180. X
  181. Xtypedef struct pt_lev_record_tag {
  182. X      int pc[2][max_pt_lev+1];
  183. X      int mp[2];             // { 1..max_pt_lev }
  184. X}  pt_lev_record;
  185. X
  186. Xtypedef struct bdstatus_type_tag {
  187. X      side_lev_range side_lev[x_index_range][2][8];
  188. X      line_lev_range line_lev[x_index_range][2][4];
  189. X      pt_lev_range   point_lev[x_index_range][2];
  190. X      pt_lev_record  pt_lev_rec;
  191. X} bdstatus_type;
  192. X
  193. Xextern int   min_depth,max_depth;       // depths of MIN/MAX search
  194. X
  195. Xextern const pt_lev_range  point_lev_tab[max_line_lev+1][max_line_lev+1];
  196. X//      initialized in "initbd.C"
  197. X
  198. Xtypedef struct update_record_tag {
  199. X        int             side_lev, line_lev;
  200. X        pt_lev_range    point_lev;
  201. X} update_record[2][8][5] ;  // array[1..2,-4..4,1..5]
  202. X
  203. Xextern char board[x_index_range];
  204. Xextern bdstatus_type bdstatus;
  205. X
  206. Xextern int player;
  207. Xextern char player_color[2];
  208. Xextern int step;
  209. X
  210. X#define x_col(x) (x % bdwidth)
  211. X#define x_row(x) (x / bdwidth)
  212. X#define dec(x) ((x)--)
  213. X#define inc(x) ((x)++)
  214. X
  215. X//---------------------------------------------------------------------------
  216. X//      Procedures defined in "initbd.C"
  217. X
  218. Xextern void init_bdstatus(void);
  219. Xextern int  get_side_lev(int x,int d,char c);
  220. Xextern void set_side_lev(int x);
  221. Xextern void set_line_lev(int x,int c,int d);
  222. Xextern void set_point_lev(int x, int c);
  223. X
  224. X//---------------------------------------------------------------------------
  225. X//      Procedures defined in "make5.C"
  226. X
  227. Xextern void update_board(int sw, int x, update_record *z, pt_lev_record *pt);
  228. Xextern void restore(int x, update_record *z, pt_lev_record *pt);
  229. Xextern update_record *new_update_record(void);
  230. Xextern pt_lev_record *new_pt_lev_record(void);
  231. X
  232. X//---------------------------------------------------------------------------
  233. END_OF_FILE
  234. if test 2343 -ne `wc -c <'bdconst.h'`; then
  235.     echo shar: \"'bdconst.h'\" unpacked with wrong size!
  236. fi
  237. # end of 'bdconst.h'
  238. fi
  239. if test -f 'debug.inc' -a "${1}" != "-c" ; then 
  240.   echo shar: Will not clobber existing file \"'debug.inc'\"
  241. else
  242. echo shar: Extracting \"'debug.inc'\" \(171 characters\)
  243. sed "s/^X//" >'debug.inc' <<'END_OF_FILE'
  244. X// FILE:        "debug.inc"
  245. X
  246. X#define Check_No_Point(a,b)
  247. X
  248. X// void Check_No_Point(char *s, point_list &p) {
  249. X//        if (p.n<=0) {printf("Error: %s\n",s); exit(1); }
  250. X// }
  251. END_OF_FILE
  252. if test 171 -ne `wc -c <'debug.inc'`; then
  253.     echo shar: \"'debug.inc'\" unpacked with wrong size!
  254. fi
  255. # end of 'debug.inc'
  256. fi
  257. if test -f 'drawing.c' -a "${1}" != "-c" ; then 
  258.   echo shar: Will not clobber existing file \"'drawing.c'\"
  259. else
  260. echo shar: Extracting \"'drawing.c'\" \(11087 characters\)
  261. sed "s/^X//" >'drawing.c' <<'END_OF_FILE'
  262. X/* FILE: drawing.c   (Ver. 1.1) */
  263. X
  264. X#include <X11/cursorfont.h>
  265. X#include <X11/Intrinsic.h>
  266. X#include <X11/StringDefs.h>
  267. X
  268. X#include <stdio.h>
  269. X/**********************************************************************/
  270. X
  271. X#include "xmake5.h"
  272. X#include "board.xbm"
  273. X
  274. XDisplay  *display;
  275. Xint      screen_num;
  276. Xunsigned long black_color, white_color;
  277. XCursor   cursor;
  278. X
  279. X/**********************************************************************/
  280. X/*       All about drawing              */
  281. X
  282. XWindow main_win;
  283. Xstatic Pixmap board_map;
  284. X
  285. Xstatic unsigned board_x0, board_x1, board_y0, board_y1;
  286. Xstatic unsigned stone_x0, stone_y0;
  287. Xstatic unsigned cell_height, cell_width;
  288. Xstatic unsigned stone_size_x, stone_size_y;
  289. X
  290. Xstatic int      min_main_win_width=396, min_main_win_height=396;
  291. Xstatic int      main_win_width=0, main_win_height=0;
  292. X
  293. Xstatic XColor   C1W,C1B;
  294. Xstatic GC       gc, gc_stone[2], gc_board, gc_back;
  295. X
  296. Xchar   board_stones[BoardLines][BoardLines];
  297. X
  298. X/**********************************************************************/
  299. X/*           All about drawing, Xlib                                  */
  300. X/**********************************************************************/
  301. Xvoid warp_to_position(x,y)  int x,y;
  302. X{   /* move the pointer out and back the main_window */
  303. X    XWarpPointer(display,NULL,main_win,0,0,0,0,-1,-1);
  304. X    XWarpPointer(display,NULL,main_win,0,0,0,0,
  305. X                 board_x0 + x * cell_width, board_y0 + y * cell_height);
  306. X}
  307. X/**********************************************************************/
  308. Xvoid refresh_pointer()
  309. X{ Window r_win, c_win;
  310. X  int r_x, r_y, w_x, w_y;
  311. X  unsigned int keys;
  312. X    XQueryPointer(display,main_win,&r_win,&c_win,&r_x,&r_y,&w_x,&w_y,&keys);
  313. X    /* move the pointer out and back the main_window */
  314. X    XWarpPointer(display,NULL,main_win,0,0,0,0,-1,-1);
  315. X    XWarpPointer(display,NULL,main_win,0,0,0,0,w_x,w_y);
  316. X}
  317. X/**********************************************************************/
  318. Xvoid to_last_position()
  319. X{   int x;
  320. X    if (last_move_rec <= 0)  warp_to_position(9,9);
  321. X    else {
  322. X        x = move_rec[last_move_rec];
  323. X        warp_to_position(BoardX(x),BoardY(x));
  324. X    }
  325. X}
  326. X/**********************************************************************/
  327. Xvoid switch_color(c) int c;
  328. X{
  329. X    if (c==0)  XRecolorCursor(display,cursor,&C1B,&C1W);
  330. X    else       XRecolorCursor(display,cursor,&C1W,&C1B);
  331. X    refresh_pointer();
  332. X}
  333. X/**********************************************************************/
  334. Xvoid draw_suggestions()
  335. X{ int i,n,x;
  336. X
  337. X    for (i=0,n=num_of_suggestion; i<n; i++) {
  338. X      x=suggest_position[i];
  339. X      mark_stone(BoardX(x),BoardY(x),player);
  340. X    }
  341. X }
  342. X/**********************************************************************/
  343. Xstatic void reconfig_board(redraw)  int redraw;
  344. X{ 
  345. X    board_x0 = 2 * cell_width;
  346. X    board_y0 = 2 * cell_height;
  347. X    board_x1 = (BoardLines+1) * cell_width;
  348. X    board_y1 = (BoardLines+1) * cell_height;
  349. X    stone_size_x = cell_width * 4 / 5;
  350. X    stone_size_y = cell_height * 4 / 5;
  351. X    stone_x0 = board_x0 - (stone_size_x/2);
  352. X    stone_y0 = board_y0 - (stone_size_y/2);
  353. X    if (redraw)  redraw_board(); 
  354. X}
  355. X/**********************************************************************/
  356. Xstatic void set_new_board_size(w,h) int w,h;
  357. X{ Dimension width,height,bw;
  358. X  Arg args[3];
  359. X    XtSetArg(args[0], XtNwidth,  &width);
  360. X    XtSetArg(args[1], XtNheight, &height);
  361. X    XtSetArg(args[2], XtNborderWidth, &bw);
  362. X    XtGetValues(toplevel, args, 3);
  363. X    width = width + w - main_win_width;
  364. X    height = height + h - main_win_height;
  365. X    XtResizeWidget(toplevel,width,height,bw);
  366. X}
  367. X/**********************************************************************/
  368. Xvoid adjust_board()
  369. X{ int mw = max(cell_width,cell_height) * (BoardLines + 3);
  370. X
  371. X    if (mw < min_main_win_width || mw < min_main_win_height)
  372. X        mw += BoardLines + 3;
  373. X    if (cell_width != cell_height ||
  374. X         main_win_width != mw  ||  main_win_height != mw )
  375. X       set_new_board_size(mw,mw);
  376. X}
  377. X/**********************************************************************/
  378. Xvoid Board_config(w, event, params, num_params)
  379. X  Widget w;
  380. X  XConfigureEvent *event;
  381. X  String *params;
  382. X  Cardinal *num_params;
  383. X{ int new_width, new_height, enlarge;
  384. X
  385. X    enlarge =  event->width > main_win_width || 
  386. X                event->height > main_win_height ;
  387. X    main_win_width = event->width;
  388. X    main_win_height = event->height;
  389. X    new_width = max(main_win_width, min_main_win_width);
  390. X    new_height = max(main_win_height, min_main_win_height);
  391. X    if (main_win_width != new_width ||
  392. X        main_win_height != new_height) {
  393. X      set_new_board_size(new_width,new_height);
  394. X      return;
  395. X    }
  396. X    cell_width = main_win_width / (BoardLines + 3);
  397. X    cell_height = main_win_height / (BoardLines + 3);
  398. X    reconfig_board(!enlarge);
  399. X    /* When the window is enlarged, 
  400. X       a further redraw event will redraw the board. */
  401. X}
  402. X/**********************************************************************/
  403. Xvoid Board_redraw(w, event, params, num_params)
  404. X  Widget w;
  405. X  XExposeEvent *event;
  406. X  String *params;
  407. X  Cardinal *num_params;
  408. X{
  409. X    if (event->count == 0) redraw_board();
  410. X}
  411. X/**********************************************************************/
  412. Xvoid Board_seton(w, event, params, num_params)
  413. X  Widget w;
  414. X  XButtonEvent *event;
  415. X  String *params;
  416. X  Cardinal *num_params;
  417. X{
  418. X    int xpos, ypos, xp, yp, movex;
  419. X  
  420. X    if (game_over) return;
  421. X    if (player_name[player] != 'M') {
  422. X      check_computer_move();
  423. X      return;   /* not for human player */
  424. X    }
  425. X    xpos   = event->x;
  426. X    ypos   = event->y; 
  427. X    xypos_to_board_pos(xpos,ypos,&xp,&yp);
  428. X    if (xp < BoardLines && board_stones[xp][yp] == empty_stone) {
  429. X      movex = xp + 1 + (yp+1) * BoardSize;
  430. X      make_a_move(movex);
  431. X      check_computer_move();
  432. X    }
  433. X}
  434. X/**********************************************************************/
  435. Xvoid setup_gc()
  436. X{
  437. X    unsigned long valuemask = 0; /* ignore XGCvalues and use defaults */
  438. X    XGCValues values;
  439. X    Colormap cmap;
  440. X    XColor C2W,C2B,C1G,C2G;
  441. X
  442. X    cursor = XCreateFontCursor(display, XC_dot);
  443. X    XDefineCursor(display, main_win, cursor);
  444. X
  445. X    cmap=DefaultColormap(display,screen_num);
  446. X    XAllocNamedColor(display, cmap, "black", &C1B, &C2B);
  447. X    XAllocNamedColor(display, cmap, "white", &C1W, &C2W);
  448. X    XAllocNamedColor(display, cmap, "LightGray", &C1G, &C2G);
  449. X    black_color = BlackPixel(display,screen_num);
  450. X    white_color = WhitePixel(display,screen_num);
  451. X
  452. X    gc = XCreateGC(display, main_win, valuemask, &values);
  453. X    XSetForeground(display, gc, black_color);
  454. X
  455. X    gc_board = XCreateGC(display, main_win, valuemask, &values);
  456. X    if (C1G.pixel == 0) {
  457. X        board_map = XCreateBitmapFromData(display, main_win,
  458. X                           board_bits, board_width, board_height);
  459. X        XSetFillStyle(display,  gc_board, FillTiled);
  460. X        XSetTile(display,       gc_board, board_map);
  461. X    } else {
  462. X        XSetForeground(display, gc_board, C1G.pixel);
  463. X    }
  464. X    gc_back  = XCreateGC(display, main_win, valuemask, &values);
  465. X    XSetForeground(display, gc_back,  white_color);
  466. X
  467. X    gc_stone[0] = XCreateGC(display, main_win, valuemask, &values);
  468. X    gc_stone[1] = XCreateGC(display, main_win, valuemask, &values);
  469. X    XSetForeground(display, gc_stone[0], black_color);
  470. X    XSetBackground(display, gc_stone[0], white_color);
  471. X    XSetForeground(display, gc_stone[1], white_color);
  472. X    XSetBackground(display, gc_stone[1], black_color);
  473. X}
  474. X/**********************************************************************/
  475. Xdraw_H_line(y) int y;
  476. X{ unsigned y1 = board_y0 + y * cell_height;
  477. X
  478. X    XDrawLine(display, main_win, gc, board_x0, y1, board_x1, y1);
  479. X}
  480. X/**********************************************************************/
  481. Xdraw_V_line(x) int x;
  482. X{ unsigned x1 = board_x0 + x * cell_width;
  483. X
  484. X    XDrawLine(display, main_win, gc, x1, board_y0, x1, board_y1);
  485. X}
  486. X/**********************************************************************/
  487. Xput_stone(x,y,c) int x,y,c;
  488. X{ unsigned xp = stone_x0 + x * cell_width;
  489. X  unsigned yp = stone_y0 + y * cell_height;
  490. X
  491. X    board_stones[x][y] = c;
  492. X    XFillArc(display,main_win,gc_stone[c],xp,yp,
  493. X             stone_size_x,stone_size_y,0,360*64);
  494. X    XDrawArc(display,main_win,gc_stone[1-c],xp,yp,
  495. X             stone_size_x,stone_size_y,0,360*64);
  496. X}
  497. X/**********************************************************************/
  498. Xvoid unmark_last_move()
  499. X{ int x = move_rec[last_move_rec];
  500. X    if (last_move_rec <= 0) return;
  501. X    put_stone(BoardX(x), BoardY(x), 1-player);
  502. X}
  503. X/**********************************************************************/
  504. Xvoid mark_last_move()
  505. X{ int m = move_rec[last_move_rec];
  506. X  unsigned xp,yp;
  507. X
  508. X    if (last_move_rec <= 0) return;
  509. X    xp = stone_x0 + BoardX(m) * cell_width;
  510. X    yp = stone_y0 + BoardY(m) * cell_height;
  511. X    XDrawArc(display,main_win,gc_stone[player],xp+3,yp+3,
  512. X             stone_size_x-6,stone_size_y-6,0,360*64);
  513. X}
  514. X/**********************************************************************/
  515. Xclear_mark_stone()
  516. X{
  517. X    if (num_of_suggestion > 0) {
  518. X      num_of_suggestion = 0;
  519. X      redraw_board_only();
  520. X    }
  521. X}
  522. X/**********************************************************************/
  523. Xmark_stone(x,y,c) int x,y,c;
  524. X{ unsigned xp = stone_x0 + x * cell_width;
  525. X  unsigned yp = stone_y0 + y * cell_height;
  526. X
  527. X    XDrawArc(display,main_win,gc_stone[c],xp,yp,
  528. X             stone_size_x,stone_size_y,0,360*64);
  529. X    XDrawArc(display,main_win,gc_stone[c],xp-1,yp-1,
  530. X             stone_size_x+2,stone_size_y+2,0,360*64);
  531. X}
  532. X/**********************************************************************/
  533. Xredraw_board_only() 
  534. X{ int i,j;
  535. X
  536. X    XFillRectangle(display, main_win, gc_back,
  537. X                   0, 0, main_win_width, main_win_height);
  538. X
  539. X    XFillRectangle(display, main_win, gc_board, 
  540. X                   cell_width, cell_height,
  541. X                   main_win_width - 2 * cell_width, 
  542. X                   main_win_height - 2 * cell_height);
  543. X
  544. X    for (i=0; i < BoardLines; i++) {
  545. X        draw_H_line(i); 
  546. X        draw_V_line(i);
  547. X    }
  548. X
  549. X    for (i=0; i < BoardLines; i++)
  550. X      for (j=0; j < BoardLines; j++)
  551. X        switch (board_stones[i][j]) {
  552. X            case white_stone:     put_stone(i,j,1); break;
  553. X            case black_stone:     put_stone(i,j,0); break;
  554. X            default: break;
  555. X        }
  556. X    if (num_of_suggestion != 0) draw_suggestions();
  557. X    mark_last_move();
  558. X}
  559. X/**********************************************************************/
  560. Xredraw_board() 
  561. X{   redraw_board_only();
  562. X    update_status();
  563. X}
  564. X/**********************************************************************/
  565. Xint near_cross_point(x) float x;
  566. X{ int k;
  567. X  float dis = 0.35;
  568. X
  569. X    if (x < - dis || x > (BoardLines - 1 + dis)) return 0;
  570. X    k = x;
  571. X    if (((x - k) < dis) || ((k + 1 - x) < dis)) return 1;
  572. X    return 0; 
  573. X}
  574. X/**********************************************************************/
  575. Xxypos_to_board_pos(xpos,ypos,xp,yp) int xpos, ypos, *xp, *yp;
  576. X{ float x=xpos, y=ypos;
  577. X
  578. X    x = (x / cell_width) - 2;   
  579. X    y = (y / cell_height) - 2;
  580. X    if (near_cross_point(x) && near_cross_point(y)) {
  581. X      *xp = x + 0.5;
  582. X      *yp = y + 0.5;
  583. X    } else {
  584. X      *xp = BoardLines;
  585. X      *yp = BoardLines;
  586. X    }
  587. X}
  588. X/**********************************************************************/
  589. END_OF_FILE
  590. if test 11087 -ne `wc -c <'drawing.c'`; then
  591.     echo shar: \"'drawing.c'\" unpacked with wrong size!
  592. fi
  593. # end of 'drawing.c'
  594. fi
  595. if test -f 'helptext.C' -a "${1}" != "-c" ; then 
  596.   echo shar: Will not clobber existing file \"'helptext.C'\"
  597. else
  598. echo shar: Extracting \"'helptext.C'\" \(4387 characters\)
  599. sed "s/^X//" >'helptext.C' <<'END_OF_FILE'
  600. Xextern char *helptext =
  601. X
  602. X"Name of the game:\n"
  603. X"=================\n"
  604. X"\n"
  605. X"Make5 is a game similar to Tic-Tac-Toe.\n"
  606. X"It is called Wu3-Zi3-Qi2 in Chinese and is \n"
  607. X"very popular in the Far East.  5-in-a-row and\n"
  608. X"Go-Moku are the other names for this game.\n"
  609. X"You may also find it called \"Chess\" on some\n"
  610. X"Nitendo games.  I call it Make5 because the goal\n"
  611. X"of this game is to make five continuous stones\n"
  612. X"in a line.\n"
  613. X"\n\n"
  614. X"How to play:\n"
  615. X"============\n"
  616. X"\n"
  617. X"This game was originally played by two players\n"
  618. X"on a board of infinite size.  Each player puts\n"
  619. X"a stone at one empty cross-point at a time.  \n"
  620. X"The winner is the one who first puts five\n"
  621. X"continuous stones in a line, vertically, \n"
  622. X"orizontally, or diagonally.\n"
  623. X"\n"
  624. X"However, this program plays the game on a finite\n"
  625. X"board the same size as a GO game board, which has\n"
  626. X"19 by 19 cross-points.  The only tricky rule is\n"
  627. X"that you must make exactly five continuous stones\n"
  628. X"in a line to win.  Six or more stones in a line\n"
  629. X"do not count.\n"
  630. X"\n"
  631. X"Some people play this game with a rule which\n"
  632. X"prohibits the first player to make double-3 or \n"
  633. X"double-4 attacking patterns.  But I do not\n"
  634. X"like this rule and did not include it in this \n"
  635. X"program.\n"
  636. X"\n\n"
  637. X"Strategies:\n"
  638. X"===========\n"
  639. X"\n"
  640. X"So, you see why it is like Tic-Tac-Toe.  \n"
  641. X"You have to stop the other player\'s continuous \n"
  642. X"lines of stones and design your own attacking lines.\n"
  643. X"Unlike Tic-Tac-Toe, this game is played on a large\n"
  644. X"board and requires five stones in a line to win.  \n"
  645. X"Is there a winning strategy for the first player?  \n"
  646. X"You tell me.\n"
  647. X"\n\n"
  648. X"Options of playing:\n"
  649. X"===================\n"
  650. X"\n"
  651. X"This program can play with you or play with itself.  \n"
  652. X"You can also play with your friends and use this\n"
  653. X"program to update the board.\n"
  654. X"\n"
  655. X"Most of the options in the \"Setup...\" menu can be\n"
  656. X"changed in the middle of a game.  Hence, you can\n"
  657. X"switch the players, change the computer's searching\n"
  658. X"level, or even undo your moves.\n"
  659. X"The \"Where...\" menu provides hints for good\n"
  660. X"positions and the position of the last move.\n"
  661. X"\n"
  662. X"You can switch to the challenge mode, in which\n"
  663. X"the computer always moves first and you can not\n"
  664. X"undo, change play level or order, or get suggestion\n"
  665. X"from the computer.  If you beat the computer, your\n"
  666. X"name would be added into the list of winners.\n"
  667. X"\n"
  668. X"Have fun!\n"
  669. X"\n\n"
  670. X"History of this program:\n"
  671. X"========================\n"
  672. X"\n"
  673. X"The basic playing algorithm was designed in 1984\n"
  674. X"as a term project of an A.I. class; it was written\n"
  675. X"in Pascal and runs on Prime-750.  The game was\n"
  676. X"ported to Turbo Pascal and ran on PC in 1986.\n"
  677. X"\n"
  678. X"Now this game is translated to C and C++ with an\n"
  679. X"X interface.  Another version called cmake5 is also\n"
  680. X"available.  It uses the UNIX curses library and runs\n"
  681. X"on most ASCII terminals.\n"
  682. X"\n"
  683. X"\n"
  684. X"Chih-Hung Hsieh      November 1991\n"
  685. X"\n"
  686. X"(Please send your comment to hsiehch@cs.nyu.edu.)\n"
  687. X"\n\n\n"
  688. X"       Hsieh             \n"
  689. X"------------------------ \n"
  690. X" ,,,       ||'      ||'  \n"
  691. X"  '||    ,,|,,,|    ||   \n"
  692. X",,,,|,|, ||   ||    ||   \n"
  693. X"         ||'''|| ,,,||,| \n"
  694. X" ,,,,|,  ||,,,||    ||   \n"
  695. X"         ||   ||,,  ||   \n"
  696. X" ''''''  || ,,||'   ||   \n"
  697. X" ,     '||'' ,|| |  ||   \n"
  698. X" ||''||    ,|'||  | ||   \n"
  699. X" ||  || ,,''  ||    ||   \n"
  700. X" ||  ||       ||    ||   \n"
  701. X" ||''''    ''||' ''||'   \n"
  702. X"------------------------ \n"
  703. X"       Chih              \n"
  704. X"------------------------ \n"
  705. X"            ||'          \n"
  706. X"            ||        ,, \n"
  707. X" '''''''''''||'''''''''''\n"
  708. X"            ||           \n"
  709. X"            ||      ,,   \n"
  710. X"   ''''''''''''''''''''  \n"
  711. X"           ,,            \n"
  712. X"    ,  ||'  '|,    ,,    \n"
  713. X"    |  ||    ''     '|,  \n"
  714. X"  ,|'  ||         |  '|| \n"
  715. X" ,||   ||         |,  ||'\n"
  716. X" ''    '|||||||||||'     \n"
  717. X"------------------------ \n"
  718. X"       Hung              \n"
  719. X"------------------------ \n"
  720. X",,,,,,,,,|,     ||,      \n"
  721. X"       ||'     ||        \n"
  722. X"       ||      ||        \n"
  723. X"|,,,,,,||     ,|'        \n"
  724. X"||     ''     ||         \n"
  725. X"||            ||         \n"
  726. X"||,,,,,,|,   ||          \n"
  727. X"''     ||'   |'   ',     \n"
  728. X"       ||   |'     '|    \n"
  729. X"      ,|'  ,'      ,||   \n"
  730. X"     ,|' ,,|,,,|''' '||  \n"
  731. X"'''|||'   ''''       ||  \n"
  732. X"------------------------ \n"
  733. X;
  734. END_OF_FILE
  735. if test 4387 -ne `wc -c <'helptext.C'`; then
  736.     echo shar: \"'helptext.C'\" unpacked with wrong size!
  737. fi
  738. # end of 'helptext.C'
  739. fi
  740. if test -f 'make5.C' -a "${1}" != "-c" ; then 
  741.   echo shar: Will not clobber existing file \"'make5.C'\"
  742. else
  743. echo shar: Extracting \"'make5.C'\" \(5243 characters\)
  744. sed "s/^X//" >'make5.C' <<'END_OF_FILE'
  745. X// FILE: make5.C  (Ver. 1.0)
  746. X
  747. X#include <stdio.h>
  748. X#include <stdlib.h>
  749. X
  750. X#include "bdconst.h"
  751. X
  752. X//---------------------------------------------------------------------------
  753. Xconst int   max_step = 175;             // maximum move steps for each player
  754. X
  755. Xextern int  player,step;                // defined in make5x.c
  756. Xchar        player_color[2];
  757. X
  758. X#define abs_d(d) ((d<4)?d:(7-d))
  759. X
  760. X//---------------------------------------------------------------------------
  761. Xupdate_record *new_update_record(void) {
  762. X    char *p;
  763. X    if ((p=(char *)malloc(2*8*5*sizeof(struct update_record_tag)))==NULL) {
  764. X         printf("Out of Heap space in new_update_record\n"); exit(1);
  765. X    }
  766. X    return((update_record*)p);
  767. X}
  768. X//---------------------------------------------------------------------------
  769. Xpt_lev_record *new_pt_lev_record(void) {
  770. X    char *p;
  771. X    if ((p=(char*)malloc(sizeof(struct pt_lev_record_tag)))==NULL) {
  772. X         printf("Out of Heap space in new_pt_lev_record\n"); exit(1);
  773. X    }
  774. X    return((pt_lev_record*)p);
  775. X}
  776. X//---------------------------------------------------------------------------
  777. Xvoid update_board(int sw, int x, update_record *z, pt_lev_record *pt) {
  778. X        // update board status and save update record to z
  779. X  int c,d,k,i;
  780. X    *pt = bdstatus.pt_lev_rec;
  781. X    if (sw == 1)
  782. X         for (i=0; i<2; i++)
  783. X           dec(bdstatus.pt_lev_rec.pc[i][bdstatus.point_lev[x][i]]);
  784. X    else for (i=0; i<2; i++)
  785. X           inc(bdstatus.pt_lev_rec.pc[i][bdstatus.point_lev[x][i]]);
  786. X    for (d=0; d<8; d++) {
  787. X      i = x;
  788. X      for (k=0; k<5; k++) {
  789. X        i += dirx[d];
  790. X        if (board[i] == blank) {
  791. X          for (c=0; c<2; c++) {
  792. X            struct update_record_tag &zcdk = (*z)[c][d][k];
  793. X            dec(bdstatus.pt_lev_rec.pc[c][bdstatus.point_lev[i][c]]);
  794. X            zcdk.side_lev = bdstatus.side_lev[i][c][7-d];
  795. X            zcdk.line_lev = bdstatus.line_lev[i][c][abs_d(d)];
  796. X            zcdk.point_lev = bdstatus.point_lev[i][c];
  797. X            bdstatus.side_lev[i][c][7-d] = get_side_lev(i,7-d,player_color[c]);
  798. X            set_line_lev(i,c,abs_d(d));
  799. X            set_point_lev(i,c);
  800. X            inc(bdstatus.pt_lev_rec.pc[c][bdstatus.point_lev[i][c]]);
  801. X          }
  802. X        }
  803. X      }
  804. X    }
  805. X    for (i=0; i<2; i++) {
  806. X      bdstatus.pt_lev_rec.mp[i] = 1;
  807. X      while (bdstatus.pt_lev_rec.pc[i][bdstatus.pt_lev_rec.mp[i]] == 0)
  808. X        (bdstatus.pt_lev_rec.mp[i])++;
  809. X    }
  810. X}
  811. X//---------------------------------------------------------------------------
  812. Xvoid restore(int x, update_record *z, pt_lev_record *pt) {
  813. X        // restore board status with update_record z
  814. X  int c,d,k,i;
  815. X    bdstatus.pt_lev_rec = *pt;
  816. X    for (d=0; d<8; d++) {
  817. X      i = x;
  818. X      for (k=0; k<5; k++) {
  819. X        i += dirx[d];
  820. X        if (board[i] == blank)
  821. X          for (c=0; c<2; c++) {
  822. X            struct update_record_tag &zcdk = (*z)[c][d][k];
  823. X            bdstatus.side_lev[i][c][7-d] = zcdk.side_lev;
  824. X            bdstatus.line_lev[i][c][abs_d(d)] = zcdk.line_lev;
  825. X            bdstatus.point_lev[i][c] = zcdk.point_lev;
  826. X          }
  827. X      }
  828. X    }
  829. X}
  830. X//---------------------------------------------------------------------------
  831. Xextern "C" void set_on(int x, int p) {  // set on position x for player p
  832. X  update_record *z = new_update_record();
  833. X  pt_lev_record *pt = new_pt_lev_record();
  834. X    board[x] = player_color[p];  // update board status
  835. X    update_board(1,x,z,pt);
  836. X    free(z); free(pt);
  837. X}
  838. X//---------------------------------------------------------------------------
  839. Xextern "C" void take_out(int x) {  // take out the stone at x
  840. X  update_record *z = new_update_record();
  841. X  pt_lev_record *pt = new_pt_lev_record();
  842. X    board[x] = blank;
  843. X    update_board(0,x,z,pt);
  844. X    free(z); free(pt);
  845. X}
  846. X//---------------------------------------------------------------------------
  847. Xstatic const int point3 = 13;
  848. Xstatic char *warning[] =
  849. X     {"",
  850. X      "***** GAME OVER *****    Five in a line.",       // 1
  851. X      "Warning: open 4-in-a-line and more !!!!!!",      // 2
  852. X      "Warning: open 4-in-a-line !!!!!!",               // 3
  853. X      "Warning: 4-in-a-line & open 3-in-a-line !!!!!",  // 4
  854. X      "Warning: Double open-3-in-a-line !!!!",          // 5
  855. X      "Warning: 4-in-a-line !!",                        // 6
  856. X      "Warning: open 3-in-a-line !!",                   // 7
  857. X      "Warning: 4-in-a-line !!",                        // 8
  858. X      "Warning: open 3-in-a-line !!",
  859. X      "Warning: 4-in-a-line !!",
  860. X      "Warning: open 3-in-a-line !!",
  861. X      "Warning: 4-in-a-line !!",
  862. X      "Warning: open 3-in-a-line !!"};
  863. X//---------------------------------------------------------------------------
  864. Xextern "C" char *get_warning(int p,int x) {
  865. X  int lev = bdstatus.point_lev[x][p];
  866. X  if (step >= max_step) 
  867. X     return "***** GAME OVER *****   Too many steps.  Tie!!";
  868. X  if (lev <= point3) return warning[lev]; 
  869. X  else return "";
  870. X}
  871. X//---------------------------------------------------------------------------
  872. Xextern "C" int is_game_over(int p,int x) {
  873. X  return (bdstatus.point_lev[x][p] == 1 || step >= max_step);
  874. X}
  875. X//---------------------------------------------------------------------------
  876. Xextern "C" void init_data(void) {
  877. X    init_bdstatus();
  878. X    player_color[0]=black;
  879. X    player_color[1]=white;
  880. X}
  881. X//---------------------------------------------------------------------------
  882. END_OF_FILE
  883. if test 5243 -ne `wc -c <'make5.C'`; then
  884.     echo shar: \"'make5.C'\" unpacked with wrong size!
  885. fi
  886. # end of 'make5.C'
  887. fi
  888. if test -f 'make5.xbm' -a "${1}" != "-c" ; then 
  889.   echo shar: Will not clobber existing file \"'make5.xbm'\"
  890. else
  891. echo shar: Extracting \"'make5.xbm'\" \(2879 characters\)
  892. sed "s/^X//" >'make5.xbm' <<'END_OF_FILE'
  893. X#define make5_width 63
  894. X#define make5_height 56
  895. Xstatic char make5_bits[] = {
  896. X   0x31, 0x91, 0x11, 0x13, 0x19, 0x31, 0x91, 0x91, 0x22, 0xe2, 0x23, 0x22,
  897. X   0x2a, 0x22, 0xe2, 0xa3, 0xa8, 0x18, 0x8c, 0x8a, 0x88, 0xa8, 0x18, 0x8c,
  898. X   0x64, 0x0c, 0x48, 0x46, 0x4c, 0x64, 0x0c, 0xc8, 0xff, 0x0f, 0xf8, 0xff,
  899. X   0xff, 0xff, 0x0f, 0xf8, 0x22, 0x0a, 0x28, 0x22, 0x2a, 0x22, 0x0a, 0xa8,
  900. X   0xa8, 0x08, 0x88, 0x8a, 0x88, 0xa8, 0x08, 0x88, 0x64, 0x14, 0x44, 0x46,
  901. X   0x4c, 0x64, 0x14, 0xc4, 0x31, 0xf1, 0x13, 0x13, 0x19, 0x31, 0xf1, 0x93,
  902. X   0x22, 0xa2, 0x22, 0x22, 0x2a, 0x22, 0xa2, 0xa2, 0xa8, 0x88, 0x08, 0x80,
  903. X   0x88, 0x00, 0x88, 0x88, 0x64, 0xc4, 0x84, 0x4f, 0x4c, 0xf8, 0xc4, 0xc4,
  904. X   0x31, 0x91, 0xd1, 0x1f, 0x19, 0xfd, 0x91, 0x91, 0xff, 0xff, 0xdf, 0xdf,
  905. X   0xff, 0xfd, 0xfd, 0xff, 0xa8, 0x88, 0xc8, 0x9f, 0x88, 0xfc, 0x89, 0x88,
  906. X   0x64, 0xc4, 0xc4, 0x5f, 0x4c, 0xfc, 0xc5, 0xc4, 0x31, 0x91, 0x91, 0x0f,
  907. X   0x19, 0xf9, 0x90, 0x91, 0x22, 0xa2, 0x22, 0x20, 0x2a, 0x02, 0xa2, 0xa2,
  908. X   0xa8, 0x88, 0x88, 0x8a, 0x88, 0xa8, 0x88, 0x88, 0x64, 0xc4, 0xc4, 0x4f,
  909. X   0x40, 0x64, 0xc4, 0xc4, 0x31, 0x91, 0x51, 0x10, 0x3e, 0x31, 0x91, 0x91,
  910. X   0x22, 0xa2, 0x22, 0x20, 0x7f, 0x22, 0xa2, 0xa2, 0xff, 0xff, 0x3f, 0x60,
  911. X   0x7f, 0xff, 0xff, 0xff, 0x64, 0xc4, 0x24, 0x60, 0x7f, 0x64, 0xc4, 0xc4,
  912. X   0x31, 0x91, 0x31, 0x20, 0x7f, 0x31, 0x91, 0x91, 0x22, 0xa2, 0x62, 0x30,
  913. X   0x3e, 0x22, 0xa2, 0xa2, 0xa8, 0x88, 0x88, 0x8f, 0x80, 0xa8, 0x88, 0x88,
  914. X   0x64, 0xc4, 0x44, 0x46, 0x4c, 0x64, 0xc4, 0xc4, 0x31, 0x91, 0x11, 0x10,
  915. X   0x3f, 0x01, 0x91, 0x91, 0x22, 0xa2, 0xa2, 0x2f, 0x41, 0xfa, 0xa2, 0xa2,
  916. X   0xa8, 0x88, 0xc8, 0x9f, 0x80, 0xfc, 0x89, 0x88, 0xff, 0xff, 0xdf, 0xdf,
  917. X   0x80, 0xfd, 0xfd, 0xff, 0x31, 0x91, 0xd1, 0x9f, 0x80, 0xfd, 0x91, 0x91,
  918. X   0x22, 0xa2, 0xc2, 0x9f, 0x80, 0xfc, 0xa1, 0xa2, 0xa8, 0x88, 0x88, 0x8f,
  919. X   0xc1, 0xf8, 0x88, 0x88, 0x64, 0xc4, 0x44, 0x40, 0x7e, 0x04, 0xc4, 0xc4,
  920. X   0x31, 0x91, 0x11, 0x13, 0x19, 0x31, 0x91, 0x91, 0x22, 0x02, 0x20, 0x22,
  921. X   0x3e, 0x22, 0xa2, 0xa2, 0xa8, 0xe8, 0x8b, 0x8a, 0xc1, 0xa8, 0x88, 0x88,
  922. X   0x64, 0xf4, 0x47, 0xc6, 0x80, 0x64, 0xc4, 0xc4, 0xff, 0xf7, 0xf7, 0xff,
  923. X   0x80, 0xff, 0xff, 0xff, 0x22, 0xf2, 0x27, 0xa2, 0x80, 0x22, 0xa2, 0xa2,
  924. X   0xa8, 0xf0, 0x87, 0x8a, 0x80, 0xa8, 0x88, 0x88, 0x64, 0xe4, 0x43, 0x46,
  925. X   0x41, 0x64, 0xc4, 0xc4, 0x31, 0x11, 0x10, 0x13, 0x3f, 0x31, 0x91, 0x91,
  926. X   0x22, 0xa2, 0x22, 0x22, 0x2a, 0x22, 0xa2, 0xa2, 0xf8, 0x88, 0x88, 0x8a,
  927. X   0x88, 0xa8, 0x88, 0x88, 0x04, 0xc5, 0x44, 0x46, 0x4c, 0x64, 0xc4, 0xc4,
  928. X   0x03, 0x92, 0x11, 0x13, 0x19, 0x31, 0x91, 0x91, 0x03, 0xfe, 0xff, 0xff,
  929. X   0xff, 0xff, 0xff, 0xff, 0x02, 0x8a, 0x88, 0x8a, 0x88, 0xa8, 0x88, 0x88,
  930. X   0x02, 0xc6, 0x44, 0x46, 0x4c, 0x64, 0xc4, 0xc4, 0x05, 0x91, 0x11, 0x13,
  931. X   0x19, 0x31, 0x91, 0x91, 0xfa, 0xa2, 0x22, 0x22, 0x2a, 0x22, 0xa2, 0xa2,
  932. X   0xa8, 0x88, 0x88, 0x8a, 0x88, 0xa8, 0x88, 0x88, 0x64, 0xc4, 0x44, 0x46,
  933. X   0x4c, 0x64, 0xc4, 0xc4};
  934. END_OF_FILE
  935. if test 2879 -ne `wc -c <'make5.xbm'`; then
  936.     echo shar: \"'make5.xbm'\" unpacked with wrong size!
  937. fi
  938. # end of 'make5.xbm'
  939. fi
  940. if test -f 'record.c' -a "${1}" != "-c" ; then 
  941.   echo shar: Will not clobber existing file \"'record.c'\"
  942. else
  943. echo shar: Extracting \"'record.c'\" \(4153 characters\)
  944. sed "s/^X//" >'record.c' <<'END_OF_FILE'
  945. X#include <stdio.h>
  946. X#include <sys/types.h>
  947. X#include <unistd.h>
  948. X#include <fcntl.h>
  949. X#include <time.h>
  950. X#include <string.h>
  951. X
  952. Xchar *ScoreF = SCORE_FILE;
  953. Xchar *LockF  = LOCK_FILE;
  954. X
  955. X#define MAX_LINES    1003     /* no more than 1000 records */
  956. Xstatic  char    *(lines[MAX_LINES]);  
  957. Xstatic  int     num_of_lines;
  958. X
  959. Xstatic void read_lines()
  960. X{
  961. X  FILE *fp;
  962. X  int c;
  963. X  char x,buf[100];
  964. X  fp=fopen(ScoreF,"r");
  965. X  num_of_lines = c = 0;
  966. X  while ((x=fgetc(fp)) != EOF) {
  967. X    buf[c++] = x;
  968. X    if (x == '\n') {
  969. X      buf[c] = 0;  lines[num_of_lines++] = strdup(buf);
  970. X      c = 0;
  971. X      if (num_of_lines >= MAX_LINES) break;
  972. X    }
  973. X  }
  974. X  fclose(fp);
  975. X}
  976. X
  977. Xstatic int wrong_order(i,j) int i,j;
  978. X{
  979. X  if (lines[i][12] < lines[j][12]) return 1;
  980. X  if (lines[i][12] > lines[j][12]) return 0;
  981. X  return (strcmp(lines[i]+19,lines[j]+19) > 0);
  982. X}
  983. X
  984. Xstatic void sort_lines()
  985. X{ int i,j,n;
  986. X  char *p;
  987. X  for (i=2,n=num_of_lines-1; i<n; i++)
  988. X    for (j=i+1; j<num_of_lines; j++) 
  989. X      if (wrong_order(i,j)) {
  990. X        p=lines[i]; lines[i]=lines[j]; lines[j]=p;
  991. X      }
  992. X}
  993. X
  994. Xstatic void write_lines()
  995. X{ 
  996. X  FILE *fp;
  997. X  int i,n;
  998. X  n = num_of_lines;
  999. X  if (num_of_lines > (MAX_LINES - 1))  n = MAX_LINES - 1;
  1000. X  fp=fopen(ScoreF,"w");
  1001. X  for (i=0; i<n; i++) fprintf(fp,"%s",lines[i]);
  1002. X  fclose(fp);
  1003. X  for (i=0; i<num_of_lines; i++) free(lines[i]);
  1004. X}
  1005. X
  1006. Xstatic void sort_record_file()
  1007. X{ 
  1008. X  read_lines();
  1009. X  sort_lines();
  1010. X  write_lines();
  1011. X}
  1012. X
  1013. Xstatic void lock_score_file()
  1014. X{
  1015. X    while (open(LockF,O_CREAT|O_EXCL|O_RDWR) < 0) { 
  1016. X      sleep(1);  printf("Wait for updating the Make5 score file.\n"); 
  1017. X    }
  1018. X    chmod(LockF,0666);   /* in case of aborted process */
  1019. X}
  1020. X
  1021. Xstatic void two_digits(f,n) FILE *f; int n;
  1022. X{
  1023. X  if (n > 9) fprintf(f,"%d",n);
  1024. X  else fprintf(f,"0%d",n);
  1025. X}
  1026. X
  1027. Xstatic void update_score_file(name,level,step,seconds)
  1028. X    char *name;
  1029. X    int level, step, seconds;
  1030. X{   
  1031. X    time_t now;
  1032. X    struct tm *t;
  1033. X    int min,sec;
  1034. X    FILE *fp;
  1035. X
  1036. X    now = time((time_t *)NULL);
  1037. X    t = localtime(&now);
  1038. X    min = seconds / 60;
  1039. X    sec = seconds % 60;
  1040. X    fp=fopen(ScoreF,"a");
  1041. X    fprintf(fp,"%-10s  %d     %3d   %3d:",
  1042. X            name, level, step, min);
  1043. X    two_digits(fp,sec);
  1044. X    fprintf(fp,"   at ");
  1045. X    two_digits(fp,t->tm_hour); fputc(':',fp);
  1046. X    two_digits(fp,t->tm_min);
  1047. X    fprintf(fp," on ");
  1048. X    two_digits(fp,t->tm_mon+1); fputc('/',fp);
  1049. X    two_digits(fp,t->tm_mday); fputc('/',fp);
  1050. X    fprintf(fp,"%d\n",t->tm_year);
  1051. X    fclose(fp);
  1052. X    sort_record_file();
  1053. X    chmod(ScoreF,0644);
  1054. X}
  1055. X
  1056. Xstatic void unlock_score_file()
  1057. X{
  1058. X    remove(LockF);
  1059. X}
  1060. X
  1061. Xvoid add_score_record(level,step,time)
  1062. X     int level,step,time;
  1063. X{   
  1064. X    lock_score_file();
  1065. X    update_score_file(getlogin(),level,step,time);
  1066. X    unlock_score_file();
  1067. X}
  1068. X
  1069. Xstatic long int timer[2], last_timer[2];
  1070. X
  1071. Xvoid start_timer(n) int n;
  1072. X{
  1073. X    last_timer[n] = time((time_t *)NULL);
  1074. X}
  1075. X
  1076. Xvoid reset_timer(n) int n;
  1077. X{
  1078. X    timer[n] = 0;
  1079. X}
  1080. X
  1081. Xvoid pause_timer(n) int n;
  1082. X{
  1083. X    timer[n] += (time((time_t *)NULL) - last_timer[n]);
  1084. X}
  1085. X
  1086. Xint get_timer(n) int n;
  1087. X{
  1088. X    return timer[n];
  1089. X}
  1090. X
  1091. X#ifndef MAIL_COMMAND
  1092. X#define MAIL_COMMAND "/usr/ucb/mail -s make5.record"
  1093. X#endif
  1094. X
  1095. X#define x_row(x) (x / 21)
  1096. X#define x_col(x) (x % 21)
  1097. X
  1098. Xvoid mail_record(current_level,num_moves,move_records)
  1099. X        int current_level,num_moves,move_records[];
  1100. X{   int i;
  1101. X    char line[80], color[2];
  1102. X    char mail_command[6600];   /* more than enough for 180 steps */
  1103. X
  1104. X        color[0]='X';  color[1]='O';
  1105. X        sprintf(line,"Challenge Level:%d   Steps:%d   Player:%s [%c]\n",
  1106. X                current_level, (num_moves+1)/2, getlogin(), color[1]);
  1107. X        sprintf(mail_command,"%s %s <<THE_END\n%s\n", 
  1108. X                MAIL_COMMAND,getlogin(),line);
  1109. X        for (i=0; i<num_moves; i++) {
  1110. X                if (i & 1) 
  1111. X                        sprintf(line,"     [%c]:(%2d,%2d)\n",
  1112. X                        color[1],
  1113. X                        x_row(move_records[i]), x_col(move_records[i]));
  1114. X                else    sprintf(line,"%2d    [%c]:(%2d,%2d)",
  1115. X                        i/2 + 1, color[0],
  1116. X                        x_row(move_records[i]), x_col(move_records[i]));
  1117. X                strcat(mail_command,line);
  1118. X        }
  1119. X        strcat(mail_command,"\nTHE_END\n");
  1120. X        system(mail_command);
  1121. X}
  1122. END_OF_FILE
  1123. if test 4153 -ne `wc -c <'record.c'`; then
  1124.     echo shar: \"'record.c'\" unpacked with wrong size!
  1125. fi
  1126. # end of 'record.c'
  1127. fi
  1128. if test -f 'select.C' -a "${1}" != "-c" ; then 
  1129.   echo shar: Will not clobber existing file \"'select.C'\"
  1130. else
  1131. echo shar: Extracting \"'select.C'\" \(11252 characters\)
  1132. sed "s/^X//" >'select.C' <<'END_OF_FILE'
  1133. X// FILE: select.C  (Ver. 1.1)
  1134. X
  1135. X#include <stdio.h>
  1136. X#include <stdlib.h>
  1137. X
  1138. X#include "bdconst.h"
  1139. X
  1140. X//---------------------------------------------------------------------------
  1141. X//      For compatible with Pascal:
  1142. X
  1143. X#define maxint 32767
  1144. X
  1145. Xconst int start_pos = 22,  end_pos = 418, center_point = 220;
  1146. X
  1147. X//---------------------------------------------------------------------------
  1148. Xtypedef unsigned long pt_lev_set;  // set of pt_lev_range
  1149. X
  1150. X#define B_1             01L
  1151. X#define B_3             07L
  1152. X#define B_4_6_8_10      01257L
  1153. X#define B_4_6_8_10_12   05257L
  1154. X#define B_5             037L
  1155. X#define B_5_7_9_11_13   (B_4_6_8_10_12 << 1 + 1)
  1156. X#define B_6_8_10        01277L
  1157. X#define B_6_8_10_12     05277L
  1158. X#define B_9             0777L
  1159. X#define B_10    01777L
  1160. X#define B_11    03777L
  1161. X#define B_13    017777L
  1162. X#define B_16    0177777L
  1163. X#define B_18    0777777L
  1164. X#define B_20    03777777L
  1165. X#define B_21    07777777L
  1166. X#define B_22    017777777L
  1167. X#define B_23    037777777L
  1168. X#define B_24    077777777L
  1169. X#define B_25    0177777777L
  1170. X#define B_26    0377777777L
  1171. X#define B_27    0777777777L
  1172. X
  1173. Xconst pt_lev_set
  1174. X  alev[2][2][max_pt_lev+1] =
  1175. X   {{{0,B_1, B_3, B_3, B_5, B_10,B_10,B_10,B_11,B_11,   // 0..9
  1176. X        B_16,B_16,B_16,B_16,B_16,B_16,B_16,B_18,B_18,   // 10..18
  1177. X        B_20,B_20,B_21,B_22,B_23,B_24,B_25,B_26,B_27},  // alev[0][0]
  1178. X     {0,B_1, B_4_6_8_10_12, B_4_6_8_10_12,B_4_6_8_10_12,// 0..4
  1179. X        B_13,B_13,B_13,B_13,B_13,B_16,B_16,B_16,B_16,   // 5..13
  1180. X        B_16,B_18,B_18,B_20,B_20,B_20,B_20,B_23,B_23,   // 14..22
  1181. X        B_24,B_25,B_26,B_26,B_27}},                     // alev[0][1]
  1182. X    {{0,0,B_1,B_1,B_1,B_4_6_8_10,B_9,B_9,B_9,B_9,       // 0..9
  1183. X        B_13,B_13,B_13,B_13,B_16,B_16,B_16,B_16,B_16,   // 10..18
  1184. X        B_16,B_16,B_20,B_20,B_20,B_22,B_23,B_25,B_26},  // alev[1][0]
  1185. X     {0,B_1,B_6_8_10,B_6_8_10,B_6_8_10,B_10,B_10,B_10,  // 0..7
  1186. X        B_11,B_11,B_16,B_16,B_16,B_16,B_16,B_16,B_16,   // 8..16
  1187. X        B_18,B_18,B_20,B_20,B_21,B_22,B_23,B_24,B_25,   // 17..25
  1188. X        B_26,B_27}}};                                   // alev[1][1]
  1189. X//---------------------------------------------------------------------------
  1190. Xconst int
  1191. X  point5 = 1 ,  point44 = 3 ,  point43 = 4 ,  point33 = 5 ,  point3 = 13;
  1192. X
  1193. X// const pt_lev_set  pointset4 = B_4_6_8_10_12;
  1194. X        //  pointset3 = B_5_7_9_11_13;
  1195. X        //  danger4   = B_6_8_10_12;
  1196. X
  1197. X//---------------------------------------------------------------------------
  1198. Xconst int MAX_POINT = 100;
  1199. X
  1200. Xtypedef struct point_list_struct {
  1201. X        int n;
  1202. X        int x[MAX_POINT];
  1203. X        float v[MAX_POINT];
  1204. X} point_list;
  1205. X
  1206. X//---------------------------------------------------------------------------
  1207. X#include "debug.inc"
  1208. X//---------------------------------------------------------------------------
  1209. Xint max(int a, int b) {  return  ((a < b) ? b : a); }
  1210. Xint min(int a, int b) {  return  ((a > b) ? b : a); }
  1211. X//---------------------------------------------------------------------------
  1212. Xconst float
  1213. X  pv_wet[max_pt_lev+1]
  1214. X    ={0, 20000,11000,10800,10400,10100,            //0..5
  1215. X      1,1,1,1,1,1,1,1,                             //6..13
  1216. X      0.05,0.04,0.03,0.003,0.002,0.00021,0.00011,  //14..20
  1217. X      0.0000012,0.000001,0.0000001,0,0,0,0};       //21..27
  1218. X//---------------------------------------------------------------------------
  1219. Xfloat low_value(int p1, int p2) {
  1220. X  float v1=0, v2=0, w=0.9;
  1221. X  int   i,k;
  1222. X    for (i=point33+1; i<=max_pt_lev; i++) {
  1223. X        if ((k=bdstatus.pt_lev_rec.pc[p1][i]) > 0)  v1 += k * pv_wet[i];
  1224. X        if ((k=bdstatus.pt_lev_rec.pc[p2][i]) > 0)  v2 += k * pv_wet[i] ;
  1225. X    }
  1226. X    return (v1 * w - v2 * (1.0 - w));
  1227. X}
  1228. X//---------------------------------------------------------------------------
  1229. Xfloat value_of(int p1) {
  1230. X  int   p2,i,k,n1,n2;
  1231. X  float v;
  1232. X
  1233. X    p2 = 1 - p1;
  1234. X    n1 = bdstatus.pt_lev_rec.mp[p1];
  1235. X    n2 = bdstatus.pt_lev_rec.mp[p2];
  1236. X    if (n1 == point5)    v = pv_wet[point5];
  1237. X    else if (bdstatus.pt_lev_rec.pc[p2][point5] > 1)  v = -pv_wet[point5];
  1238. X    else if (n1 <= point33) v = pv_wet[n1];
  1239. X    else if (n2 <= point33) {
  1240. X           k = 0;
  1241. X           for (i=point5; i<=point33; i++)
  1242. X             k += bdstatus.pt_lev_rec.pc[p2][i];
  1243. X           switch (k) {
  1244. X             case 0: v = low_value(p1,p2); break;
  1245. X             case 1: v = (-7000 + low_value(p1,p2)); break;
  1246. X             default: v =  (-8000 + low_value(p1,p2)); break;
  1247. X           }
  1248. X         }
  1249. X    else  v = low_value(p1,p2);
  1250. X    return v;
  1251. X}
  1252. X//---------------------------------------------------------------------------
  1253. Xvoid sort_list0(point_list &mp) {
  1254. X  float  t;
  1255. X  int  i,j,n,k;
  1256. X      n=mp.n-1;
  1257. X      for (i=0; i<n; i++)    // sort mp.x[0..mp.n] by mp.v[0..mp.n]
  1258. X        for (j=i+1; j<=n; j++) {
  1259. X          if (mp.v[i] < mp.v[j]) {
  1260. X            k = mp.x[i];  mp.x[i] = mp.x[j];  mp.x[j] = k;
  1261. X            t = mp.v[i];  mp.v[i] = mp.v[j];  mp.v[j] = t;
  1262. X          }
  1263. X      }
  1264. X}
  1265. X//---------------------------------------------------------------------------
  1266. X
  1267. Xvoid sort_list1(point_list &mp, int p1) {
  1268. X  float  t;
  1269. X  int  p2,i,x;
  1270. X  update_record *z = new_update_record();
  1271. X  pt_lev_record *pt = new_pt_lev_record();
  1272. X    if (mp.n > 1) {
  1273. X      p2 = 1 - p1;
  1274. X      for (i=0; i<mp.n; i++) {
  1275. X        x = mp.x[i];
  1276. X        board[x] = player_color[p1];
  1277. X        update_board(1,x,z,pt);
  1278. X        mp.v[i] = t = -value_of(p2);
  1279. X        board[x] = blank;
  1280. X        restore(x,z,pt);
  1281. X      }
  1282. X      sort_list0(mp);
  1283. X    }
  1284. X    free(z); free(pt);
  1285. X}
  1286. X//---------------------------------------------------------------------------
  1287. Xstatic const int
  1288. X  m_lev[max_pt_lev+1] =
  1289. X       {0,1,2,2,2,2,3,3,3,3,3,3,4,4,5,5,5,5,5,5,5,5,5,5,5,5,5,5};
  1290. X//---------------------------------------------------------------------------
  1291. Xvoid sort_list2(point_list &mp, int p1) {
  1292. X  int  p2,i,x;
  1293. X
  1294. X    if (mp.n > 1) {
  1295. X      p2 = 1 - p1;
  1296. X      for (i=0; i<mp.n; i++) {
  1297. X         x = mp.x[i];
  1298. X         mp.v[i] = - ((bdstatus.point_lev[x][p1] << 5) -
  1299. X                           bdstatus.point_lev[x][p2]);
  1300. X      }
  1301. X      sort_list0(mp);
  1302. X    }
  1303. X}
  1304. X//---------------------------------------------------------------------------
  1305. X#define in_set(i,s) (s & (1L << (i-1)))
  1306. X//---------------------------------------------------------------------------
  1307. Xvoid add_point(int x, point_list &mp) {
  1308. X    if (mp.n < MAX_POINT) {
  1309. X        mp.x[mp.n] = x;
  1310. X        mp.v[mp.n] = 0;
  1311. X        (mp.n)++;
  1312. X    }
  1313. X}
  1314. X//---------------------------------------------------------------------------
  1315. Xpoint_list &init_point_list(point_list &mp) {
  1316. X    mp.n=0;  return mp;
  1317. X}
  1318. X//---------------------------------------------------------------------------
  1319. Xvoid select_point(int p1, int depth, point_list &mp, int &m1, int &m2) {
  1320. X  pt_lev_set  a00,a01,a10,a11;
  1321. X  int  i,p2,l1,l2;
  1322. X
  1323. X    p2 = 1 - p1;
  1324. X    m1 = bdstatus.pt_lev_rec.mp[p1];
  1325. X    m2 = bdstatus.pt_lev_rec.mp[p2];
  1326. X    a00 = alev[0][0][m1];  a01 = alev[0][1][m2];
  1327. X    a10 = alev[1][0][m1];  a11 = alev[1][1][m2];
  1328. X    for (i = start_pos; i <= end_pos; i++)
  1329. X      if (board[i] == blank) {
  1330. X          l1 = bdstatus.point_lev[i][p1];
  1331. X          l2 = bdstatus.point_lev[i][p2];
  1332. X          if ((in_set(l1,a00) && in_set(l1,a01)) ||
  1333. X              (in_set(l2,a10) && in_set(l2,a11)))
  1334. X             add_point(i,mp);
  1335. X      }
  1336. X  Check_No_Point("A",mp);
  1337. X    if ((depth == 1) && (step <= 3) && (step > 1)) 
  1338. X                sort_list1(mp,p1);
  1339. X    else        sort_list2(mp,p1);
  1340. X  Check_No_Point("B",mp);
  1341. X}
  1342. X//---------------------------------------------------------------------------
  1343. X#define with_danger_four(p) (bdstatus.pt_lev_rec.pc[p][4] \
  1344. X        + bdstatus.pt_lev_rec.pc[p][6] \
  1345. X        + bdstatus.pt_lev_rec.pc[p][8] \
  1346. X        + bdstatus.pt_lev_rec.pc[p][10])
  1347. X//---------------------------------------------------------------------------
  1348. Xfloat point_val(int x, int p1, int depth, float a) {
  1349. X        // using recursive alpha-beta prunning strategy
  1350. X  int           i,p2,l1,l2,m1,m2;
  1351. X  float         pv,m,t,a2;
  1352. X  point_list    mp;
  1353. X  update_record *z = new_update_record();
  1354. X  pt_lev_record *pt = new_pt_lev_record();
  1355. X
  1356. X    p2 = 1 - p1;
  1357. X    l1 = bdstatus.point_lev[x][p1];
  1358. X    l2 = bdstatus.point_lev[x][p2];
  1359. X    m = 0;
  1360. X    if (l1 == point5)       
  1361. X                pv = maxint - depth;
  1362. X    else if (l1 <= point44)
  1363. X                pv = maxint - depth - 2;
  1364. X    else if ((l1 <= point33) && !with_danger_four(p2))
  1365. X                pv = maxint - depth - 4;
  1366. X    else {
  1367. X        int continue_search =
  1368. X                 (depth <= min_depth) ||
  1369. X                 (((l2 <= point33) || (l1 <= point33)) &&
  1370. X                  ((depth < 9) || (depth <= max_depth)) ) ||
  1371. X//                 (in_set(l1,danger4) && depth < 15) ||
  1372. X                 ((l1 <= point3) && (depth <= max_depth));
  1373. X        board[x] = player_color[p1] ;
  1374. X        update_board(1,x,z,pt) ;
  1375. X        if (continue_search) {
  1376. X           select_point(p2,depth+1,init_point_list(mp),m2,m1) ;
  1377. X           m = 50000. ; i=0;
  1378. X           while ((i < mp.n) && (m > a))
  1379. X           {
  1380. X             if (m > 30000.)
  1381. X                  a2 = -30000.0;
  1382. X             else a2 = -m;
  1383. X             t = -point_val(mp.x[i],p2,depth+1,a2);
  1384. X             if (t < m)       m = t;
  1385. X             i++;
  1386. X           }
  1387. X           if (m != 0)   pv = m;
  1388. X           else          pv = -value_of(p2);
  1389. X        } else  pv = -value_of(p2);
  1390. X        board[x] = blank ;
  1391. X        restore(x,z,pt) ;
  1392. X    }
  1393. X    free(z); free(pt);
  1394. X    return pv;
  1395. X}
  1396. X//---------------------------------------------------------------------------
  1397. Xextern "C" int rand(void);
  1398. Xint random_move(point_list &goodp) {
  1399. X  int  i,j,n,k,x;
  1400. X  float  mv;
  1401. X    mv = -50000.0;  n=goodp.n; 
  1402. X    for (i=0; i<n; i++) {                       // assume that n>0
  1403. X      if (goodp.v[i] > mv) {
  1404. X         mv=goodp.v[i];  k=1;  x=goodp.x[i];
  1405. X      } else if (goodp.v[i] == mv) k++;
  1406. X    }
  1407. X    j = rand() % k;
  1408. X    for (i=0; i<n; i++)
  1409. X        if (goodp.v[i] == mv  &&  j-- <= 0)  return goodp.x[i];
  1410. X    return x;
  1411. X}
  1412. X//---------------------------------------------------------------------------
  1413. Xint computer_select(int p, point_list &goodp) {
  1414. X  int         m1,m2,i;
  1415. X  float       m,t;
  1416. X
  1417. X    if ((step == 1) && (p == 0)) return center_point;
  1418. X        // always start at the center position
  1419. X    select_point(p,1,init_point_list(goodp),m1,m2);
  1420. X    if (max_depth == 0) goodp.n = 1;
  1421. X  Check_No_Point("C",goodp);
  1422. X    if (goodp.n > 1) {
  1423. X      m = -30000.0;  i = 0; 
  1424. X      while ((i < goodp.n) && (m < 30000.0)) {
  1425. X        goodp.v[i] = t = point_val(goodp.x[i],p,1,m) ;
  1426. X        if (t > m)       m = t ;
  1427. X        i++;
  1428. X      }
  1429. X      goodp.n = i;
  1430. X    }
  1431. X  Check_No_Point("D",goodp);
  1432. X    return random_move(goodp);
  1433. X}
  1434. X//---------------------------------------------------------------------------
  1435. Xint num_of_suggestion, suggest_position[300];
  1436. X//---------------------------------------------------------------------------
  1437. Xextern "C" int computer_suggest(int p) {
  1438. X  int         i,best;
  1439. X  point_list  goodp;
  1440. X
  1441. X    if ((step == 1) && (p == 0)) {
  1442. X        num_of_suggestion = 1;
  1443. X        suggest_position[0] = center_point;
  1444. X        return center_point;
  1445. X    }
  1446. X    best = computer_select(p,goodp);
  1447. X    num_of_suggestion = goodp.n;
  1448. X    for (i=0; i<num_of_suggestion; i++)  
  1449. X        suggest_position[i] = goodp.x[i];
  1450. X    return best;
  1451. X}
  1452. X//---------------------------------------------------------------------------
  1453. Xextern "C" int computer_move(int p) {
  1454. X  point_list  goodp;
  1455. X
  1456. X    return computer_select(p,goodp);
  1457. X}
  1458. X//---------------------------------------------------------------------------
  1459. END_OF_FILE
  1460. if test 11252 -ne `wc -c <'select.C'`; then
  1461.     echo shar: \"'select.C'\" unpacked with wrong size!
  1462. fi
  1463. # end of 'select.C'
  1464. fi
  1465. if test -f 'xmake5.6' -a "${1}" != "-c" ; then 
  1466.   echo shar: Will not clobber existing file \"'xmake5.6'\"
  1467. else
  1468. echo shar: Extracting \"'xmake5.6'\" \(2156 characters\)
  1469. sed "s/^X//" >'xmake5.6' <<'END_OF_FILE'
  1470. X.TH XMAKE5 6  "28 November 1991"
  1471. X.SH NAME
  1472. Xxmake5 \- the game of 5-in-a-row
  1473. X.SH SYNOPSIS
  1474. X.B xmake5
  1475. X.SH DESCRIPTION
  1476. X.I Make5
  1477. Xis a game similar to Tic-Tac-Toe.
  1478. XIt is called Wu3-Zi3-Qi2 in Chinese and is 
  1479. Xvery popular in the Far East.
  1480. X5-in-a-row and Go-Moku are the other names
  1481. Xfor this game.
  1482. XYou may also find it called "Chess" 
  1483. Xon some Nitendo game cartridges.
  1484. XI call it Make5 because the goal of this game
  1485. Xis to make five continuous stones in a line.
  1486. X.LP
  1487. XThis game was originally played by two players
  1488. Xon a board of infinite size.  Each player puts
  1489. Xa stone at one empty cross-point at a time.  
  1490. XThe winner is the one who first puts five
  1491. Xcontinuous stones in a line, vertically, 
  1492. Xhorizontally, or diagonally.
  1493. X.LP
  1494. XHowever, this program plays the game on a finite
  1495. Xboard the same size as a GO game board, which has
  1496. X19 by 19 cross-points.
  1497. X.I The only tricky rule 
  1498. X.I is that you must make
  1499. X.I exactly five continuous 
  1500. X.I stones in a line to win.  
  1501. X.I Six or more stones in
  1502. X.I a line do not count.
  1503. X.LP
  1504. XSome people play this game with a rule which
  1505. Xprohibits the first player to make double-3 or 
  1506. Xdouble-4 attacking patterns.  But I do not
  1507. Xlike this rule and did not include it in this 
  1508. Xprogram.
  1509. X.LP
  1510. X.SH OPTIONS
  1511. XThis program can play with you or play with itself.  
  1512. XYou can also play with your friends and use this
  1513. Xprogram to update the board.
  1514. XMost of the options in the "Setup..." menu can be
  1515. Xchanged in the middle of a game.  Hence, you can
  1516. Xswitch the players, change the computer's searching
  1517. Xlevel, or even undo your moves.
  1518. XThe "Where..." menu provides hints for good
  1519. Xpositions and the position of the last move.
  1520. X.LP
  1521. XYou can switch to the challenge mode, in which
  1522. Xthe computer always moves first and you can not
  1523. Xundo, change play level or order, or get suggestions
  1524. Xfrom the computer.  If you beat the computer, your
  1525. Xname would be added into the list of winners.
  1526. X.LP
  1527. XHave fun!
  1528. X
  1529. X.SH BUGS
  1530. X.nf
  1531. XPlease send bugs to "hsiehch@cs.nyu.edu".
  1532. X.LP
  1533. XThis program does not have any learning ability.  
  1534. XYou could use the same strategy to beat it again and again.
  1535. X.fi
  1536. X.sp
  1537. X.SH AUTHOR
  1538. XChih-Hung Hsieh
  1539. X.sp
  1540. X.SH "SEE ALSO"
  1541. Xcmake5 \- a simplified version that runs on ASCII terminals.
  1542. X
  1543. END_OF_FILE
  1544. if test 2156 -ne `wc -c <'xmake5.6'`; then
  1545.     echo shar: \"'xmake5.6'\" unpacked with wrong size!
  1546. fi
  1547. # end of 'xmake5.6'
  1548. fi
  1549. if test -f 'xmake5.doc' -a "${1}" != "-c" ; then 
  1550.   echo shar: Will not clobber existing file \"'xmake5.doc'\"
  1551. else
  1552. echo shar: Extracting \"'xmake5.doc'\" \(3823 characters\)
  1553. sed "s/^X//" >'xmake5.doc' <<'END_OF_FILE'
  1554. XName of the game:
  1555. X=================
  1556. X
  1557. XMake5 is a game similar to Tic-Tac-Toe.
  1558. XIt is called Wu3-Zi3-Qi2 in Chinese and is 
  1559. Xvery popular in the Far East.  5-in-a-row and
  1560. XGo-Moku are the other names for this game.
  1561. XYou may also find it called "Chess" on some
  1562. XNitendo games.  I call it Make5 because the goal
  1563. Xof this game is to make five continuous stones
  1564. Xin a line.
  1565. X
  1566. X
  1567. XHow to play:
  1568. X============
  1569. X
  1570. XThis game was originally played by two players
  1571. Xon a board of infinite size.  Each player puts
  1572. Xa stone at one empty cross-point at a time.  
  1573. XThe winner is the one who first puts five
  1574. Xcontinuous stones in a line, vertically, 
  1575. Xorizontally, or diagonally.
  1576. X
  1577. XHowever, this program plays the game on a finite
  1578. Xboard the same size as a GO game board, which has
  1579. X19 by 19 cross-points.  The only tricky rule is
  1580. Xthat you must make exactly five continuous stones
  1581. Xin a line to win.  Six or more stones in a line
  1582. Xdo not count.
  1583. X
  1584. XSome people play this game with a rule which
  1585. Xprohibits the first player to make double-3 or 
  1586. Xdouble-4 attacking patterns.  But I do not
  1587. Xlike this rule and did not include it in this 
  1588. Xprogram.
  1589. X
  1590. X
  1591. XStrategies:
  1592. X===========
  1593. X
  1594. XSo, you see why it is like Tic-Tac-Toe.  
  1595. XYou have to stop the other player's continuous 
  1596. Xlines of stones and design your own attacking lines.
  1597. XUnlike Tic-Tac-Toe, this game is played on a large
  1598. Xboard and requires five stones in a line to win.  
  1599. XIs there a winning strategy for the first player?  
  1600. XYou tell me.
  1601. X
  1602. X
  1603. XOptions of playing:
  1604. X===================
  1605. X
  1606. XThis program can play with you or play with itself.  
  1607. XYou can also play with your friends and use this
  1608. Xprogram to update the board.
  1609. X
  1610. XMost of the options in the "Setup..." menu can be
  1611. Xchanged in the middle of a game.  Hence, you can
  1612. Xswitch the players, change the computer's searching
  1613. Xlevel, or even undo your moves.
  1614. XThe "Where..." menu provides hints for good
  1615. Xpositions and the position of the last move.
  1616. X
  1617. XYou can switch to the challenge mode, in which
  1618. Xthe computer always moves first and you can not
  1619. Xundo, change play level or order, or get suggestion
  1620. Xfrom the computer.  If you beat the computer, your
  1621. Xname would be added into the list of winners.
  1622. X
  1623. XHave fun!
  1624. X
  1625. X
  1626. XHistory of this program:
  1627. X========================
  1628. X
  1629. XThe basic playing algorithm was designed in 1984
  1630. Xas a term project of an A.I. class; it was written
  1631. Xin Pascal and runs on Prime-750.  The game was
  1632. Xported to Turbo Pascal and ran on PC in 1986.
  1633. X
  1634. XNow this game is translated to C and C++ with an
  1635. XX interface.  Another version called cmake5 is also
  1636. Xavailable.  It uses the UNIX curses library and runs
  1637. Xon most ASCII terminals.
  1638. X
  1639. X
  1640. XChih-Hung Hsieh      November 1991
  1641. X
  1642. X(Please send your comment to hsiehch@cs.nyu.edu.)
  1643. X
  1644. X
  1645. X
  1646. X       Hsieh             
  1647. X------------------------ 
  1648. X ,,,       ||'      ||'  
  1649. X  '||    ,,|,,,|    ||   
  1650. X,,,,|,|, ||   ||    ||   
  1651. X         ||'''|| ,,,||,| 
  1652. X ,,,,|,  ||,,,||    ||   
  1653. X         ||   ||,,  ||   
  1654. X ''''''  || ,,||'   ||   
  1655. X ,     '||'' ,|| |  ||   
  1656. X ||''||    ,|'||  | ||   
  1657. X ||  || ,,''  ||    ||   
  1658. X ||  ||       ||    ||   
  1659. X ||''''    ''||' ''||'   
  1660. X------------------------ 
  1661. X       Chih              
  1662. X------------------------ 
  1663. X            ||'          
  1664. X            ||        ,, 
  1665. X '''''''''''||'''''''''''
  1666. X            ||           
  1667. X            ||      ,,   
  1668. X   ''''''''''''''''''''  
  1669. X           ,,            
  1670. X    ,  ||'  '|,    ,,    
  1671. X    |  ||    ''     '|,  
  1672. X  ,|'  ||         |  '|| 
  1673. X ,||   ||         |,  ||'
  1674. X ''    '|||||||||||'     
  1675. X------------------------ 
  1676. X       Hung              
  1677. X------------------------ 
  1678. X,,,,,,,,,|,     ||,      
  1679. X       ||'     ||        
  1680. X       ||      ||        
  1681. X|,,,,,,||     ,|'        
  1682. X||     ''     ||         
  1683. X||            ||         
  1684. X||,,,,,,|,   ||          
  1685. X''     ||'   |'   ',     
  1686. X       ||   |'     '|    
  1687. X      ,|'  ,'      ,||   
  1688. X     ,|' ,,|,,,|''' '||  
  1689. X'''|||'   ''''       ||  
  1690. X------------------------ 
  1691. END_OF_FILE
  1692. if test 3823 -ne `wc -c <'xmake5.doc'`; then
  1693.     echo shar: \"'xmake5.doc'\" unpacked with wrong size!
  1694. fi
  1695. # end of 'xmake5.doc'
  1696. fi
  1697. echo shar: End of archive 2 \(of 3\).
  1698. cp /dev/null ark2isdone
  1699. MISSING=""
  1700. for I in 1 2 3 ; do
  1701.     if test ! -f ark${I}isdone ; then
  1702.     MISSING="${MISSING} ${I}"
  1703.     fi
  1704. done
  1705. if test "${MISSING}" = "" ; then
  1706.     echo You have unpacked all 3 archives.
  1707.     rm -f ark[1-9]isdone
  1708. else
  1709.     echo You still need to unpack the following archives:
  1710.     echo "        " ${MISSING}
  1711. fi
  1712. ##  End of shell archive.
  1713. exit 0
  1714.