home *** CD-ROM | disk | FTP | other *** search
/ Giga Games 1 / Giga Games.iso / net / go / prog / inetgo72.sh < prev    next >
Encoding:
Linux/UNIX/POSIX Shell Script  |  1993-06-20  |  94.1 KB  |  4,455 lines

  1. #! /bin/sh
  2. # This is a shell archive, meaning:
  3. # 1. Remove everything above the #! /bin/sh line.
  4. # 2. Save the resulting text in a file.
  5. # 3. Execute the file with /bin/sh (not csh) to create:
  6. #    README
  7. #    Makefile
  8. #    go.6
  9. #    backup.c
  10. #    changes.c
  11. #    connect.c
  12. #    curse.c
  13. #    board.c
  14. #    doloop.c
  15. #    doother.c
  16. #    file.c
  17. #    go.c
  18. #    handicap.c
  19. #    help.c
  20. #    life.c
  21. #    loop.c
  22. #    mesg.c
  23. #    opts.c
  24. #    putpiece.c
  25. #    score.c
  26. #    strength.c
  27. #    tick.c
  28. #    traps.c
  29. #    var.c
  30. #    go.h
  31. #    std.disclaimer
  32. # This archive created: Fri Nov 15 23:50:54 1991
  33. export PATH; PATH=/bin:/usr/bin:$PATH
  34. if test -f 'README'
  35. then
  36.     echo shar: "will not over-write existing file 'README'"
  37. else
  38. cat << \SHAR_EOF > 'README'
  39.         Copyright 1990      Greg Hale
  40.         Portions Copyright 1990, Fred Hansen
  41.  
  42. Permission to use, copy, modify, and distribute this
  43. software and its documentation for any purpose and without
  44. fee is hereby granted, provided that the above copyright
  45. notice appear in all copies and that both that copyright
  46. notice and this permission notice appear in supporting
  47. documentation.  No representations are made about the
  48. suitability of this software for any purpose.  It is
  49. provided "as is" without express or implied warranty.
  50.  
  51. -----------
  52.  
  53. To make the Internet GO board type:
  54.  
  55.     make
  56.  
  57. If you get re-defined errors from connect.c, remove the lines near the top
  58. between and including the #ifndef.
  59.  
  60. By default, the program will install at   .    
  61. To change this, modify the BINDIR variable in the Makefile.
  62. It will install the manual page in MANDIR (default:   . ).
  63.  
  64. If you want the long help option to work, you will need to change
  65. the HELP_CMD in go.h to reference the correct directory.
  66.  
  67.  
  68. Have fun and please report all bugs to: 
  69.             Greg Hale (hale@scam.berkeley.edu)
  70.          or Adrian Mariano (adrian@milton.u.washington.edu)
  71.  
  72. P.S.  Be sure to add yourself to the internet go players list by sending 
  73.       mail to adrian@milton.u.washington.edu.
  74.  
  75. -----------
  76. Changes:
  77.  
  78. 11/15/87 (v 1.2)
  79.     Add command line arguements, variable board size, handicapping.
  80.     Select the port available to the user in case
  81.     several games are running at once to avoid collisions.
  82.  
  83. 11/23/87 (v 1.5)
  84.     -c option for command line welcome message.  Show last move
  85.     command (key is '/').  Beeps when a message is sent.  Nomove.c
  86.     modified; some compilers thought the expression was too complicated.
  87.  
  88. 11/27/87 (v 1.6)
  89.     Keep track of stregth and wins in a default file in user's home
  90.     directory.  Use this to determine sides and handicapping.
  91.     I/O problems (when selecting socket and stdin) fixed.
  92.  
  93. 1/30/88 (v 2.0)
  94.     Add demo mode and optional beeping. 
  95.  
  96. 2/10/88 (v 2.1)
  97.     Change in arguments, modification to strength and scoring
  98.     algorithm.  A bug in declining that had led to lock up was fixed.
  99.     Among other options, KOMI was added to scoring.
  100.  
  101. 4/13/88 (v 4.2)
  102.         Fixed scoring and option bug
  103.  
  104. 1/30/90 (v 5.0)
  105.     Add coordinates to the side of the board.  Show captured stones.
  106.     At the end of the game, clear the screen using
  107.     carriage returns instead of Clear() BEFORE the score info is printed.
  108.  
  109. 2/15/90
  110.     Interface is cleaned up, synchonization for load games,
  111.     Exit the message section by ^D,
  112.     and restore saved game.
  113.  
  114. 7/17/90 (v 7.0)
  115.         Added move by move game logging to Smart-Go, and restore from 
  116.        Smart-Go files.  
  117.     Added inverse video and made it easy to redefine black stone character.
  118.     Added number keys for movement
  119.     Handicap information is only used if the -E option is specified
  120.     Cleaned up options.
  121.  
  122. 11/10/90 (v 7.1)
  123.     Fixed so ^D from message will invent a newline if none given
  124.     Added automatic timekeeping
  125.         Byoyomi allows for a sequence of periods in each of
  126.         which the player must make some given number of moves.
  127.         If the opponent's version of inetgo doesn't have timing,
  128.         then he is sent a time message after each move.
  129.     Added * as HANDICAP mode command to set standard handicaps
  130.     Added T as HANDICAP mode command to set time limit parameters
  131.     Reformatted the indenting in DoOther()
  132.     Changed so S prints a message only if game really saved
  133.     Revised help message to differ for the three principle modes
  134.     Fixed homemes() to put next message at top of message area
  135.  
  136.         Fixed Smart-Go load to not print the file, and to correctly handle
  137.             captured stones.
  138. SHAR_EOF
  139. fi
  140. if test -f 'Makefile'
  141. then
  142.     echo shar: "will not over-write existing file 'Makefile'"
  143. else
  144. cat << \SHAR_EOF > 'Makefile'
  145. # Makefile for Go version 7.20
  146. # by Greg Hale
  147. # Monday, June 8, 1987
  148. # Modified by Jeff Boscole ( aesop@blake.acs.washington.edu )  8/31/89
  149. # Modified by Adrian Mariano ( adrian@u.washington.edu ) 7/13/90
  150. # Modified by Fred Hansen ( wjh+@andrew.cmu.edu ) 8 Nov 1990
  151.  
  152. CFLAGS= -w -DINVERSE=${INVERSE} -DBLACK=${BLACK} -DVERSION='"Go 7.20"'
  153.  
  154. # Video options.  Set INVERSE to 128 to set default to inverse video
  155. # or set it to 0 to get normal video as default.  Set BLACK to the
  156. # default character for black stones.
  157.  
  158. INVERSE = 128 
  159.  
  160. #INVERSE = 0
  161.  
  162. #This line gets black # for black stones
  163. #BLACK = 35
  164.  
  165. BLACK = "'*'"
  166.  
  167. # destination manual pages
  168. MANSRC=go.6
  169. MAN=go.doc
  170.  
  171. # destination directory vvvvvvv ---  put your directory here  vvvvvvvvvvvv |
  172. MANDIR= .
  173. BINDIR= .
  174.  
  175. # PROGRAM NAMES        ^^^^^^^^ ---  put your directory here  ^^^^^^^^^^^^ |
  176. GO=go
  177. SHAR=shar
  178. SHARCHIVE=inetgo.sh
  179.  
  180. FORMATTER=format
  181.  
  182. # files which make up the shell archive along with sources
  183. FILES = README Makefile $(MANSRC) 
  184.  
  185. MOBJECTS = curse.o \
  186.            board.o \
  187.         doloop.o \
  188.         go.o \
  189.         loop.o \
  190.         mesg.o \
  191.         tick.o \
  192.         traps.o 
  193.  
  194. SHARED = changes.o \
  195.         connect.o \
  196.         backup.o \
  197.         doother.o \
  198.         file.o \
  199.         handicap.o \
  200.         life.o \
  201.         strength.o \
  202.         help.o \
  203.         opts.o \
  204.         putpiece.o \
  205.         score.o \
  206.         var.o 
  207.  
  208. SRCS =  backup.c changes.c \
  209.         connect.c curse.c \
  210.         board.c \
  211.         doloop.c doother.c \
  212.          file.c   \
  213.         go.c  handicap.c  help.c \
  214.         life.c  loop.c \
  215.            mesg.c \
  216.         opts.c \
  217.         putpiece.c \
  218.         score.c \
  219.         strength.c \
  220.          tick.c \
  221.         traps.c \
  222.         var.c
  223.  
  224. HDRS =    go.h \
  225.     std.disclaimer
  226.  
  227. all: $(GO) $(MAN)
  228.  
  229. $(GO): $(MOBJECTS) $(SHARED)
  230.     @echo "loading $(GO)..."
  231.     @cc $(MOBJECTS) $(SHARED) -lcurses -ltermlib -o $(BINDIR)/$(GO);
  232.     @echo "done."
  233.  
  234. $(MAN): $(MANSRC)
  235.     @echo -n "typesetting manual..."
  236.     @nroff -man $(MANSRC) > $(MANDIR)/$(MAN)
  237.     @echo "done."
  238.  
  239. tags:
  240.     ctags *.c *.h
  241.  
  242. clean:
  243.     @echo -n "removing extra files..."
  244.     @-rm -f *.o $(GO) $(SHARCHIVE) $(SHARCHIVE).Z
  245.     @echo "done."
  246.  
  247. make:
  248.     mkmf -d
  249.  
  250. archive:
  251.     shar $(FILES) $(SRCS) $(HDRS)  > igo.sh
  252.  
  253. # alternate for new archive program
  254. archive1:
  255.     shar -m 100000 -f $(SHARCHIVE) $(FILES) $(SRCS) $(HDRS)
  256.  
  257. $(MOBJECTS): go.h
  258. $(SHARED): go.h
  259.  
  260. checkout:
  261.     co -l $(SRCS) go.h
  262. checkin:
  263.     ci $(SRCS) go.h
  264. SHAR_EOF
  265. fi
  266. if test -f 'go.6'
  267. then
  268.     echo shar: "will not over-write existing file 'go.6'"
  269. else
  270. cat << \SHAR_EOF > 'go.6'
  271. .TH GO 6  "6 September 1991"
  272. .SH NAME
  273. go \- the oriental game of go
  274. .SH SYNOPSIS
  275. .B go
  276. [option switches] user[@host]
  277. .SH DESCRIPTION
  278. .I Go
  279. is an ancient oriental strategy game based on the capturing of territory.  
  280. The players alternate putting stones on the board, 
  281. trying to surround as many empty intersections as possible.  
  282. Although go rules are very similar everywhere, there are variations in the 
  283. details of scoring;  in general this program corresponds 
  284. to the Japanese method of scoring.
  285. If you do not know how to play,
  286. it may help to find someone who does (look at the file 
  287. .B goplayers
  288. ) and have him or her explain.
  289. .SH WHAT TO DO
  290. The standard rogue keys
  291. .B [hjklyubn]
  292. are used for cursor movement and the space bar selects a point.
  293. If rogue keys are not one's "cup of tea" then the numeric keypad 
  294. .B [12346789] 
  295. may be used:
  296. .B [?]
  297. will give a short help list for further commands.
  298. When a command is inappropriate at the given time, 
  299. the game will beep when the action is attempted.
  300. .LP
  301. [CTRL-C] will exit the game at any time.
  302. .LP
  303. A [>] indicates which player one is by
  304. appearing next to the player status at the bottom of the screen.
  305. Either player can switch which player he is by selecting the switch command.
  306. (Use the panic command if both players are the same color.  The panic command
  307. only switches one side.)
  308. .LP
  309. When the game begins,
  310. both players have the option of setting up the handicap until play begins.
  311. Selecting a point on the board puts a black piece down or
  312. takes it away if there is already one there.
  313. After setting up the handicap,
  314. either player can select the play option to begin the game.
  315. .LP
  316. NOTE- the program keeps track of respective player strengths
  317. in a file in the home directory called '.go_strength'.
  318. It contains two values separated by a space and followed
  319. by a carriage return.
  320. .LP
  321. The first value is the player strength,
  322. starting at 35 kyu = value -5,
  323. and working down to 1 kyu = value 29.
  324. Higher values represent dan level players.
  325. The second value is the number of games won (if positive),
  326. or the number of games lost (if negative).
  327. .LP
  328. Versions of Inet GO prior to 7.0 take the difference in
  329. player strengths from the info in '.go_strength' to determine handicap stones.
  330. For each point difference,
  331. one handicap stone is given
  332. to the weaker player on a 19x19 board.
  333. Smaller boards reduce this handicap proportionally.
  334. After the player wins or looses several games
  335. in a row,
  336. his rank changes accordingly.
  337. Inet GO version 7.0 and future versions do not set handicapping 
  338. automatically in the initial display window unless players specify the -E
  339. option on the run-time command line. 
  340. .LP
  341. Note: One may set rank with command line options.
  342. .LP
  343. If any player does not like the rank assigned automatically by computer,
  344. the handicap stones may be changed manually,
  345. as well as player rank.
  346. .LP
  347. Play begins with black if no handicap stones are put down,
  348. otherwise play begins with white.
  349. Afterwards,
  350. play alternates until the end of the game.
  351. The most recent move can be shown by selecting the Last command.
  352. .LP
  353. When a player thinks the game is over,
  354. he may select the score option.
  355. This will enable scoring and both players
  356. can remove the dead groups from the board.
  357. If either player disagrees with the scoring and/or wishes to resume play,
  358. the cancel option returns the game to the state just before scoring
  359. and play resumes as before.
  360. The player whose turn it was when scoring began resumes his turn.
  361. If both players agree to scoring,
  362. the quit option should be selected by either player.
  363. The other player will be queried to make sure he agrees with the scoring,
  364. the the program will print the resulting score.
  365. .LP
  366. Another way to leave the game is via the resign option.
  367. When a player resigns,
  368. the other player is automatically declared a winner and the score
  369. files are updated.
  370. .LP
  371. The game also terminates when either player runs out of time.  
  372. The other player is automatically declared a winner and the score
  373. files are updated.  The time limits and byoyomi options are set 
  374. during game setup by by 'T' command.
  375. .LP
  376. There are several byoyomi schemes, most of which are supported by this 
  377. program.  The program implements three parameters for byoyomi:
  378. .IP
  379. .B Seconds -
  380. The number of seconds per byoyomi period.   Default 400 for 20 seconds per stone.
  381. .IP
  382. .B Stones -
  383. The number of stones to play in a period.   Default 20 stones.
  384. .IP
  385. .B Extends -
  386. The number of occasions when time can run out without losing.  Default zero.
  387. Use for Japanese professional byoyomi.
  388. .LP
  389. It is a good idea to give a little extra time per stone in byoyomi because the 
  390. mechanics of making a move are harder.
  391. .LP
  392. In most North American tournaments the value of Extends is zero.  
  393. This means that the player may have as many byoyomi periods as desired
  394. and must use the number of stones given by the Stones parameter during
  395. each period.  Typically this is using 20 stones in 5 minutes 
  396. or 30 stones in 10 minutes.  If the Stones are used before time runs out, the 
  397. player is given another set of stones and the timer is set back to Seconds.
  398. .LP
  399. In European play the Extends value is also zero but the player is given a 
  400. certain number of seconds to play each stone.  In this case the Stones parameter 
  401. is 1 and the number of Seconds is whatever is allowed.
  402. .LP
  403. In Japanese professional play, Stones is 1, seconds are 60, and Extends are 4.
  404. At the beginning of byoyomi the player is shown as having 5 minutes for 
  405. the current byoyomi period and the 4 extends.  If the player completes a move 
  406. in under one minute, the time for the next move is again 5 minutes.  Each extend is 
  407. an extra minute that can be used for a move during byoyomi.  After it is used, 
  408. the total time alloted is one minute less.  Thus if a player has five minutes 
  409. and uses 121 seconds for one stone only three minutes will be shown for 
  410. subsequent plays.
  411. .LP
  412. Please note that the timing version of inetgo will operate with
  413. prior versions.  If the opponent does not have a clock, the side with the
  414. clock keeps him informed by sending message notes with the clock values.
  415. .LP
  416. When both players are using 7.1 or better, each keeps his or her own clock.  But
  417. while the opponent is moving, the local inetgo is keeping a shadow
  418. version of the  opponent's clock.  Since there can be network delays,
  419. the opponents clock can appear to move backward when his or her turn
  420. ends;  the amount of the jump reflects the network delay.  Consequence:
  421. you will never run out of time due to something on your opponents
  422. machine or due to network delay (even though it may temporarily appear
  423. to your opponent as though you have run out of time when you haven't.)
  424. .LP
  425. If this version is used with an old version (or possibly due to a bug), 
  426. the program may start up incorrectly, with both sides proclaiming "Your turn"
  427. or "Waiting for opponent."  In this case, use the panic key, ctrl-P to switch 
  428. the state on your end only to allow the game to proceed.
  429. .SH OPTIONS
  430. .TP 8
  431. .B none
  432. Print out the options and a short explanation of each.
  433. .LP
  434. .TP 8
  435. .B -h
  436. Print out this help file.
  437. .LP
  438. .TP 8
  439. .B -p
  440. Set the port to the specified port number.
  441. This is so the connection can be forced to a
  442. free port if several programs are running at once.
  443. .LP
  444. .TP 8
  445. .B -q
  446. Quiet -- don't issue any beeps. 
  447. .LP
  448. .TP 8
  449. .B -s
  450. Set the size of the board to a value from 7 to 19.
  451. If both players select a size,
  452. the smaller board will be used.
  453. .LP
  454. .TP 8
  455. .B -n
  456. Set the number of times to blink a piece.
  457. This is useful for various screen-display speeds.
  458. .LP
  459. .TP 8 
  460. .B -E
  461. Use the handicapping info from the respective .go_strength files.
  462. If both players specify -E then the .go_strength file info is used
  463. to calculate a correct handicapping on the display at initialization.
  464. If one of the players is using a former version of Inet GO previous
  465. to release version 7.0, then the .go_strength files will be used.
  466. If both players are using Inet GO release version 7.0, or subsequent
  467. releases, then the the initial display will, by default, show -no-
  468. handicapping stones.   To provide for an initial handicap setting -other-
  469. than a value calculated from the respective .go_strength files, do not
  470. specify -E, but use the -H option or the '*' command during setup.
  471. .LP
  472. .TP 8
  473. .B -c 
  474. Gives an opening message and credits. 
  475. .LP
  476. .TP 8
  477. .B -H
  478. Set the number of handicap stones to the value specified.
  479. If the two players select different numbers,
  480. the larger value will be used.
  481. .LP
  482. .TP 8
  483. .B -r
  484. Give the program's approximation of player rank and wins.
  485. .LP
  486. .TP 8
  487. .B -R
  488. Modify current player rank.  
  489. ``go -R 5 k'' would set player rank to 5 kyu (amateur).
  490. ``go -R 5 d'' would set player rank to 5 dan (middle ranks).
  491. ``go -R 5 p'' would set player rank to 5 professional dan (highest ranks).
  492. ``go -R +'' would increase player rank by one.
  493. ``go -R -'' would decrease player rank by one.
  494. The lowest rank is 35 kyu,
  495. climbing to 1 kyu.
  496. Then one may become 1 dan (Shodan),
  497. increasing to 7 dan.
  498. Lastly,
  499. the professional ranks go from 1 to 9 professional dan.
  500. These 51 rankings are linked to 51 states of Buddha consciousness.
  501. .LP
  502. .TP 8
  503. .B -l
  504. Load a file.
  505. ``-l filename'' will load a saved file.
  506. The format is as follows:
  507. all numbers are separated by spaces.
  508. The first value is the board size (7-19).
  509. The next is the current player (0-1=b/w).
  510. Then a `#' delimits the board info on a line by itself.
  511. Following are rows of the board with a newline at the end of each.
  512. At the end of the rows is another `#' on a new line.
  513. Then the captured black, captured white, cursor x and y positions follow.
  514. You will be prompted for a filename.
  515. .LP
  516. .TP 8
  517. .B -L
  518. Initiate game-logging to the 'Smart-GO' file format.
  519. ``-L sgfile'' will output the game-record as the game is played.
  520. If the specified file already exists, it will be loaded as 
  521. a 'Smart-GO' file.   This
  522. option is intended to restore logged games, rather than to read Smart-Go
  523. files in general.  Only the AddBlack, AddWhite, AddEmpty, White, and Black
  524. Smart-Go commands are supported.  Variations will be superimposed. 
  525. This takes precedence over the -l option
  526. for restoring a game.
  527. .LP
  528. .TP 8
  529. .B -a
  530. Do not include the player messages from the
  531. discussion windows in the 'Smart-GO' game record.
  532. .LP
  533. .TP 8
  534. .B -V
  535. Flip (invert) the video orientation opposite to
  536. whatever the default compile options were.
  537. .LP
  538. .TP 8
  539. .B -B
  540. Use ascii code number, or char for displaying the Black stones.
  541. (e.g.  -B 42, or -B \\* gives the '*' character).
  542. .LP
  543. .LP
  544. .B Setting/unsetting 
  545. .B stones
  546. .B during play:
  547. The 'z' and 'x' keys set/unset stones on the board.
  548. .LP
  549. .SH ABOUT THE GAME
  550. In the rest of this document,
  551. [O] refers to white or player two,
  552. and [@] refers to black or player one.
  553. .LP
  554. Some general rules are common.
  555. First of all, liberties are the
  556. free points horizontally or vertically adjacent to a group.
  557. In the following examples,
  558. white has 0,1,2,3,4,5, and 6 liberties
  559. respectively:
  560. .sp
  561. .nf
  562.      (l = liberty, normally a [.])
  563.      (# = out of bounds)
  564.  
  565.      #. @ .      #. @ .     #. @ .     #. @ .     #. l .
  566.      #@ O @      #@ O l     #l O l     #l O l     #l O l
  567.      #. @ .      #. @ .     #. @ .     #. l .     #. l .
  568.      ######      ######     ######     ######     ######
  569.  
  570.      #. l @ .    #. l l .
  571.      #l O O l    #l O O l
  572.      #. l l .    #. l l .
  573.      ########    ########
  574. .fi
  575. .LP
  576. During play,
  577. the players are not allowed to play a point when the 
  578. corresponding group will have no liberties at the end of
  579. the turn.  This is the "no suicide" rule.
  580. .LP
  581. When the last liberty of a group is taken away,
  582. it is captured.
  583. These captured stones count one point at the end of the game.
  584. .sp
  585. .nf
  586.      (@ plays at 1)
  587.      #. . . . .                #. . . . .
  588.      #. @ @ @ .                #. @ @ @ .
  589.      #@ O O O 1   --->         #@ . . . @
  590.      #. @ @ @ .                #. @ @ @ .
  591.      #. . . . .                #. . . . .
  592.      ##########                ##########
  593. .fi
  594. .LP
  595. A territory which can not be saved does not have to be removed
  596. from the board before the end of the game.
  597. The surrounding player can remove the stones during scoring mode at the end of
  598. the game without having to play it out.
  599. .LP
  600. In these examples,
  601. white owns the territory surrounded unconditionally.
  602. Black can not fill in the last point
  603. of either hole since he will not capture any stones
  604. in the process.
  605. Some of the points may be filled,
  606. but white will eventually capture the black stones no matter
  607. what black does.
  608. If black does try this,
  609. white will simply wait and gain points by passing.
  610. .sp
  611. .nf
  612.      #. . . . . . . . .    #. . . . . . . . .
  613.      #. . . . . . . . .    #. . . . . . . . .
  614.      #@ @ @ @ @ @ @ @ .    #. . . . . . . . .
  615.      #O O O O O O O @ .    #@ @ @ @ . . . . .
  616.      #. . * O . . O @ .    #O O O @ . . . . .
  617.      #. . O O . . O @ .    #O . O @ . . . . .
  618.      #. . . O . . O @ .    #. O O @ . . . . .
  619.      ##################    ##################
  620. .fi
  621. .LP
  622. In these examples,
  623. white does
  624. .B not
  625. own the territory because
  626. black can fill in the remaining points and kill white.
  627. It is important to understand that black will lose one or two
  628. pieces in the second example,
  629. but will succeed in the end.
  630. .sp
  631. .nf
  632.      #. . . . . .           #. . . . . .
  633.      #. . . . . .           #. . . . . .
  634.      #@ @ @ @ . .           #@ @ @ @ @ .
  635.      #O O O @ . .           #O O O O @ .
  636.      #. . O @ . .           #. @ . O @ .
  637.      ############           ############
  638. .fi
  639. .LP
  640. In this example,
  641. if white goes first and plays the center point,
  642. he will have what is known as a cats eye and will be safe.
  643. If black goes first and plays this point,
  644. white is dead.
  645. .sp
  646. .nf
  647.      #. . . . . .
  648.      #. . . . . .
  649.      #@ @ @ @ @ .
  650.      #O O O O @ .
  651.      #. . . O @ .
  652.      ############
  653. .fi
  654. .LP
  655. In all cases where a group like these can be considered dead,
  656. they can be removed from the board at the end
  657. of the game without further play.
  658. This of course excludes cases where the external
  659. group will die before it has
  660. a chance to kill the internal group.
  661. .LP
  662. Another common situation is as follows:
  663. .sp
  664. .nf
  665.      . . . . . .
  666.      . . . . . .
  667.      . O O @ @ .
  668.      . O . O @ .
  669.      . O O @ @ .
  670.      . . . . . .
  671. .fi
  672. .LP
  673. If black plays the empty space capturing white,
  674. white can then capture black,
  675. etc.
  676. This can go on forever.
  677. This situation is a
  678. .B KO,
  679. and white is not allowed to take black immediately.
  680. White
  681. .B MUST
  682. play somewhere else,
  683. then if black does not fill the KO,
  684. white can then try to take it,
  685. then black must play somewhere else.
  686. Sooner or later,
  687. someone should fill it before scoring is done.
  688. .LP
  689. If there is any debate whether territory is owned by a player,
  690. just play further and the winner will prevail.
  691. .LP
  692. A good strategy in the beginning is to try to build stable
  693. structures.
  694. When something is stable,
  695. one may attach appendages
  696. to it and expand safely.
  697. For beginners,
  698. one big strong group is better than
  699. several spread out vulnerable groups.
  700. .LP
  701. Later,
  702. try to spread out:
  703. place one or two pieces in open territory to obtain
  704. influence over that section of the board.
  705. Good Go players need only to put one piece near a
  706. corner to know that they have a good chance of owning it
  707. later.
  708. .LP
  709. At the end of the game, when scoring,
  710. each captured stone is worth one point,
  711. and each point owned as territory is one point.
  712. The player with the most points wins.
  713. The procedure is to erase all groups both players
  714. agree have no chance of surviving.
  715. If at any time a disagreement occurs,
  716. either player can cancel scoring and continue the
  717. game at the point before scoring occurred.
  718. .LP
  719. When all scoring is complete,
  720. both players must agree to quit and the game
  721. with print out the score.
  722. .LP
  723. As a final note, I highly recommend a 
  724. purchase of go literature if one intends to enjoy
  725. the game to its fullest.
  726. To pass through the lower levels swiftly and correctly,
  727. I STRONGLY recommend the _Graded Go Problems for Beginners_
  728. series by the Ishi Press.
  729. Almost any game store should be able to supply it.
  730. .SH FILES
  731. go.doc         this file
  732. .sp
  733. $(HOME)/.go_strength    a file kept in the player's home directory keeping track of ranks and wins.
  734. .sp
  735. go.players    a file set up by users to tell other players who they are.
  736. .sp
  737. .SH BUGS
  738. .nf
  739. A SiZe[xx] statement in a Smart-Go file will be ignored.
  740. .LP
  741. When loading a Smart-Go file, the program may not correctly 
  742. identify the player whose turn it is.
  743. .LP
  744. Smart-Go files must not contain variations
  745. .LP
  746. If both players specify -L on files that contain game data, 
  747. the two games will be superimposed.
  748. .LP
  749. There is no way to save or load game timing information.
  750. .LP
  751. Send further bug reports to "adrian@u.washington.edu",
  752. "...!ucbvax!scam!hale" or "hale@scam.Berkeley.EDU"
  753. .fi
  754. .sp
  755. .SH AUTHORS
  756. Greg Hale (hale@scam.berkeley.edu)
  757. .LP
  758. Jeff Boscole
  759. .LP
  760. Adrian Mariano (adrian@u.washington.edu)
  761. .LP
  762. Fred Hansen (wjh+@andrew.cmu.edu)
  763. .sp
  764. .SH "SEE ALSO"
  765. rn rec.games.go \- a newsgroup on the game
  766. .br
  767. _Graded go problems for beginners,
  768. vol 1-3._, Ishi Press.
  769. (Highly recommended.)
  770. .br
  771. _In the Beginning_,
  772. Ishi Press.
  773. .br
  774. _The Treasure Chest Enigma_,
  775. Ishi Press.
  776. .br
  777. go.players \- an optional file with players and ranks
  778. SHAR_EOF
  779. fi
  780. if test -f 'backup.c'
  781. then
  782.     echo shar: "will not over-write existing file 'backup.c'"
  783. else
  784. cat << \SHAR_EOF > 'backup.c'
  785. #include "std.disclaimer"
  786. #include "go.h"
  787.  
  788. int ohama[2] =
  789. {
  790.    0, 0
  791. };
  792. static int ocur;
  793. static BOARD lastboard;
  794. int lhama[2] =
  795. {
  796.    0, 0
  797. };
  798.  
  799.  
  800. saveboard()
  801. {
  802.    int i, j;
  803.    ocur = curplr;
  804.    ohama[0] = hama[0];
  805.    ohama[1] = hama[1];
  806.  
  807.    for (i = 0; i < MAXX; i++)
  808.       for (j = 0; j < MAXY; j++)
  809.      backup.d[i][j] = board.d[i][j];
  810. }
  811.  
  812. saveboard0()
  813. {
  814.    int i, j;
  815.    for (i = 0; i < MAXX; i++)
  816.       for (j = 0; j < MAXY; j++)
  817.      backup.d[i][j] = lastboard.d[i][j];
  818. }
  819.  
  820. savelast()
  821. {
  822.    int i, j;
  823.    lhama[0] = hama[0];
  824.    lhama[1] = hama[1];
  825.    for (i = 0; i < MAXX; i++)
  826.       for (j = 0; j < MAXY; j++)
  827.      lastboard.d[i][j] = board.d[i][j];
  828. }
  829.  
  830. restlast()
  831. {
  832.    int i, j;
  833.    hama[0] = lhama[0];
  834.    hama[1] = lhama[1];
  835.    for (i = 0; i < MAXX; i++)
  836.       for (j = 0; j < MAXY; j++) {
  837.      if (board.d[i][j] != lastboard.d[i][j]) {
  838.         Plt(&lastboard, i, j);
  839.      }
  840.      board.d[i][j] = lastboard.d[i][j];
  841.       }
  842. }
  843.  
  844. restboard()
  845. {
  846.    int i, j;
  847.    hama[0] = ohama[0];
  848.    hama[1] = ohama[1];
  849.    curplr = ocur;
  850.    for (i = 0; i < MAXX; i++)
  851.       for (j = 0; j < MAXY; j++)
  852.      board.d[i][j] = backup.d[i][j];
  853. }
  854.  
  855. int compboard()
  856. {
  857.    int i, j;
  858.    for (i = 0; i < MAXX; i++)
  859.       for (j = 0; j < MAXY; j++)
  860.      if (board.d[i][j] != backup.d[i][j])
  861.         return (-1);
  862.    return (0);
  863. }
  864. SHAR_EOF
  865. fi
  866. if test -f 'changes.c'
  867. then
  868.     echo shar: "will not over-write existing file 'changes.c'"
  869. else
  870. cat << \SHAR_EOF > 'changes.c'
  871. #include "std.disclaimer"
  872.  
  873. changes()
  874. {
  875.    printf("\
  876. ----------------------------------------------------------------------\n\
  877. \n\
  878.                       %s\n\
  879.                      By Greg Hale\n\
  880.                     Enhancements by Adrian Mariano, Jeff Boscole, and Fred Hansen\n\
  881. \n\
  882. Welcome to the oriental game of Go.  If you do not know how to play,\n\
  883. I recommend that you read the documentation or find someone who knows\n\
  884. how to play.\n\
  885. \n\
  886. This program was developed at the Experimental Computing Facility at the\n\
  887. University of California, Berkeley, by Greg Hale and enhanced by Adrian\n\
  888. Mariano at the University of Washington and Fred Hansen.  Thanks to all the\n\
  889. other members for their input, support, and test playing.\n\
  890. \n\
  891. ----------------------------------------------------------------------\n \
  892. [Hit return to continue]\n\n", VERSION);
  893.    getchar();
  894. }
  895. SHAR_EOF
  896. fi
  897. if test -f 'connect.c'
  898. then
  899.     echo shar: "will not over-write existing file 'connect.c'"
  900. else
  901. cat << \SHAR_EOF > 'connect.c'
  902. #include "std.disclaimer"
  903. #include "go.h"
  904. #include <sys/param.h>
  905. #include <netinet/in.h>
  906. #include <netdb.h>
  907. #include <pwd.h>
  908. #include <errno.h>
  909.  
  910. /* Some systems do not have these defined in the include files. */
  911. #ifndef MAXHOSTNAMELEN
  912. #define MAXHOSTNAMELEN 256
  913. typedef short uid_t;
  914. #endif
  915.  
  916. char *opponent;
  917. char myhostname[MAXHOSTNAMELEN + 1];
  918. extern char *myname;
  919.  
  920. extern int errno;
  921.  
  922. FILE *inp, *out;
  923.  
  924. connectport(oppon, port)
  925.     char *oppon;
  926.     u_short port;
  927. {
  928.    struct sockaddr_in addr;
  929.    struct hostent *host;
  930.    struct passwd *mypasswd, *getpwuid();
  931.    char *hishostname, *index(), *getpw(), *malloc();
  932.    char *hisaddr, *myaddr;
  933.    int hislen, mylen;
  934.    u_long iaddr;
  935.    uid_t getuid();
  936.    u_short hashport(), hashaddr();
  937.    char *copyhost();
  938.    int s, i;
  939.  
  940.    opponent = oppon;
  941.    if (gethostname(myhostname, MAXHOSTNAMELEN) < 0)
  942.       error("gethostname in connectport");
  943.    host = gethostbyname(myhostname);
  944.    if (host == NULL) {
  945.       errno = 0;
  946.       error("don't know my own name.");
  947.    }
  948.    mylen = host->h_length;
  949.    myaddr = copyhost(host);
  950.    if (hishostname = index(oppon, '@')) {
  951.       *hishostname++ = '\0';    /* separate user and host */
  952.       if (hishostname[0] >= '0' && hishostname[0] <= '9') {
  953.      iaddr = inet_addr(hishostname);
  954.      hisaddr = (char *) &iaddr;
  955.      hislen = sizeof iaddr;
  956.       } else {
  957.      host = gethostbyname(hishostname);
  958.      if (host == NULL) {
  959.         errno = 0;
  960.         error("Unknown host");
  961.      }
  962.      hislen = host->h_length;
  963.      hisaddr = copyhost(host);
  964.      hishostname = host->h_name;
  965.       }
  966.    } else {
  967.       hislen = mylen;
  968.       hisaddr = myaddr;
  969.       hishostname = myhostname;
  970.    }
  971.    mypasswd = getpwuid((int) getuid());
  972.    myname = mypasswd->pw_name;
  973.  
  974.    if (iamserver == UNSET)
  975.       if (i = strcmp(myname, oppon))
  976.      iamserver = (i < 0);
  977.       else if (i = comparehost(myaddr, hisaddr))
  978.      iamserver = (i < 0);
  979.    if ((sock = socket(AF_INET, SOCK_STREAM, 0)) < 0)
  980.       error("socket in connectport");
  981.    bzero((char *) &addr, sizeof(addr));
  982.    if (port != 0) {
  983.       if (port > 1000) {
  984.      errno = 0;
  985.      error("bad port number");
  986.       }
  987.    } else if (iamserver) {
  988.       port = hashaddr(myaddr, port, mylen);
  989.       port = hashaddr(hisaddr, port, hislen);
  990.       port = hashport(myname, port);
  991.       port = hashport(oppon, port);
  992.    } else {
  993.       port = hashaddr(hisaddr, port, hislen);
  994.       port = hashaddr(myaddr, port, mylen);
  995.       port = hashport(oppon, port);
  996.       port = hashport(myname, port);
  997.    }
  998.    port += 3000;
  999.    addr.sin_family = AF_INET;
  1000.    addr.sin_port = htons(port);
  1001.  
  1002.    connectmes(hishostname);
  1003.  
  1004.    if (iamserver) {
  1005.       s = sock;
  1006.       if (bind(s, /* (char *) */ &addr, sizeof(addr)) < 0)
  1007.      if (errno == EADDRINUSE && iamserver == UNSET) {
  1008.         /* hope other player is server */
  1009.         iamserver = FALSE;
  1010.         close(s);
  1011.         if ((sock = socket(AF_INET, SOCK_STREAM, 0))
  1012.         < 0)
  1013.            error("socket in connectport");
  1014.      } else
  1015.         error("bind in connectport");
  1016.       if (iamserver) {
  1017.      if (listen(s, 1) < 0)
  1018.         error("listen in connectport");
  1019.      while ((sock = accept(s, (struct sockaddr_in *) NULL,
  1020.                    (int *) NULL)) < 0)
  1021.         if (errno != EINTR)
  1022.            error("accept in connectport");
  1023.      close(s);
  1024.       }
  1025.    }
  1026.    if (!iamserver) {
  1027.       bcopy(hisaddr, (char *) &addr.sin_addr, hislen);
  1028.       while (connect(sock, /* (char *) */ &addr, sizeof(addr)) < 0)
  1029.      if (errno == EINTR || errno == ECONNREFUSED) {
  1030.         close(sock);
  1031.         sleep(2);
  1032.         if ((sock = socket(AF_INET, SOCK_STREAM, 0))
  1033.         < 0)
  1034.            error("socket in connectport");
  1035.      } else
  1036.         error("connect in connectport");
  1037.    }
  1038.    if ((s = dup(sock)) < 0)
  1039.       error("dup");
  1040.    if ((inp = fdopen(sock, "r")) == NULL)
  1041.       error("fdopen");
  1042.    if ((out = fdopen(s, "w")) == NULL)
  1043.       error("fdopen");
  1044.    setlinebuf(out);
  1045.  
  1046.    sockmask[1] = 1 << sock;
  1047. }
  1048.  
  1049. u_short hashport(s, port)
  1050.     char *s;
  1051.     u_short port;
  1052. {
  1053.    while (*s)
  1054.       port = (port << 1) + *s++;
  1055.    return (port & 0x7fff);
  1056. }
  1057.  
  1058. /* addr is in network byte order. */
  1059. u_short hashaddr(addr, port, len)
  1060.     u_short port;
  1061.     char *addr;
  1062. {
  1063.  
  1064.    while (len--)
  1065.       port = (port << 1) + *addr++;
  1066.    return (port & 0x7fff);
  1067. }
  1068.  
  1069. char *copyhost(host)
  1070.     struct hostent *host;
  1071. {
  1072.    char *ret;
  1073.  
  1074.    ret = malloc(host->h_length);
  1075.    if (ret == NULL)
  1076.       error("malloc");
  1077.    bcopy(host->h_addr, ret, host->h_length);
  1078.  
  1079.    return ret;
  1080. }
  1081.  
  1082. comparehost(h1, h2)
  1083.     char *h1, *h2;
  1084. {
  1085.    auto unsigned long l1, l2;
  1086.  
  1087.    bcopy(h1, &l1, sizeof l1);
  1088.    bcopy(h2, &l2, sizeof l2);
  1089.  
  1090.    if (l1 < l2)
  1091.       return -1;
  1092.    else if (l1 > l2)
  1093.       return 1;
  1094.    return 0;
  1095. }
  1096.  
  1097.  
  1098. RECV(mes)
  1099.     char *mes;
  1100. {
  1101.    char num[4];
  1102.    int u;
  1103.    num[3] = '\0';
  1104.    if (read(sock, num, 3) != 3) {
  1105.       error("\n\nError- bad transmission\n");
  1106.       getchar();
  1107.    }
  1108.    u = read(sock, mes, atoi(num));
  1109.    mes[u] = '\0';
  1110.    if (u != atoi(num)) {
  1111.       error("\n\nRECEIVE: length does not match.\n");
  1112.    }
  1113. }
  1114.  
  1115.  
  1116. SEND(mes)
  1117.     char *mes;
  1118. {
  1119.    char tbuf[MAXBUF];
  1120.    sprintf(tbuf, "%03d%s", strlen(mes), mes);
  1121.    write(sock, tbuf, strlen(tbuf));
  1122. }
  1123.  
  1124. readint(i)
  1125.     int *i;
  1126. {
  1127.    RECV(buf);
  1128.    *i = atoi(buf);
  1129. }
  1130.  
  1131. sendint(i)
  1132.     int i;
  1133. {
  1134.    sprintf(buf, "%d", i);
  1135.    SEND(buf);
  1136. }
  1137. SHAR_EOF
  1138. fi
  1139. if test -f 'curse.c'
  1140. then
  1141.     echo shar: "will not over-write existing file 'curse.c'"
  1142. else
  1143. cat << \SHAR_EOF > 'curse.c'
  1144. #include "std.disclaimer"
  1145. #include "go.h"
  1146. #include <ctype.h>
  1147. #include <curses.h>
  1148.  
  1149. #define DEBUG_CURSE 0
  1150.  
  1151. extern int mesflg;
  1152.  
  1153.  
  1154. int curpos = 0;
  1155. #define OFFX (2*MAXX+2)
  1156. #define MAXL 23
  1157.  
  1158. connectmes(hname)
  1159.     char *hname;
  1160. {
  1161.    extern char *myname, myhostname[];
  1162.    extern char *hisname;
  1163.    move(0, 0);
  1164.    printw("Waiting for %s@%s to type 'go user@host.net' ", hisname, hname);
  1165.    refresh();
  1166. }
  1167.  
  1168. doneconnectmes()
  1169. {
  1170.    clear();
  1171.    refresh();
  1172. }
  1173.  
  1174. REFRESH()
  1175. {
  1176.    refresh();
  1177. }
  1178. CLEAR()
  1179. {
  1180.    clear();
  1181.    refresh();
  1182. }
  1183.  
  1184. DoQuit()
  1185. {
  1186.    char c;
  1187.    homemes();
  1188.    addmes("- Opponent wants to score and quit.   Do you accept? (y/n)");
  1189.    Beep();
  1190.    do
  1191.       c = GetAKey0();
  1192.    while (c != 'y' && c != 'n');
  1193.    if (c == 'y') {
  1194.       SEND(MACCEPT);
  1195.       Score();
  1196.    } else {
  1197.       dodecline();
  1198.       SEND(MDECLINE);
  1199.    }
  1200.    move(0, 0);
  1201.    clrtoeol();
  1202.    refresh();
  1203. }
  1204.  
  1205.  
  1206. #define mesgy 1
  1207. #define mesgy2 5
  1208. #define mesgx 42
  1209.  
  1210. homemes()
  1211. {
  1212.    int y;
  1213.    for (y = mesgy; y < mesgy2; y++) {
  1214.       move(y, mesgx);
  1215.       clrtoeol();
  1216.    }
  1217.    curpos = 0;
  1218. }
  1219.  
  1220. addmes(mes)
  1221.     char *mes;
  1222. {
  1223.    do {
  1224.       move(curpos + mesgy, mesgx);
  1225.       printw("%.35s", mes);
  1226.       curpos = (curpos + 1) % (mesgy2 - mesgy + 1);
  1227.       move(curpos + mesgy, mesgx);
  1228.       clrtoeol();
  1229.       if (strlen(mes) <= 35)
  1230.      break;
  1231.       else
  1232.      mes += 35;
  1233.    }
  1234.    while (1);
  1235.    refresh();
  1236. }
  1237.  
  1238.  
  1239. GetAKey0()
  1240. {
  1241.    char c;
  1242.    if (read(FD_INPUT, &c, 1) <= 0) {
  1243.       SEND(MEXIT);
  1244.       error("Aborting- End of File read.\n");
  1245.    }
  1246.    return (c);
  1247. }
  1248.  
  1249. movecur(x, y)
  1250.     int x, y;
  1251. {
  1252.    cx = (cx + x + MAXX) % MAXX;
  1253.    cy = (cy + y + MAXX) % MAXY;
  1254. }
  1255.  
  1256. chkmve(c)
  1257.     char c;
  1258. {
  1259.    switch (c) {
  1260.     WHEN '4':
  1261.    case 'h':
  1262.       movecur(-1, 0);
  1263.       return (1);
  1264.     WHEN '2':
  1265.    case 'j':
  1266.       movecur(0, 1);
  1267.       return (1);
  1268.     WHEN '8':
  1269.    case 'k':
  1270.       movecur(0, -1);
  1271.       return (1);
  1272.     WHEN '6':
  1273.    case 'l':
  1274.       movecur(1, 0);
  1275.       return (1);
  1276.     WHEN '7':
  1277.    case 'y':
  1278.       movecur(-1, -1);
  1279.       return (1);
  1280.     WHEN '9':
  1281.    case 'u':
  1282.       movecur(1, -1);
  1283.       return (1);
  1284.     WHEN '1':
  1285.    case 'b':
  1286.       movecur(-1, 1);
  1287.       return (1);
  1288.     WHEN '3':
  1289.    case 'n':
  1290.       movecur(1, 1);
  1291.       return (1);
  1292.     WHEN 'H':
  1293.       movecur(-FASTMOVE, 0);
  1294.       return (1);
  1295.     WHEN 'J':
  1296.       movecur(0, FASTMOVE);
  1297.       return (1);
  1298.     WHEN 'K':
  1299.       movecur(0, -FASTMOVE);
  1300.       return (1);
  1301.     WHEN 'L':
  1302.       movecur(FASTMOVE, 0);
  1303.       return (1);
  1304.     WHEN 'Y':
  1305.       movecur(-FASTMOVE, -FASTMOVE);
  1306.       return (1);
  1307.     WHEN 'U':
  1308.       movecur(FASTMOVE, -FASTMOVE);
  1309.       return (1);
  1310.     WHEN 'B':
  1311.       movecur(-FASTMOVE, FASTMOVE);
  1312.       return (1);
  1313.     WHEN 'N':
  1314.       movecur(FASTMOVE, FASTMOVE);
  1315.       return (1);
  1316.     OTHERWISE:
  1317.       return (0);
  1318.    }
  1319. }
  1320.  
  1321. getcmd()
  1322. {
  1323.    char c;
  1324.    int ret;
  1325.  
  1326.    c = GetAKey0();
  1327.  
  1328. #if DEBUG_CURSE
  1329.    {
  1330.       char buf[100];
  1331.  
  1332.       sprintf(buf, "char hit '%c'", c);
  1333.       addmes(buf);
  1334.    }
  1335. #endif
  1336.  
  1337.    if (mesflg) {
  1338.        /*-->*/ return c;
  1339.    }
  1340.    /* move the cursor */
  1341.    if (chkmve(c))
  1342.        /*-->*/ return C_NOTHING;
  1343.  
  1344.    switch (c) {
  1345.    case 'T':
  1346.       ret = C_SETTIME;
  1347.       break;
  1348.    case '*':
  1349.       ret = C_SETHAND;
  1350.       break;
  1351.    case REDRAW:
  1352.       ret = C_REDRAW;
  1353.       break;
  1354.    case 'V':            /* inverse */
  1355.       /* hadle here. */
  1356.       ret = C_INVERSE;
  1357.       break;
  1358.    case 'S':            /* save */
  1359.       ret = C_SAVE;
  1360.       break;
  1361.    case '#':            /* load */
  1362.       ret = C_LOAD;
  1363.       break;
  1364.    case 'q':            /* quit */
  1365.       ret = C_QUIT;
  1366.       break;
  1367.    case 't':            /* tally */
  1368.       ret = C_TALLY;
  1369.       break;
  1370.    case 'c':            /* cancel */
  1371.       ret = C_CANCEL;
  1372.       break;
  1373.    case 'C':            /* clear */
  1374.       ret = C_CLEAR;
  1375.       break;
  1376.    case 'm':            /* message */
  1377.       ret = C_MESSAGE;
  1378.       break;
  1379.    case 'R':            /* resign */
  1380.       ret = C_RESIGN;
  1381.       break;
  1382.    case 's':            /* switch */
  1383.       ret = C_SWITCH;
  1384.       break;
  1385.    case '/':            /* play */
  1386.       /* bad name for this command.  show last would be better. */
  1387.       ret = C_LAST;
  1388.       break;
  1389.    case 'P':
  1390.       ret = C_PAUSE;
  1391.       break;
  1392.    case 'p':            /* pass */
  1393.       ret = C_PASS;
  1394.       break;
  1395.    case '?':            /* help */
  1396.       /* hadle here. */
  1397.       ret = C_HELP;
  1398.       break;
  1399.    case 'z':            /* dohand with '0' */
  1400.       ret = C_SETBLACK;
  1401.       break;
  1402.    case 'x':            /* dohand with '0' */
  1403.       ret = C_SETWHITE;
  1404.       break;
  1405.    case '0':
  1406.    case ' ':            /* put priece, remove group */
  1407.       ret = C_PLAY;
  1408.       break;
  1409.    case 'P'&31:
  1410.       ret = C_PANIC;
  1411.       break;
  1412.    default:
  1413.       ret = C_NOTHING;
  1414.    }
  1415.  
  1416.    return ret;
  1417. }
  1418.  
  1419.  
  1420. moveto(x, y)
  1421. {
  1422.    move(y + 1, (x * 2) + 1);
  1423. }
  1424.  
  1425.  
  1426. setmode()
  1427. {
  1428.    /* cbreak(); */
  1429.    noecho();
  1430.    crmode();
  1431. }
  1432.  
  1433. unsetmode()
  1434. {
  1435.    /* nocbreak(); */
  1436.    echo();
  1437.    nocrmode();
  1438. }
  1439.  
  1440. DoRefresh()
  1441. {
  1442.    clearok(stdscr, 1);
  1443.    refresh();
  1444.    clearok(stdscr, 0);
  1445. }
  1446.  
  1447.  
  1448. int getLine(query, dst, maxLen)    /* char *, char *, int */
  1449.     char *query, *dst;
  1450.     int maxLen;
  1451. {
  1452.    int qLen, dLen;
  1453.    int c;
  1454.    move(0, 1);
  1455.    for (c = 0; c < maxLen; c++)
  1456.       addch(' ');
  1457.    mvaddstr(0, 1, query);
  1458.    dLen = 0;
  1459.    qLen = strlen(query);
  1460.    do {
  1461.       move(0, qLen + 1 + dLen);
  1462.       refresh();
  1463.       c = getchar();
  1464.       if (isprint(c) && dLen < maxLen) {
  1465.      mvaddch(0, qLen + dLen + 1, c);
  1466.      dst[dLen++] = c;
  1467.       } else if (dLen && (c == '\b' || c == '\177')) {
  1468.      dLen--;
  1469.      mvaddch(0, qLen + dLen + 1, ' ');
  1470.       }
  1471.    }
  1472.    while (c != '\n' && c != '\r');
  1473.    dst[dLen] = 0;
  1474.    move(0, 1);
  1475.    for (c = 0; c < maxLen; c++)
  1476.       addch(' ');
  1477.    return dLen;
  1478. }
  1479.  
  1480. DoRedraw()
  1481. {
  1482.    touchwin(stdscr);
  1483.    clear();
  1484.    PrintBoard(&board);
  1485. }
  1486. SHAR_EOF
  1487. fi
  1488. if test -f 'board.c'
  1489. then
  1490.     echo shar: "will not over-write existing file 'board.c'"
  1491. else
  1492. cat << \SHAR_EOF > 'board.c'
  1493. #include "std.disclaimer"
  1494. #include "go.h"
  1495. #include <curses.h>
  1496.  
  1497. PrintBoard(br)
  1498.     BOARD *br;
  1499. {
  1500.    extern int handin, dimensions, inverse;
  1501.    int x, y;
  1502.    touchwin(stdscr);
  1503.    handin = (dimensions > 12) ? 3 : 2;
  1504.    for (y = 1; y < MAXY + 1; y++)
  1505.       for (x = 0; x < MAXX * 2; x++)
  1506.      mvaddch(y, x, 32 + inverse);
  1507.    for (y = 0; y < MAXY; y++) {
  1508.       for (x = 0; x < MAXX; x++) {
  1509.      Plt(br, x, y);
  1510.       }
  1511.       mvprintw(y + 1, MAXX * 2, "|%d", MAXY - y);
  1512.    }
  1513.    for (x = MAXX; x--;) {
  1514.       char c;
  1515.       c = 'A' + x;
  1516.       c = (c >= 'I') ? c + 1 : c;
  1517.       mvaddch(MAXY + 1, x * 2 + 1, c);
  1518.    }
  1519.    initmesg();
  1520.    printscore();
  1521.    printtimes();
  1522.    refresh();
  1523. }
  1524.  
  1525. printscore()
  1526. {  char lin[80];
  1527.    /* mvaddstr(MAXY+1,0,"Go - By Greg Hale"); */
  1528.    move(21, 0);
  1529.    addch(player ? '>' : ' ');
  1530.  
  1531. /* This next bit gets around a bug on ES/OS in the printw function */
  1532.  
  1533.    sprintf(lin,"Player one [%c] (captured O): %4d", pieces[1]&127, hama[0]);
  1534.    printw(lin);
  1535.  
  1536.    move(22, 0);
  1537.    addch(!player ? '>' : ' ');
  1538.    
  1539.    sprintf(lin,"Player two [O] (captured %c): %4d", pieces[1]&127, hama[1]);
  1540.    printw(lin);
  1541. }
  1542.  
  1543.  
  1544. InitBoard(br)
  1545.     BOARD *br;
  1546. {
  1547.    int x, y;
  1548.    for (y = 0; y < MAXY; y++)
  1549.       for (x = 0; x < MAXX; x++)
  1550.      br->d[x][y] = NONE;
  1551. }
  1552.  
  1553.  
  1554. Plt(br, x, y)
  1555.     BOARD *br;
  1556.     int x, y;
  1557. {
  1558.    char c;
  1559.    moveto(x, y);
  1560.    c = (pieces[br->d[x][y]]);
  1561.    if (c == pieces[0])
  1562.       c = cp(x, y);
  1563.    addch(c);
  1564. }
  1565.  
  1566. cp(x, y)
  1567.     int x, y;
  1568. {
  1569.    extern int handin;
  1570.  
  1571.    if ((x == handin || x == MAXX - 1 - handin || x == (MAXX - 1) / 2) &&
  1572.        (y == handin || y == MAXY - 1 - handin || y == (MAXY - 1) / 2)) {
  1573.       return (pieces[4]);
  1574.    } else {
  1575.       return (pieces[0]);
  1576.    }
  1577. }
  1578.  
  1579.  
  1580. setboard(x, y, p)
  1581.     int x, y;
  1582.     char p;
  1583. {
  1584.    if ((p < 1 || p > 2) && b(x, y) == 1 || b(x, y) == 2) {
  1585.       hama[!(b(x, y) - 1)]++;
  1586.    }
  1587.    board.d[x][y] = p;
  1588.    Plt(&board, x, y);
  1589. }
  1590.  
  1591.  
  1592. deletes(x, y)
  1593.     int x, y;
  1594. {
  1595.    InitBoard(&marks);
  1596.    killit(x, y, b(x, y));
  1597. }
  1598.  
  1599.  
  1600.  
  1601. Kill(x, y, type)
  1602.     int x, y, type;
  1603. {
  1604.    int t;
  1605.    InitBoard(&marks);
  1606.    t = !(type - 1) + 1;
  1607.    if (!IsSafe(x - 1, y))
  1608.       killit(x - 1, y, t);
  1609.    if (!IsSafe(x + 1, y))
  1610.       killit(x + 1, y, t);
  1611.    if (!IsSafe(x, y - 1))
  1612.       killit(x, y - 1, t);
  1613.    if (!IsSafe(x, y + 1))
  1614.       killit(x, y + 1, t);
  1615. }
  1616.  
  1617.  
  1618. killit(x, y, t)
  1619.     int x, y, t;
  1620. {
  1621.    if (ir(x, y) && b(x, y) == t && t != NONE) {
  1622.       setboard(x, y, NONE);
  1623.       Plt(&board, x, y);
  1624.       killit(x - 1, y, t);
  1625.       killit(x + 1, y, t);
  1626.       killit(x, y - 1, t);
  1627.       killit(x, y + 1, t);
  1628.    }
  1629. }
  1630.  
  1631.  
  1632. DoHand(x, y, c)
  1633.     int x, y, c;
  1634. {
  1635.  
  1636.    sethand(x, y, (b(x, y) == c + 1 ? 0 : c + 1));
  1637.    printscore();
  1638. }
  1639.  
  1640. sethand(x, y, v)
  1641.     int x, y, v;
  1642. {
  1643.    extern int handicaps;
  1644.    if (b(x, y) != v) {
  1645.       if (AreWe(HANDICAP)) {
  1646.      if (v)
  1647.         handicaps++;
  1648.      else
  1649.         handicaps--;
  1650.       }
  1651.       b(x, y) = v;
  1652.       dolog(x, y, v);
  1653.       Plt(&board, x, y);
  1654.       SEND(MHANDICAP);
  1655.       SendCoord(x, y);
  1656.       sendint(v);
  1657.    }
  1658. }
  1659.  
  1660.  
  1661.  
  1662. NoMove(x, y, c, d)
  1663.     int x, y, c, d;
  1664. {
  1665.    return (!IsSafe(x, y) &&
  1666.        nmv0(x - 1, y, c, d) &&
  1667.        nmv0(x + 1, y, c, d) &&
  1668.        nmv0(x, y - 1, c, d) &&
  1669.        nmv0(x, y + 1, c, d));
  1670. }
  1671.  
  1672. nmv0(x, y, c, d)
  1673.     int x, y, c, d;
  1674. {
  1675.    return (!ir(x, y) ||
  1676.        (b(x, y) == c && IsSafe(x, y)) ||
  1677.        (b(x, y) == d && !IsSafe(x, y)));
  1678. }
  1679. SHAR_EOF
  1680. fi
  1681. if test -f 'doloop.c'
  1682. then
  1683.     echo shar: "will not over-write existing file 'doloop.c'"
  1684. else
  1685. cat << \SHAR_EOF > 'doloop.c'
  1686. #include "std.disclaimer"
  1687. #include "go.h"
  1688. #include <ctype.h>
  1689.  
  1690. extern int mesflg, loadflg, inverse, handicaps;
  1691.  
  1692. DEBUG(extern FILE * debug;
  1693. )
  1694.     bool getint(prompt, dest)
  1695.     char *prompt;
  1696.     int *dest;
  1697. {
  1698.    char buffer[5], *bx;
  1699.    int v;
  1700.  
  1701.    getLine(prompt, buffer, sizeof(buffer) - 1);
  1702.    bx = buffer;
  1703.    while (*bx && !isdigit(*bx))
  1704.       bx++;
  1705.    if (!*bx)
  1706.       return FALSE;
  1707.    v = 0;
  1708.    while (*bx && isdigit(*bx))
  1709.       v = v * 10 + (*bx++ - '0');
  1710.    *dest = v;
  1711.    return TRUE;
  1712. }
  1713.  
  1714. DoLoop()
  1715. {
  1716.    char c;
  1717.    char buf[20];
  1718.  
  1719.    c = getcmd();
  1720.  
  1721.    if (mesflg)
  1722.       domesg(c);
  1723.    else if (!disable)
  1724.       switch (c) {
  1725.      WHEN C_REDRAW:
  1726.         DoRefresh();
  1727.      WHEN C_INVERSE:
  1728.      if (inverse) {
  1729.         for (c = 0; c < 6; c++)
  1730.            pieces[c] -= 128;
  1731.         inverse = 0;
  1732.      } else {
  1733.         for (c = 0; c < 6; c++)
  1734.            pieces[c] += 128;
  1735.         inverse = 128;
  1736.      }
  1737.      DoRedraw();
  1738.      WHEN C_SAVE:
  1739.         dosave();
  1740.      WHEN C_SETTIME:
  1741.      if (AreWe(HANDICAP)) {
  1742.         dosettiming();
  1743.      } else
  1744.            Beep();
  1745.      WHEN C_SETHAND:
  1746.      if (AreWe(HANDICAP) && getint("Handicap: ", &handicaps)) {
  1747.         SEND(MCLEAR);
  1748.         doclear();
  1749.         sethandi();
  1750.      } else
  1751.            Beep();
  1752.      WHEN C_LOAD:
  1753.      if (!AreWe(PAUSED))
  1754.            doload();
  1755.      WHEN C_QUIT:
  1756.      if (AreWe(SCORE)) {
  1757.         SEND(MQUIT);
  1758.         disable = 1;
  1759.      } else
  1760.            Beep();
  1761.      WHEN C_TALLY:
  1762.      if (AreWe(SCORE)) {
  1763.         savelast();
  1764.         Tally();
  1765.         PrintBoard(&board);
  1766.         GetAKey();
  1767.         restlast();
  1768.      } else
  1769.            Beep();
  1770.  
  1771.      WHEN C_CANCEL:
  1772.      if (AreWe(SCORE)) {
  1773.         docancel();
  1774.         SEND(MCANCEL);
  1775.      } else
  1776.            Beep();
  1777.  
  1778.      WHEN C_CLEAR:
  1779.      if ((!AreWe(PAUSED)) && verify("Clear the board (y/n)?")) {
  1780.         SEND(MCLEAR);
  1781.         doclear();
  1782.      }
  1783.      WHEN C_MESSAGE:
  1784.      /* addmes("control-D to finish message"); */
  1785.         mesflg++;
  1786.  
  1787.      WHEN C_RESIGN:
  1788.      if ((!AreWe(PAUSED)) && verify("Resign (y/n)?")) {
  1789.         SEND(MRESIGN);
  1790.         dodecided(FALSE,
  1791.               "You resigned.",
  1792.               "\nYou lost by resignation.\n");
  1793.      }
  1794.          WHEN C_PANIC:
  1795.             doswitch();
  1796.             addmes("Switched game state ON THIS END");
  1797.      WHEN C_SWITCH:
  1798.      if (AreWe(HANDICAP)) {
  1799.         SEND(MSWITCH);
  1800.         doswitch();
  1801.      } else if (AreWe(PLAY)) {
  1802.         SEND(MSCORE);
  1803.         doscore();
  1804.      } else
  1805.         Beep();
  1806.  
  1807.      WHEN C_LAST:
  1808.      if (AreWe(PLAY)) {
  1809.         ShowLast();
  1810.      } else
  1811.            Beep();
  1812.      WHEN C_PASS:
  1813.      if (AreWe(PLAY) && myturn) {
  1814.         stoptick(TRUE);
  1815.         curplr = !curplr;
  1816.         SEND(MPASS);
  1817.         if (timedgame) {
  1818.            if (opphastiming) {
  1819.           SEND(MTIME);
  1820.           sprintf(buf, "%d",
  1821.               mytime.left.tv_sec);
  1822.           SEND(buf);
  1823.            } else
  1824.              sendtimemesg();
  1825.         }
  1826.         starttick(FALSE);
  1827.      } else if (AreWe(HANDICAP)) {
  1828.         SEND(MPLAY);
  1829.         doplay();
  1830.         printscore();
  1831.      } else
  1832.         Beep();
  1833.      WHEN C_HELP:
  1834.         help();
  1835.      PrintBoard(&board);
  1836.  
  1837.      WHEN C_SETBLACK:
  1838.      if (AreWe(PLAY))
  1839.            DoHand(cx, cy, 0);
  1840.      else
  1841.         Beep();
  1842.      WHEN C_SETWHITE:
  1843.      if (AreWe(PLAY))
  1844.            DoHand(cx, cy, 1);
  1845.      else
  1846.         Beep();
  1847.      WHEN C_PAUSE:
  1848.      if (AreWe(PAUSED))
  1849.            unpausegame(TRUE);
  1850.      else if (AreWe(PLAY))
  1851.         pausegame(TRUE);
  1852.      WHEN C_PLAY:
  1853.      if (AreWe(HANDICAP)) {
  1854.         sethand(cx, cy, !b(cx, cy));
  1855.      } else if (AreWe(SCORE))
  1856.            doscorehit(cx, cy);
  1857.      else if (AreWe(PLAY) && myturn) {
  1858.         stoptick(TRUE);
  1859.         putpiece(cx, cy, curplr, TRUE, TRUE);
  1860.         if (timedgame) {
  1861.            if (opphastiming) {
  1862.           SEND(MTIME);
  1863.           sprintf(buf, "%d",
  1864.               mytime.left.tv_sec);
  1865.           SEND(buf);
  1866.            } else
  1867.           sendtimemesg();
  1868.         }
  1869.         starttick(FALSE);
  1870.      } else
  1871.         Beep();
  1872.      printscore();
  1873.      WHEN C_NOTHING:;
  1874.        OTHERWISE:
  1875.      Beep();
  1876.       }
  1877. }
  1878.  
  1879.  
  1880.  
  1881. int verify(s)
  1882.     char *s;
  1883. {
  1884.    char buf[2];
  1885.    do {
  1886.       getLine(s, buf, 1);
  1887.    }
  1888.    while (buf[0] != 'y' && buf[0] != 'n');
  1889.  
  1890.    return buf[0] == 'y';
  1891. }
  1892. SHAR_EOF
  1893. fi
  1894. if test -f 'doother.c'
  1895. then
  1896.     echo shar: "will not over-write existing file 'doother.c'"
  1897. else
  1898. cat << \SHAR_EOF > 'doother.c'
  1899. #include "std.disclaimer"
  1900. #include "go.h"
  1901.  
  1902. extern int loadflg;
  1903. extern char loadname[];
  1904. extern bool savegame();
  1905. extern int handicaps;
  1906. int turn;
  1907. bool done;
  1908.  
  1909. DEBUG(extern FILE * debug;
  1910. )
  1911. /* this table should match the one in go.h and the numeric sequence must match
  1912.  * the entries in DoOther() */
  1913.     char messages[][15] =
  1914.     {
  1915.        "SCORE",            /* 0 */
  1916.        "QUIT",            /* 1 */
  1917.        "ACCEPT",        /* 2 */
  1918.        "EXIT",            /* 3 */
  1919.        "DECLINE",        /* 4 */
  1920.        "CANCEL",        /* 5 */
  1921.        "PLAY",            /* 6 */
  1922.        "MOVE",            /* 7 */
  1923.        "LOAD",            /* 8 */
  1924.        "DELETE",        /* 9 */
  1925.        "CLEAR",            /* 10 */
  1926.        "PASS",            /* 11 */
  1927.        "MESSAGE",        /* 12 */
  1928.        "HANDICAP",        /* 13 */
  1929.        "SWITCH",        /* 14 */
  1930.        "RESIGN",        /* 15 */
  1931.        "TIME",            /* 16 */
  1932.        "SETTIME",        /* 17 */
  1933.        "SETBYO",        /* 18 */
  1934.        "TIMELOSE",        /* 19 */
  1935.        "PAUSE",            /* 20 */
  1936.        ""
  1937.     };
  1938.  
  1939. DoOther()
  1940. {
  1941.    extern int lastx, lasty;
  1942.    int x, y, cur;
  1943.    int i;
  1944.  
  1945.    RECV(buf);
  1946.    for (i = 0; *messages[i]; i++)
  1947.       if (!strcmp(messages[i], buf))
  1948.      break;
  1949.  
  1950.    DEBUG(fprintf(debug, "%d %s\n", i, buf);
  1951.    fflush(debug);
  1952.    )
  1953.       switch (i) {
  1954.     WHEN 0:            /* MSCORE */
  1955.       doscore();
  1956.     WHEN 1:            /* MQUIT */
  1957.       DoQuit();
  1958.     WHEN 2:            /* MACCEPT */
  1959.       Score();
  1960.     WHEN 3:            /* MEXIT */
  1961.       homemes();
  1962.       addmes("- your opponent has departed");
  1963.       SetStat(EXIT);
  1964.     WHEN 4:            /* MDECLINE */
  1965.       homemes();
  1966.       addmes("- Other player has declined.");
  1967.       addmes("-    Please resume play.");
  1968.       Beep();
  1969.       disable = 0;
  1970.       dodecline();
  1971.     WHEN 5:            /* MCANCEL */
  1972.       docancel();
  1973.     WHEN 6:            /* MPLAY */
  1974.       doplay();
  1975.       printscore();
  1976.     WHEN 7:            /* MMOVE */
  1977.       if (!opphastiming && timedgame) {
  1978.      /* he has no clock. tell him what we he's got left */
  1979.      stoptick(FALSE);
  1980.      sendtimemesg();
  1981.       } else if (timedgame)
  1982.      opptime.stones--;
  1983.       if (!(AreWe(HANDICAP)))
  1984. {
  1985.      Beep();
  1986. Beep();Beep();
  1987. }
  1988.       savelast();
  1989.       GetCoord(&x, &y);
  1990.       readint(&cur);
  1991.  
  1992.       lastx = x;
  1993.       lasty = y;
  1994.       setboard(x, y, cur + 1);
  1995.       Kill(x, y, cur + 1);
  1996.       Plt(&board, x, y);
  1997.       REFRESH();
  1998.       dolog(x, y, cur + 1);
  1999.       printscore();
  2000.       blink(x, y, cur + 1);
  2001.       NextPlr();
  2002.       saveboard0();
  2003.       starttick(TRUE);
  2004.     WHEN 8:            /* MLOAD */
  2005.       doReceiveLoad();
  2006.     WHEN 9:            /* MDELETE */
  2007.       GetCoord(&x, &y);
  2008.       deletes(x, y);
  2009.     WHEN 10:            /* MCLEAR */
  2010.       doclear();
  2011.     WHEN 11:            /* MPASS */
  2012.       if (!opphastiming && timedgame) {
  2013.      /* he has no clock. tell him what he's got left */
  2014.      stoptick(FALSE);
  2015.      sendtimemesg();
  2016.       } else if (timedgame)
  2017.      opptime.stones--;
  2018.       homemes();
  2019.       addmes("- Other player passed.");
  2020.       NextPlr();
  2021.       starttick(TRUE);
  2022.     WHEN 12:            /* MMESSAGE */
  2023.       RECV(buf);
  2024.       /* if (beepflg) Beep(); */
  2025.       addtalk(buf);
  2026.     WHEN 13:            /* MHANDICAP */
  2027.       GetCoord(&x, &y);
  2028.       readint(&cur);
  2029.       if (cur != b(x, y)) {
  2030.      if (AreWe(HANDICAP)) {
  2031.         if (cur)
  2032.            handicaps++;
  2033.         else
  2034.            handicaps--;
  2035.      }
  2036.      b(x, y) = cur;
  2037.      Plt(&board, x, y);
  2038.      dolog(x, y, cur);
  2039.       }
  2040.       printscore();
  2041.     WHEN 14:            /* MSWITCH */
  2042.       doswitch();
  2043.     WHEN 15:            /* MRESIGN */
  2044.       dodecided(FALSE,
  2045.         "The other player resigned.",
  2046.         "\nYou won by resignation.\n");
  2047.     WHEN 16:            /* MTIME */
  2048.       readint(&cur);
  2049.       opptime.left.tv_sec = cur;
  2050.       opptime.left.tv_usec = 0;
  2051.       showtime(FALSE, &opptime);
  2052.       opphastiming = TRUE;
  2053.       starttick(FALSE);        /* this is solely to set the time left */
  2054.     WHEN 17:            /* MSETTIME */
  2055.       opphastiming = TRUE;
  2056.       readint(&totalmin);
  2057.       timedgame = (totalmin > 0);
  2058.       inittick();
  2059.       SEND(MTIME);        /* to set his opphastiming */
  2060.       sendint(mytime.left.tv_sec);
  2061.     WHEN 18:            /* MSETBYO */
  2062.       readint(&byosec);
  2063.       readint(&byostones);
  2064.       readint(&byoextends);
  2065.       showbyo();
  2066.     WHEN 19:            /* MTIMELOSE */
  2067.       dodecided(FALSE,
  2068.         "Your opponent's clock ran out.",
  2069.         "\nYou won by time out.\n");
  2070.     WHEN 20:            /* MPAUSE */
  2071.       myturn = !myturn;
  2072.       if (ticking)
  2073.      pausegame(FALSE);
  2074.       else
  2075.      unpausegame(FALSE);
  2076.       myturn = !myturn;
  2077.    }
  2078. }
  2079.  
  2080. pausegame(needsend)
  2081.     char needsend;
  2082. {
  2083.    if (!timedgame)
  2084.       return;
  2085.    if (needsend) {
  2086.       if (opphastiming)
  2087.      SEND(MPAUSE);
  2088.       else {
  2089.      SEND(MMESSAGE);
  2090.      SEND("Clock paused.");
  2091.       }
  2092.    }
  2093.    Beep();
  2094.    Beep();
  2095.    Beep();
  2096.    addmes("- Game paused.  Hit P to resume.");
  2097.    pausetick(myturn);
  2098.    SetStat(PAUSED);
  2099.    ClrStat(PLAY);
  2100. }
  2101.  
  2102. unpausegame(needsend)
  2103.     char needsend;
  2104. {
  2105.    if (needsend) {
  2106.       if (opphastiming)
  2107.      SEND(MPAUSE);
  2108.       else {
  2109.      SEND(MMESSAGE);
  2110.      SEND("Clock restarted.");
  2111.       }
  2112.    }
  2113.    Beep();
  2114.    Beep();
  2115.    Beep();
  2116.    addmes("- Game resumed.");
  2117.    resumetick(myturn);
  2118.    SetStat(PLAY);
  2119.    ClrStat(PAUSED);
  2120. }
  2121.  
  2122.  
  2123.  
  2124. dodecided(isme, msg1, msg2)
  2125.     int isme;
  2126.     char *msg1, *msg2;
  2127. {
  2128.    iwon = !isme;
  2129.    savestr();
  2130.    homemes();
  2131.    Beep();
  2132.    addmes(msg1);
  2133.    testsave();
  2134.    CLEAR();
  2135.    printf(msg2);
  2136.    Exit();
  2137. }
  2138.  
  2139. setcurplr()
  2140. {
  2141.    int x, y;
  2142.    for (x = 0; x < MAXX; x++)
  2143.       for (y = 0; y < MAXY; y++)
  2144.      if (b(x, y)) {
  2145.         curplr = 1;
  2146.         return (0);
  2147.      }
  2148. }
  2149.  
  2150. /* print out the messages to start scoring */
  2151. scoremes()
  2152. {
  2153.    homemes();
  2154.    addmes("- Please score now.");
  2155.    addmes("   - Cancel returns to play.");
  2156.    addmes("   - Select dead groups.");
  2157.    addmes("   - Quit determines winner.");
  2158.    Beep();
  2159. }
  2160.  
  2161. dosave()
  2162. {
  2163.    if (savegame())
  2164.       addmes("Game saved.");
  2165.    else
  2166.       addmes("Not saved");
  2167.    homemes();
  2168. }
  2169.  
  2170. doplay()
  2171. {
  2172.    extern int loadflg;
  2173.    homemes();
  2174.    addmes("- Please begin play.");
  2175.    Beep();
  2176.    ClrStat(HANDICAP);
  2177.    SetStat(PLAY);
  2178.    if (!loadflg) {
  2179.       /*hama[0] = hama[1] = 0;
  2180.       setcurplr();*/
  2181. if (handicaps) curplr = !curplr;
  2182.    }
  2183.    DEBUG(
  2184.      fprintf(debug, "doplay - player: %d    curplr: %d    start for %d\n",
  2185.          player, curplr, (!player && curplr) || (player && !curplr));
  2186.    fflush(debug);
  2187.    )
  2188.       starttick((!player && curplr) || (player && !curplr));
  2189. }
  2190.  
  2191. doscorehit(x, y)
  2192.     int x, y;
  2193. {
  2194.    if (b(x, y)) {
  2195.       deletes(x, y);
  2196.       SEND(MDELETE);
  2197.       SendCoord(x, y);
  2198.    } else
  2199.       Beep();
  2200. }
  2201.  
  2202.  
  2203. doswitch()
  2204. {
  2205.    player = !player;
  2206.    printscore();
  2207.    /* initmesg() ; */
  2208. }
  2209.  
  2210. dodecline()
  2211. {
  2212.    extern int mesflg, curx, cury, tcury;
  2213.    int curxbak, curybak, mesgbak, tcurybak;
  2214.    curxbak = curx;
  2215.    curybak = cury;
  2216.    mesgbak = mesflg;
  2217.    tcurybak = tcury;
  2218.    restboard();
  2219.    ClrStat(SCORE);
  2220.    SetStat(PLAY);
  2221.    PrintBoard(&board);
  2222.    mesflg = mesgbak;
  2223.    tcury = tcurybak;
  2224.  
  2225.    curx = curxbak;
  2226.    cury = curybak;
  2227. }
  2228.  
  2229. docancel()
  2230. {
  2231.    extern int mesflg, curx, cury, tcury;
  2232.    int curxbak, curybak, mesgbak, tcurybak;
  2233.    curxbak = curx;
  2234.    curybak = cury;
  2235.    mesgbak = mesflg;
  2236.    tcurybak = tcury;
  2237.    restboard();
  2238.    ClrStat(SCORE);
  2239.    SetStat(PLAY);
  2240.    PrintBoard(&board);
  2241.  
  2242.    REFRESH();
  2243.    homemes();
  2244.    addmes("- Scoring is cancelled.");
  2245.    addmes("-     Resume play.");
  2246.    mesflg = mesgbak;
  2247.    tcury = tcurybak;
  2248.  
  2249.    curx = curxbak;
  2250.    cury = curybak;
  2251.    resumetick(myturn);
  2252. }
  2253.  
  2254. doscore()
  2255. {
  2256.    pausetick(myturn);
  2257.    SetStat(SCORE);
  2258.    ClrStat(PLAY);
  2259.    scoremes();
  2260.    saveboard();
  2261. }
  2262.  
  2263.  
  2264.  
  2265. doclear()
  2266. {
  2267.    int x, y;
  2268.    char token[12];
  2269.  
  2270.    strcpy(token, ";\nAddEmpty");
  2271.    for (y = 0; y < dimensions; y++)
  2272.       for (x = 0; x < dimensions; x++)
  2273.      if (b(x, y)) {
  2274.         b(x, y) = 0;
  2275.         Plt(&board, x, y);
  2276.  
  2277.  
  2278.         loglist(x, y, token);
  2279.         strcpy(token, "");
  2280.  
  2281.  
  2282.      }
  2283.    logendlist();
  2284.    curplr = 0;
  2285.    hama[0] = hama[1] = 0;
  2286.  
  2287.  
  2288. }
  2289.  
  2290.  
  2291.  
  2292.  
  2293. GetAKey()
  2294. {
  2295.    addmes(HITAKEYMES);
  2296.    return (GetAKey0());
  2297. }
  2298.  
  2299.  
  2300. Beep()
  2301. {
  2302.    extern int beepflg;
  2303.    if (beepflg)
  2304.       putchar(07);
  2305. }
  2306.  
  2307.  
  2308. NextPlr()
  2309. {
  2310.    curplr = !curplr;
  2311.    turn++;
  2312.    if (done)
  2313.       done--;
  2314. }
  2315. SHAR_EOF
  2316. fi
  2317. if test -f 'file.c'
  2318. then
  2319.     echo shar: "will not over-write existing file 'file.c'"
  2320. else
  2321. cat << \SHAR_EOF > 'file.c'
  2322. #include "std.disclaimer"
  2323. #include "go.h"
  2324. #include <strings.h>
  2325. #include <sys/file.h>
  2326.  
  2327.  
  2328. /* save file */
  2329.  
  2330. FILE *sf;
  2331. int initload;
  2332. int commenting = 0;
  2333.  
  2334. char input_buffer[MAXBUF];
  2335.  
  2336. extern int beepflg, status;
  2337. extern int handicaps;
  2338. extern int dimensions, myport;
  2339. extern char *arg0;
  2340. extern int logflg;
  2341. extern FILE *logfile;
  2342.  
  2343. /* file format:
  2344.  * 
  2345.  * #<board dimension> #<curplr: 0/1> #<black's prisoners> #<white's prisoners>
  2346.  * #<cursor x> #<cursor y> <options= Rxx -> right justify with x being width
  2347.  * Bxx -> bottom justify with xx being height of data > '(' xoooxoxox..x
  2348.  * ..x..x...... ...x..x..xxx ')' %comments to be printed. %in the message
  2349.  * window
  2350.  * 
  2351.  */
  2352.  
  2353. static char *cont = ".@O.....";
  2354.  
  2355. bool
  2356. savegame()
  2357. {
  2358.    extern char *opponent;
  2359.    int x, y;
  2360.  
  2361.    getLine("Save as <ret exits>:", input_buffer, 44);
  2362.    if (input_buffer[0]) {
  2363.       sf = fopen(input_buffer, "w");
  2364.       if (!sf)
  2365.      badload("Can't create file.");
  2366.       fprintf(sf, "%d %d %d %d %d %d %d\n",
  2367.           dimensions, curplr, hama[0], hama[1], cx, cy, player);
  2368.       fprintf(sf, "(\n");
  2369.       for (y = 0; y < MAXY; y++) {
  2370.      for (x = 0; x < MAXX; x++)
  2371.         fprintf(sf, "%c ", cont[b(x, y)]);
  2372.      fprintf(sf, "\n");
  2373.       }
  2374.       fprintf(sf, ")\n\n");
  2375.       fclose(sf);
  2376.       return TRUE;
  2377.    }
  2378.    return FALSE;
  2379. }
  2380.  
  2381. testsave()
  2382. {
  2383.    char buf[2];
  2384.    getLine("Save Game (y/n)? ", buf, 1);
  2385.    if (buf[0] == 'y')
  2386.       savegame();
  2387.    printf("\n");
  2388. }
  2389.  
  2390. doReceiveLoad()
  2391. {
  2392.    extern int loadflg;
  2393.    extern char loadname[];
  2394.    loadflg = TRUE;
  2395.    loadname[0] = 0;
  2396.    readint(&hama[0]);
  2397.    readint(&hama[1]);
  2398.    readint(&curplr);
  2399.    readint(&dimensions);
  2400.    readint(&player);
  2401.    MAXX = MAXY = dimensions;
  2402.    DoRedraw();
  2403. }
  2404.  
  2405. restgame(f)
  2406.     char *f;
  2407. {
  2408.    char *cp;
  2409.    int x, y, done;
  2410.    int lj, bj;
  2411.  
  2412.  
  2413.    sf = fopen(f, "r");
  2414.  
  2415.    getbuf(1);
  2416.    sscanf(input_buffer, "%d %d %d %d %d %d %d",
  2417.       &dimensions, &curplr, &hama[0], &hama[1], &cx, &cy, &player);
  2418.  
  2419.  
  2420.  
  2421.    MAXX = MAXY = lj = bj = dimensions;
  2422.    if (!initload) {
  2423.       initload = 1;
  2424.       PrintBoard(&board);
  2425.    } else {
  2426.       SEND(MCLEAR);
  2427.       doclear();
  2428.    }
  2429.  
  2430.  
  2431.    homemes();
  2432.    if (!curplr)
  2433.       addmes("== Black to play.");
  2434.    else
  2435.       addmes("== White to play.");
  2436.  
  2437.    done = 0;
  2438.    do {
  2439.       getbuf(1);
  2440.       if (input_buffer[0] == 'R' || input_buffer[0] == 'r') {
  2441.      lj = atoi(input_buffer + 1);
  2442.      if (lj < 1 || lj > dimensions)
  2443.         lj = dimensions;
  2444.       } else if (input_buffer[0] == 'B' || input_buffer[0] == 'b') {
  2445.      bj = atoi(input_buffer + 1);
  2446.      if (bj < 1 || bj > dimensions)
  2447.         bj = dimensions;
  2448.       } else
  2449.      done++;
  2450.    }
  2451.    while (!done);
  2452.  
  2453.    SEND(MLOAD);
  2454.    sendint(hama[0]);
  2455.    sendint(hama[1]);
  2456.    sendint(curplr);
  2457.    sendint(dimensions);
  2458.    sendint(!player);
  2459.  
  2460.    while (input_buffer[0] != '(')
  2461.       getbuf(1);
  2462.  
  2463.    getbuf(1);
  2464.    done = 0;
  2465.    x = dimensions - lj;
  2466.    y = dimensions - bj;
  2467.    cp = input_buffer;
  2468.  
  2469.    while (!done) {
  2470.       switch (*cp) {
  2471.       case '.':
  2472.       case '0':
  2473.      cp++;
  2474.      sethand(x++, y, 0);
  2475.      break;
  2476.  
  2477.       case 'O':
  2478.       case 'o':
  2479.       case 'w':
  2480.       case '2':
  2481.      cp++;
  2482.      sethand(x++, y, 2);
  2483.      break;
  2484.  
  2485.       case 'X':
  2486.       case '*':
  2487.       case 'x':
  2488.       case '@':
  2489.       case 'b':
  2490.       case '1':
  2491.      cp++;
  2492.      sethand(x++, y, 1);
  2493.      break;
  2494.  
  2495.       case '\n':
  2496.       case ';':
  2497.       case '\0':
  2498.      getbuf(1);
  2499.      cp = input_buffer;
  2500.      x = dimensions - lj;
  2501.      y++;
  2502.      break;
  2503.  
  2504.       case ')':
  2505.      done++;
  2506.      break;
  2507.       default:
  2508.      cp++;
  2509.      break;
  2510.       }
  2511.  
  2512.       if (x >= dimensions) {
  2513.      getbuf(1);
  2514.      x = dimensions - lj;
  2515.      y++;
  2516.      cp = input_buffer;
  2517.       }
  2518.       if (y >= dimensions)
  2519.      done++;
  2520.    }
  2521.    /* Read in and display comments */
  2522.    while (fgets(input_buffer, MAXBUF, sf) != NULL && input_buffer[0] == '%') {
  2523.       if (input_buffer[0] == '%') {
  2524.      char *cc;
  2525.      cc = index(input_buffer, '\n');
  2526.      if (cc != NULL)
  2527.         *cc = '\0';
  2528.      addmes(input_buffer + 1);    /* display the message */
  2529.       }
  2530.       input_buffer[0] = '\0';    /* is this neccessary? */
  2531.    }
  2532.  
  2533.    fclose(sf);
  2534. }
  2535.  
  2536. getbuf(err)
  2537.     int err;
  2538. {
  2539.    do {
  2540.       if (fgets(input_buffer, MAXBUF, sf) == NULL)
  2541.      if (err)
  2542.         badload("Bad Data/End of file reached early.");
  2543.    }
  2544.    while (input_buffer[0] == '\n' || input_buffer[0] == '\0' || input_buffer[0] == ';' || input_buffer[0] == '#');
  2545. }
  2546.  
  2547. badload(s)
  2548.     char *s;
  2549. {
  2550.    homemes();
  2551.    addmes(s);
  2552.    Beep();
  2553.    GetAKey();
  2554.    SEND(MEXIT);
  2555.    Exit();
  2556. }
  2557.  
  2558. doload()
  2559. {
  2560.    extern char loadname[];
  2561.    extern int loadflg;
  2562.  
  2563.    if (!loadname[0])
  2564.       getLine("Load which file?", loadname, 40);
  2565.    loadflg = loadname[0];
  2566.    if (loadflg)
  2567.       restgame(loadname);
  2568.    return 1;
  2569. }
  2570.  
  2571. int lastpiecex=  -1,lastpiecey= -1,lastpiecec= -1;
  2572.  
  2573. addapiece(str, c)
  2574.     char *str;
  2575.     int c;
  2576. {
  2577.    int x, y;
  2578.  
  2579.    while (str[0] == '[' && str[3] == ']' && str[1] >= 'a' && str[1] <= 's' &&
  2580.       str[2] >= 'a' && str[2] <= 's') {
  2581.       x = str[1] - 'a';
  2582.       y = str[2] - 'a';
  2583.       if (c == 2) {
  2584.      if (b(x, y) == 1)
  2585.         DoHand(x, y, 0);
  2586.      else if (b(x, y) == 2)
  2587.         DoHand(x, y, 1);
  2588.       } else {
  2589.      lastpiecex=x;
  2590.      lastpiecey=y;
  2591.      lastpiecec=c;
  2592.      setboard(x, y, c + 1);
  2593.      Kill(x, y, c + 1);
  2594.      Plt(&board, x, y);
  2595.      SEND(MMOVE);
  2596.      curplr=!curplr;
  2597.      SendCoord(x, y);
  2598.      sendint(c);
  2599.       }
  2600.       str += 4;
  2601.    }
  2602. }
  2603.  
  2604.  
  2605. loadlog()
  2606. {
  2607.    char instr[1024];
  2608.    extern int logflg;
  2609.  
  2610.    logflg = 0;
  2611.    fseek(logfile, 0, 0);
  2612.    while (!feof(logfile)) {
  2613.       fgets(instr, 1023, logfile);
  2614.       if (!strncmp(instr, "Black[", 6))
  2615.      addapiece(instr + 5, 0);
  2616.       else if (!strncmp(instr, "AddBlack[", 9))
  2617.      addapiece(instr + 8, 0);
  2618.       else if (!strncmp(instr, "White[", 6))
  2619.      addapiece(instr + 5, 1);
  2620.       else if (!strncmp(instr, "AddWhite[", 9))
  2621.      addapiece(instr + 8, 1);
  2622.       else if (!strncmp(instr, "AddEmpty[", 9))
  2623.      addapiece(instr + 8, 2);
  2624.    }
  2625.    logflg++;
  2626.    PrintBoard(&board);
  2627.    if (lastpiecec != -1) {
  2628.       sprintf(instr,"Last move %s %c%d",lastpiecec?"White":"Black",
  2629.           lastpiecex+'A',19-lastpiecey);
  2630.       addmes(instr);
  2631.    }      
  2632. }
  2633.  
  2634.  
  2635. int openlogfile()
  2636. {
  2637.    extern char logname[];
  2638.    extern int logflg;
  2639.    int d;
  2640.    char c;
  2641.  
  2642.    if (logfile = fopen(logname, "r+")) {
  2643.       loadlog();
  2644.       fseek(logfile, 0, 2);
  2645.       if (ftell(logfile)) {
  2646.      d = (-1);
  2647.      fseek(logfile, d, 2);
  2648.      do {
  2649.         d--;
  2650.         c = fgetc(logfile);
  2651.      }
  2652.      while ((!fseek(logfile, d, 2)) && ((c != ')') && (c != ']')));
  2653.      if (c == ')')
  2654.         d++;
  2655.      else
  2656.         d = 0;
  2657.       }
  2658.       fseek(logfile, d, 2);
  2659.       logflg = 2;
  2660.       return 1;
  2661.    } else if (logfile = fopen(logname, "a+")) {
  2662.       fprintf(logfile, "(\n;\nGaMe[1]\nVieW[]\nSiZe[%d]\n", dimensions);
  2663.       logflg = 2;
  2664.       return 0;
  2665.    } else {
  2666.       SEND(MEXIT);
  2667.       logflg = 0;
  2668.       fprintf(stderr, "Error opening logfile\n\n");
  2669.       Exit();
  2670.    }
  2671. }
  2672.  
  2673.  
  2674. logendlist()
  2675. {
  2676.    if (logflg)
  2677.       fprintf(logfile, "\n");
  2678. }
  2679.  
  2680.  
  2681. loglist(x, y, text)
  2682.     int x, y;
  2683.     char *text;
  2684. {
  2685.    if (logflg) {
  2686.       if (commenting) {
  2687.      commenting = 0;
  2688.      fprintf(logfile, "]\n");
  2689.       }
  2690.       fprintf(logfile, "%s[%c%c]", text, x + 'a', y + 'a');
  2691.       fflush(logfile);
  2692.    }
  2693. }
  2694.  
  2695.  
  2696. char *Player[] =
  2697. {
  2698.    "AddEmpty", "Black", "White"};
  2699.  
  2700. dolog(x, y, color)
  2701.     int x, y, color;
  2702. {
  2703.    if (logflg) {
  2704.       if (commenting) {
  2705.      commenting = 0;
  2706.      fprintf(logfile, "]\n");
  2707.       }
  2708.       fprintf(logfile, ";\n%s[%c%c]\n", Player[color], x + 'a', y + 'a');
  2709.       fflush(logfile);
  2710.    }
  2711. }
  2712.  
  2713.  
  2714. closelogfile()
  2715. {
  2716.    if (logflg == 2) {
  2717.       if (commenting)
  2718.      fprintf(logfile, "]\n");
  2719.       fprintf(logfile, ")\n");
  2720.       fclose(logfile);
  2721.    }
  2722. }
  2723.  
  2724.  
  2725. logcomment(comm, player)
  2726.     char *comm;
  2727.     int player;
  2728.  
  2729. {
  2730.    extern char *myname, *hisname;
  2731.    extern int usemess;
  2732.  
  2733.    if ((logflg) && (usemess) && (*comm) && (*comm != '\\')) {
  2734.       if (!commenting)
  2735.      fputs("Comment[", logfile);
  2736.       if ((player == 1) && (commenting != 1))
  2737.      fprintf(logfile, "\n %s:", myname);
  2738.       else if ((player == 2) && (commenting != 2))
  2739.      fprintf(logfile, "\n %s:", hisname);
  2740.       commenting = player;
  2741.       fputc(' ', logfile);
  2742.       for (; *comm; comm++) {
  2743.      if ((*comm == ')') || (*comm == '(') || (*comm == '[') || (*comm == ']'))
  2744.         fputc('\\', logfile);
  2745.      fputc(*comm, logfile);
  2746.       }
  2747.    }
  2748. }
  2749. SHAR_EOF
  2750. fi
  2751. if test -f 'go.c'
  2752. then
  2753.     echo shar: "will not over-write existing file 'go.c'"
  2754. else
  2755. cat << \SHAR_EOF > 'go.c'
  2756. /* Go written by Greg Hale (April 20 1987) */
  2757.  
  2758. #include "std.disclaimer"
  2759. #include "go.h"
  2760. #include <ctype.h>
  2761. #include <signal.h>
  2762. #include <strings.h>
  2763.  
  2764. bool iamserver = UNSET;
  2765. long random();
  2766. long time();
  2767.  
  2768. DEBUG(FILE * debug = NULL;
  2769. )
  2770. main(argc, argv)
  2771.     int argc;
  2772.     char **argv;
  2773. {
  2774.    extern int loadflg, logflg, myport;
  2775.    extern char loadname[], *hisname, waiting;
  2776.    int port, trap_cdump(), trap_sigint(), tstp(), ts_tp();
  2777.    char *p, *malloc();
  2778.  
  2779.    if (argc <= 1)
  2780.       helpstart(argv);
  2781.    parseline(argc, argv);
  2782.  
  2783.    sockmask[0] = 1;
  2784.  
  2785.    port = myport;
  2786.  
  2787.    signal(SIGINT, SIG_IGN);
  2788.    signal(SIGPIPE, SIG_IGN);
  2789.    srandom(time((long *) NULL));
  2790.  
  2791.    Init();
  2792.  
  2793.    signal(SIGINT, trap_sigint);
  2794.    setcore(trap_cdump);        /* set up the core dump trap */
  2795.  
  2796.    p = hisname;            /* used to be argv[argc-1] */
  2797.    connectport(p, port);
  2798.    doneconnectmes();
  2799.    waiting = 0;
  2800.  
  2801.    player = iamserver;
  2802.    DEBUG(debug = fopen((player) ? "/tmp/deb1" : "/tmp/deb0", "w");
  2803.    )
  2804.       printscore();
  2805.    initmesg();
  2806.    DEBUG(fprintf(debug, "Ready to Synchronize\n");
  2807.    fflush(debug);
  2808.    )
  2809.       Synchronize();
  2810.    if (timedgame)
  2811.       sendtimestart();
  2812.    if (!((logflg && openlogfile()) || (loadflg && doload()))) {
  2813.       PrintBoard(&board);
  2814.       sethandi();
  2815.    }
  2816.    DEBUG(fprintf(debug, "Ready to Loop\n");
  2817.    fflush(debug);
  2818.    )
  2819.       Loop();
  2820.  
  2821.    testsave();
  2822.    CLEAR();
  2823.  
  2824.    Exit();
  2825. }
  2826.  
  2827.  
  2828. /* Make sure all game parameters match in programs */
  2829. Synchronize()
  2830. {
  2831.    extern int strength, opponstr, handin, handicaps;
  2832.    int temp;
  2833.    extern char *myname;
  2834.  
  2835.  
  2836.    swap(MSTR, strength, &opponstr,
  2837.     "Incompatable version: strength not sent from other program.\n");
  2838.  
  2839.    swap(MMODE, 1, &temp, "Incompatable version: demoflag not sent from other program.\n");
  2840.  
  2841.  
  2842.    swap(MSIZE, dimensions, &temp,
  2843.     "Incompatable verison: size not sent from other program.\n");
  2844.    if (temp < dimensions)
  2845.       dimensions = temp;
  2846.    /* dimensions = dimensions / 2 * 2 + 1; */
  2847.    MAXX = MAXY = dimensions;
  2848.    handin = (dimensions > 12) ? 3 : 2;
  2849.  
  2850.    swap(MHAND, handicaps, &temp,
  2851.     "Incompatable verison: # of handicaps not sent from other program.\n");
  2852.    if (temp >= 0 || handicaps >= 0) {
  2853.       handicaps = (temp > handicaps ? temp : handicaps);
  2854.    } else {
  2855.       temp = opponstr - strength;
  2856.       handicaps = (temp > 0 ? temp : -temp);
  2857.       handicaps = (handicaps * dimensions * dimensions) / (19 * 19);
  2858.       if (temp)
  2859.      player = temp > 0;
  2860.    }
  2861.  
  2862. }
  2863.  
  2864.  
  2865. swap(mesg, s, r, err)
  2866.     char *mesg, *err;
  2867.     int *r, s;
  2868. {
  2869.    char line[100];
  2870.  
  2871.    SEND(mesg);
  2872.    RECV(line);
  2873.    if (strcmp(line, mesg)) {
  2874.       error(err);
  2875.    }
  2876.    sprintf(line, "%d", s);
  2877.    SEND(line);
  2878.  
  2879.    RECV(line);
  2880.    *r = atoi(line);
  2881. }
  2882.  
  2883.  
  2884. Exit()
  2885. {
  2886.    unsetmode();
  2887.    endwin();
  2888.    closelogfile();
  2889.    exit(0);
  2890. }
  2891.  
  2892.  
  2893. Init()
  2894. {
  2895.    extern int tstp();
  2896.    int myts_tp(), myts_cont();
  2897.  
  2898.    MAXX = dimensions;
  2899.    MAXY = dimensions;
  2900.  
  2901.    initscr();
  2902.    /* signal (SIGTSTP, myts_tp); signal (SIGCONT, myts_cont); */
  2903.    setmode();
  2904.  
  2905.    CLEAR();
  2906.    InitBoard(&board);
  2907.    SetStat(HANDICAP);
  2908. }
  2909. SHAR_EOF
  2910. fi
  2911. if test -f 'handicap.c'
  2912. then
  2913.     echo shar: "will not over-write existing file 'handicap.c'"
  2914. else
  2915. cat << \SHAR_EOF > 'handicap.c'
  2916. #include "std.disclaimer"
  2917. #include "go.h"
  2918.  
  2919. #define MAXHANDICAPS 9
  2920.  
  2921. hcap(x, y, log)
  2922.     int x, y, log;
  2923. {
  2924.    extern FILE *logfile;
  2925.    cx = x;
  2926.    cy = y;
  2927.    Handicap(!b(x, y));
  2928.    if (log)
  2929.       fprintf(logfile, "[%c%c]", x + 'a', y + 'a');
  2930. }
  2931.  
  2932. sethandi()
  2933. {
  2934.    extern int handicaps, handin;
  2935.    int savelog;
  2936.    extern int logflg;
  2937.    extern FILE *logfile;
  2938.  
  2939.    int h;
  2940.    h = handicaps;
  2941.    if (h > MAXHANDICAPS)
  2942.       h = MAXHANDICAPS;
  2943.    SetStat(HANDICAP);
  2944.    if (h < 2)
  2945.       return;
  2946.    if (savelog = logflg) {
  2947.       logflg = 0;
  2948.       fprintf(logfile, "AddBlack");
  2949.    }
  2950.    switch (h) {
  2951.    case 5:
  2952.       hcap(MAXX / 2, MAXY / 2, savelog);
  2953.    case 4:
  2954.       hcap(handin, MAXY - 1 - handin, savelog);
  2955.    case 3:
  2956.       hcap(MAXX - 1 - handin, handin, savelog);
  2957.    case 2:
  2958.       hcap(MAXX - 1 - handin, MAXY - 1 - handin, savelog);
  2959.       hcap(handin, handin, savelog);
  2960.       break;
  2961.    case 7:
  2962.       hcap(MAXX / 2, MAXY / 2, savelog);
  2963.    case 6:
  2964.       hcap(handin, handin, savelog);
  2965.       hcap(MAXX - 1 - handin, MAXY - 1 - handin, savelog);
  2966.       hcap(MAXX - 1 - handin, handin, savelog);
  2967.       hcap(handin, MAXY - 1 - handin, savelog);
  2968.       hcap(handin, MAXY / 2, savelog);
  2969.       hcap(MAXX - 1 - handin, MAXY / 2, savelog);
  2970.       break;
  2971.    case 9:
  2972.       hcap(MAXX / 2, MAXY / 2, savelog);
  2973.    case 8:
  2974.       hcap(handin, handin, savelog);
  2975.       hcap(MAXX - 1 - handin, MAXY - 1 - handin, savelog);
  2976.       hcap(MAXX - 1 - handin, handin, savelog);
  2977.       hcap(handin, MAXY - 1 - handin, savelog);
  2978.       hcap(handin, MAXY / 2, savelog);
  2979.       hcap(MAXX - 1 - handin, MAXY / 2, savelog);
  2980.       hcap(MAXX / 2, handin, savelog);
  2981.       hcap(MAXX / 2, MAXY - 1 - handin, savelog);
  2982.       break;
  2983.    }
  2984.    if (logflg = savelog)
  2985.       fprintf(logfile, "\n");
  2986.  
  2987. }
  2988.  
  2989.  
  2990.  
  2991. Handicap(i)
  2992.     int i;
  2993. {
  2994.    int savehand;
  2995.    extern int handicaps;
  2996.    savehand = handicaps;
  2997.    if (AreWe(HANDICAP))
  2998.       sethand(cx, cy, i);
  2999.    handicaps = savehand;
  3000. }
  3001. SHAR_EOF
  3002. fi
  3003. if test -f 'help.c'
  3004. then
  3005.     echo shar: "will not over-write existing file 'help.c'"
  3006. else
  3007. cat << \SHAR_EOF > 'help.c'
  3008. #include "std.disclaimer"
  3009. #include "go.h"
  3010. #include <curses.h>
  3011.  
  3012. help()
  3013. {
  3014.    CLEAR();
  3015.  
  3016.    /* first five lines */
  3017.    printf("\
  3018.     %s: by Greg Hale, Jeff Boscole, Adrian Mariano, and Fred Hansen\n\
  3019.     \n\
  3020.     ^c:       leave the game\n\
  3021.     ?:        help\n\
  3022.     [12346789hjklyubnHJKLYUBN]:  move cursor\n\
  3023.     \n",
  3024.       VERSION);
  3025.  
  3026.    /* middle eight lines */
  3027.    if (AreWe(HANDICAP)) {
  3028.  
  3029.       printf("\
  3030.     MODE - Setting game parameters\n\
  3031.     \n\
  3032.             <space>,0: place or remove handicap stone at current point\n\
  3033.             p:        start play\n\
  3034.             s:        switch which player you are (black/white)\n\
  3035.             *:        set standard handicap stones\n\
  3036.             T:        set time limit and byoyomi\n\
  3037.     \n"
  3038.      );
  3039.  
  3040.    } else if (AreWe(PLAY)) {
  3041.  
  3042.       printf("\
  3043.     MODE - Playing the game\n\
  3044.             <space>, 0:  play at current point\n\
  3045.             /:        show the last move\n\
  3046.             p:        pass your turn\n\
  3047.             s:        turn on scoring mode\n\
  3048.             R:        resign and give the win to the other player\n\
  3049.             z,x:      set and unset moves for demonstrations\n\
  3050.             P:        Pause/unpause the clock\n\
  3051.         ^P:       PANIC - press only if game is not synchronized"
  3052.      );
  3053.  
  3054.    } else if (AreWe(SCORE)) {
  3055.  
  3056.       printf("\
  3057.     MODE - computing the score\n\
  3058.     \n\
  3059.             <space>, 0: declare that group at current point is dead\n\
  3060.             t:        tally--show how territory is defined\n\
  3061.             c:        cancel scoring mode and restore game\n\
  3062.             q:        print score and quit\n\
  3063.             R:        resign and give the win to the other player\n\
  3064.     \n"
  3065.      );
  3066.  
  3067.    }
  3068.    /* last eleven lines */
  3069.    printf("\
  3070.     \n\
  3071.     m:        send a message to the other player\n\
  3072.                 press control-D to resume playing\n\
  3073.     C:        clear the board\n\
  3074.     ^l:       redraw the screen\n\
  3075.     V:        toggle inverse <-> normal video\n\
  3076.     S:        save the current board, turn, and score\n\
  3077.     #:        load a saved game\n\
  3078.     \n\
  3079.     <hit any key to continue>"
  3080.       );
  3081.  
  3082.    refresh();
  3083.    GetAKey0();
  3084.    clear();
  3085. }
  3086.  
  3087.  
  3088. longhelp()
  3089. {
  3090.    system(HELP_CMD);
  3091.    exit(0);
  3092. }
  3093. SHAR_EOF
  3094. fi
  3095. if test -f 'life.c'
  3096. then
  3097.     echo shar: "will not over-write existing file 'life.c'"
  3098. else
  3099. cat << \SHAR_EOF > 'life.c'
  3100. #include "std.disclaimer"
  3101. #include "go.h"
  3102.  
  3103. IsSafe(x, y)
  3104.     int x, y;
  3105. {
  3106.    int t;
  3107.    if (!ir(x, y) || (t = b(x, y)) == NONE)
  3108.       return (FALSE);
  3109.    InitBoard(&marks);
  3110.    return (esc(x, y, t));
  3111. }
  3112.  
  3113. esc(x, y, t)
  3114.     int x, y, t;
  3115. {
  3116.    if (!ir(x, y))
  3117.       return (FALSE);
  3118.    if (b(x, y) == NONE)
  3119.       return (TRUE);
  3120.    if (!m(x, y) && b(x, y) == t) {
  3121.       m(x, y) = MARK;
  3122.       return (esc(x - 1, y, t) ||
  3123.           esc(x + 1, y, t) ||
  3124.           esc(x, y - 1, t) ||
  3125.           esc(x, y + 1, t));
  3126.    }
  3127.    return (FALSE);
  3128. }
  3129.  
  3130.  
  3131. Owner(x, y)
  3132.     int x, y;
  3133. {
  3134.    int o;
  3135.    InitBoard(&marks);
  3136.    o = Owner0(x, y);
  3137.    return (o == -1 ? 3 : o);
  3138. }
  3139.  
  3140. Owner0(x, y)
  3141.     int x, y;
  3142. {
  3143.    if (m(x, y) || !ir(x, y))
  3144.       return 3;
  3145.    m(x, y) = 1;
  3146.    if (b(x, y) != NONE)
  3147.       return (b(x, y) + 3);
  3148.    return (New(New(New(New(3, x - 1, y), x + 1, y), x, y - 1), x, y + 1));
  3149.  
  3150. }
  3151.  
  3152. New(o, x2, y2)            /* 3= undetermined, 4=p1, 5=p2, -1=shared */
  3153.     register int o;
  3154.     int x2, y2;
  3155. {
  3156.    register int n;        /* old, new */
  3157.    n = Owner0(x2, y2);
  3158.    if (o == 3)
  3159.       return n;
  3160.    if (n == 3)
  3161.       return o;
  3162.    if (o < 0)
  3163.       return o;
  3164.    return (n == o ? o : -1);
  3165. }
  3166.  
  3167. int ir(x, y)
  3168.     int x, y;
  3169. {
  3170.    return ((x >= 0) && (x < MAXX) && (y >= 0) && (y < MAXY));
  3171. }
  3172. SHAR_EOF
  3173. fi
  3174. if test -f 'loop.c'
  3175. then
  3176.     echo shar: "will not over-write existing file 'loop.c'"
  3177. else
  3178. cat << \SHAR_EOF > 'loop.c'
  3179. #include "std.disclaimer"
  3180. #include "go.h"
  3181. #include <strings.h>
  3182. #include <curses.h>
  3183.  
  3184. extern int errno;
  3185. extern int mesflg, curx, cury;
  3186.  
  3187.  
  3188. Loop()
  3189. {
  3190.    int mask;
  3191.    struct timeval waittime;
  3192.    int result;
  3193.  
  3194. /*   homemes();*/
  3195.    /* strcpy(message,"- "); strcat(message,VERSION); strcat(message," By Greg
  3196.     * Hale"); addmes(message); */
  3197.    addmes("- Set up handicap.");
  3198.    addmes("- Press 'p' to play");
  3199.  
  3200.    inittick();
  3201.  
  3202.    do {
  3203.       myturn = (!player && curplr) || (player && !curplr);
  3204.       if (AreWe(PAUSED))
  3205.      notify(" Paused...");
  3206.       else if (AreWe(PLAY)) {
  3207.      if (myturn) {
  3208.         notify(" Your turn");
  3209.      } else
  3210.         notify(" Waiting for opponent");
  3211.       } else if (AreWe(HANDICAP)) {
  3212.      notify(" Set Handicap");
  3213.       } else if (AreWe(SCORE)) {
  3214.      notify(" Scoring");
  3215.       } else {
  3216.      notify(" What are we doing??");
  3217.       }
  3218.  
  3219.       do {
  3220.      if (mesflg)
  3221.         move(cury, curx);
  3222.      else
  3223.         moveto(cx, cy);
  3224.  
  3225.      REFRESH();
  3226.  
  3227.      mask = sockmask[0] | sockmask[1];
  3228.      if (timedgame && AreWe(PLAY)) {
  3229.         waittime.tv_sec = 1;
  3230.         waittime.tv_usec = 0;
  3231.         result = select(32, &mask, 0, 0, &waittime);
  3232.      } else
  3233.         result = select(32, &mask, 0, 0, 0);
  3234.      if (result == -1) {
  3235.         if (errno == EINTR)
  3236.            continue;
  3237.         else
  3238.            error(" Error- Select failed\n");
  3239.      } else if (result == 0) {
  3240.         if (AreWe(PLAY))
  3241.            tick(myturn);
  3242.      }
  3243.       } while (result == 0);
  3244.  
  3245.       if (mask & sockmask[0]) {
  3246.      DoLoop();
  3247.       } else if (mask == sockmask[1]) {
  3248.      myturn = !myturn;
  3249.      DoOther();
  3250.       } else
  3251.      error(" Error - bad select\n");
  3252.  
  3253.    }
  3254.    while (!AreWe(EXIT));
  3255. }
  3256. SHAR_EOF
  3257. fi
  3258. if test -f 'mesg.c'
  3259. then
  3260.     echo shar: "will not over-write existing file 'mesg.c'"
  3261. else
  3262. cat << \SHAR_EOF > 'mesg.c'
  3263. #include "std.disclaimer"
  3264. #include "go.h"
  3265. #include <curses.h>
  3266. #include <ctype.h>
  3267.  
  3268. extern char *opponent;
  3269.  
  3270. int mesgx = 42;
  3271. int mesgy = 7;
  3272. int mesgx2 = 78;
  3273. int mesgy2 = 14;
  3274.  
  3275.  
  3276. int talkx = 42;
  3277. int talky = 16;
  3278. int talkx2 = 78;
  3279. int talky2 = 23;
  3280.  
  3281. int timex = 55;
  3282.  
  3283. static char mesgbuf[1000];
  3284. int cur;
  3285. int curx;
  3286. int cury;
  3287. int mesflg;
  3288.  
  3289. int tcury;
  3290.  
  3291. notify(s)
  3292.     char *s;
  3293. {
  3294.    mvaddstr(0, 0, "                                ");
  3295.    mvaddstr(0, 0, s);
  3296. }
  3297.  
  3298. initmesg()
  3299. {
  3300.    mesflg = 0;
  3301.    cur = -1;
  3302.    curx = mesgx;
  3303.    cury = mesgy;
  3304.  
  3305.    tcury = talky;
  3306.  
  3307.  
  3308.    mvaddstr(0, mesgx, "   -- Internet ");
  3309.    mvaddstr(0, mesgx + 15, VERSION);
  3310.    mvaddstr(0, mesgx + 16 + strlen(VERSION), "--");
  3311.    /* mvaddstr (mesgy - 1, mesgx, "   -- your messages ^D end   --"); mvaddstr
  3312.     * (talky - 1, talkx, "   -- opponent      ^D end   --"); */
  3313.    mvaddstr(mesgy - 1, mesgx, "   -- you -- ^D ends");
  3314.    mvaddstr(talky - 1, talkx, "   -- opp --");
  3315. }
  3316.  
  3317. addtalk(s)
  3318.     char *s;
  3319. {
  3320.    logcomment(s, 2);
  3321.    mvaddstr(tcury, talkx, s);
  3322.    if (tcury++ == talky2)
  3323.       tcury = talky;
  3324.    move(tcury, talkx);
  3325.    clrtoeol();
  3326. }
  3327.  
  3328. domesg(c)
  3329.     char c;
  3330. {
  3331.    if (c == '\b' || c == '\177')
  3332.       delchar();
  3333.    else if (c == '\n')
  3334.       mesgnl();
  3335.    else if (c == 004) {        /* ^D returns to board now */
  3336.       if (curx != mesgx)
  3337.      mesgnl();
  3338.       mesflg = 0;
  3339.       return (0);
  3340.    } else {
  3341.       if (isprint(c) || c == 007)
  3342.      addchar(c);
  3343.    }
  3344.    move(cury, curx);
  3345. }
  3346.  
  3347. mesgnl()
  3348. {
  3349.    sendbuf();
  3350.    curx = mesgx;
  3351.    if (cury++ == mesgy2)
  3352.       cury = mesgy;
  3353.    move(cury, curx);
  3354.    clrtoeol();
  3355. }
  3356.  
  3357. addchar(c)
  3358.     char c;
  3359. {
  3360.    mesgbuf[++cur] = c;
  3361.    mvaddch(cury, curx, c);
  3362.    if (curx++ == mesgx2) {
  3363.       mesgnl();
  3364.    }
  3365. }
  3366.  
  3367. delchar()
  3368. {
  3369.    if (cur >= 0 && curx > mesgx) {
  3370.       curx--;
  3371.       cur--;
  3372.       mvaddch(cury, curx, ' ');
  3373.    }
  3374. }
  3375.  
  3376. sendbuf()
  3377. {
  3378.    mesgbuf[++cur] = '\0';
  3379.    SEND(MMESSAGE);
  3380.    SEND(mesgbuf);
  3381.    cur = -1;
  3382.    logcomment(mesgbuf, 1);
  3383. }
  3384.  
  3385. /* show time at y,timex, where y is talky-1 for you==0 or mesgy-1 iff you==1 t
  3386.  * is seconds remaining.  s is number of stones left in byomi */
  3387.  
  3388. showtime(myturn, t)
  3389.     bool myturn;
  3390.     struct timing *t;
  3391. {
  3392.    int y;
  3393.    char buf[25];
  3394.    long secs = t->left.tv_sec;
  3395.    if (!timedgame) return 0;
  3396. /*      strcpy(buf, "                     ");*/
  3397.    else if (secs < 1800 || t->byoyomi
  3398.         DEBUG(||TRUE)
  3399.       )
  3400.       sprintf(buf, "%d:%02d:%02d", secs / 3600, (secs % 3600) / 60, secs % 60);
  3401.    else
  3402.       sprintf(buf, "%d:%02d", secs / 3600, (secs % 3600) / 60);
  3403.    if (t->byoyomi)
  3404.       sprintf(buf + strlen(buf), "  %d stones", t->stones);
  3405.    y = ((myturn) ? mesgy : talky) - 1;
  3406.    mvaddstr(y, timex, buf);
  3407. }
  3408. SHAR_EOF
  3409. fi
  3410. if test -f 'opts.c'
  3411. then
  3412.     echo shar: "will not over-write existing file 'opts.c'"
  3413. else
  3414. cat << \SHAR_EOF > 'opts.c'
  3415. #include "std.disclaimer"
  3416. #include "go.h"
  3417. #include <strings.h>
  3418. #include <sys/file.h>
  3419.  
  3420. #define ISARG(s) (!strncmp(*argv,s,strlen(s)))
  3421.  
  3422. int numberblink;
  3423.  
  3424. parseline(argc, argv)
  3425.     int argc;
  3426.     char **argv;
  3427. {
  3428.    char **argval;
  3429.    extern char loadname[], logname[], *hisname, *myname;
  3430.    extern int beepflg, strength, myport, handicaps;
  3431.    extern int loadflg;
  3432.    extern int inverse;
  3433.    extern int usemess;
  3434.    extern int logflg;
  3435.    extern float wins;
  3436.    extern FILE *logfile;
  3437.  
  3438.    GetStr();
  3439.    inverse = INVERSE;
  3440.    numberblink = 4;
  3441.    handicaps = 0;
  3442.    argval = argv;
  3443.    dimensions = MAXDIM;
  3444.    myport = DEFAULTPORT;
  3445.    beepflg = 1;
  3446.    usemess = 1;
  3447.    hisname = NULL;
  3448.  
  3449.    while (++argv, --argc > 0) {
  3450.       if (ISARG("-h")) {
  3451.      longhelp();
  3452.       } else if (ISARG("-s")) {
  3453.      if (--argc > 0) {
  3454.         dimensions = atoi(*++argv);
  3455.         if (dimensions < 7)
  3456.            dimensions = 7;
  3457.         if (dimensions > 19)
  3458.            dimensions = 19;
  3459.      } else
  3460.         helpstart(argval);
  3461.       } else if (ISARG("-p")) {
  3462.      if (--argc > 0)
  3463.         myport = atoi(*++argv);
  3464.      else
  3465.         helpstart(argval);
  3466.       } else if (ISARG("-a")) {
  3467.      usemess = 0;
  3468.       } else if (ISARG("-H")) {
  3469.      if (--argc > 0)
  3470.         handicaps = atoi(*++argv);
  3471.      else
  3472.         helpstart(argval);
  3473.       } else if (ISARG("-c")) {
  3474.      changes();
  3475.       } else if (ISARG("-r")) {
  3476.      showstr();
  3477.      exit(0);
  3478.       } else if (ISARG("-B")) {
  3479.      if (--argc > 0) {
  3480.         char black;
  3481.         black = atoi(*++argv);
  3482.         if ((black) && (black < 127))
  3483.            pieces[1] = black + inverse;
  3484.         else
  3485.            pieces[1] = (**argv) + inverse;
  3486.      } else
  3487.         helpstart(argval);
  3488.       } else if (ISARG("-E")) {
  3489.      handicaps = -2;
  3490.       } else if (ISARG("-V")) {
  3491.      char c;
  3492.      if (inverse) {
  3493.         for (c = 0; c < 6; c++)
  3494.            pieces[c] -= 128;
  3495.         inverse = 0;
  3496.      } else {
  3497.         for (c = 0; c < 6; c++)
  3498.            pieces[c] += 128;
  3499.         inverse = 128;
  3500.      }
  3501.       } else if (ISARG("-q")) {
  3502.      beepflg = 0;
  3503.       } else if (ISARG("-n")) {
  3504.      if (--argc > 0) {
  3505.         numberblink = atoi(*++argv);
  3506.         if (numberblink < 0)
  3507.            numberblink = 4;
  3508.      } else
  3509.         helpstart(argval);
  3510.  
  3511.       } else if (ISARG("-l")) {
  3512.      if (--argc > 0) {
  3513.         loadflg++;
  3514.         strcpy(loadname, *++argv);
  3515.      } else
  3516.         helpstart(argval);
  3517.       } else if (ISARG("-L")) {
  3518.      if (--argc > 0) {
  3519.         logflg = 1;
  3520.         strcpy(logname, *++argv);
  3521.      } else
  3522.         helpstart(argval);
  3523.       } else if (ISARG("-t")) {
  3524.      if (--argc > 3) {
  3525.         totalmin = atoi(*++argv);
  3526.         byosec = atoi(*++argv);
  3527.         byostones = atoi(*++argv);
  3528.         byoextends = atoi(*++argv);
  3529.         timedgame = TRUE;
  3530.         argc -= 3;
  3531.  
  3532.      } else
  3533.         helpstart(argval);
  3534.       } else if (ISARG("-R")) {
  3535.      wins = 0.0;
  3536.      if (--argc) {
  3537.         if (*argv[1] == '+') {
  3538.            strength++;
  3539.            argv++;
  3540.         } else if (*argv[1] == '-') {
  3541.            strength--;
  3542.            argv++;
  3543.  
  3544.         } else if (--argc) {
  3545.            switch (*argv[2]) {
  3546.         WHEN 'k':
  3547.           strength = 31 - atoi(argv[1]);
  3548.         WHEN 'd':
  3549.           strength = 30 + atoi(argv[1]);
  3550.         WHEN 'p':
  3551.           strength = 39 + atoi(argv[1]);
  3552.         OTHERWISE:
  3553.           helpstart(argval);
  3554.            }
  3555.            argv += 2;
  3556.         } else
  3557.            helpstart(argval);
  3558.  
  3559.         if (strength < 1)
  3560.            strength = 1;
  3561.         else if (strength > MAXSTR)
  3562.            strength = MAXSTR;
  3563.  
  3564.         savestr0();
  3565.         exit(0);
  3566.      } else
  3567.         helpstart(argval);
  3568.       } else {
  3569.      hisname = *argv++;
  3570.       }
  3571.    }
  3572.    if (hisname == NULL)
  3573.       helpstart(argval);
  3574. }
  3575.  
  3576.  
  3577. helpstart(argv)
  3578.     char *argv[];
  3579. {
  3580.  
  3581.  
  3582.  
  3583.  
  3584.    fprintf(stderr, "                      %s\n", VERSION);
  3585.    fprintf(stderr, "\nUsage:\n");
  3586.    fprintf(stderr, "%s {opts} user[@host]\n", argv[0]);
  3587.  
  3588.    fprintf(stderr, "{opts} is any of :\n");
  3589.    fprintf(stderr, "-p port#               which address to meet at.\n");
  3590.    fprintf(stderr, "-q                     quiet -- don't beep.\n");
  3591.    fprintf(stderr, "-s size                set the board size [7-19].\n");
  3592.    fprintf(stderr, "-n blink               set the number of times to blink a piece.\n");
  3593.    fprintf(stderr, "-H #handicaps          set the number of handicap stones.\n");
  3594.    fprintf(stderr, "-c                     give the opening message and credits.\n");
  3595.    fprintf(stderr, "-l <filename>          load a saved/sample game from diagram file.\n");
  3596.    fprintf(stderr, "-L <filename>          load or create a move by move log of game.\n");
  3597.    fprintf(stderr, "-a                     abridged log -- don't include player messages.\n");
  3598.    fprintf(stderr, "-t time byo stones ex  where time is time in minutes, byo and stones are\n");
  3599.    fprintf(stderr, "                       the time in seconds and number of stones for\n");
  3600.    fprintf(stderr, "                       byoyomi, and ex is the number of extends.\n");
  3601. #if (INVERSE==0)
  3602.    fprintf(stderr, "-V                     use inverse video.\n");
  3603. #else
  3604.    fprintf(stderr, "-V                     use normal video instead of inverse.\n");
  3605. #endif
  3606.    fprintf(stderr, "-B {number|char}       Use ascii code number, or char for black stones.\n");
  3607.    fprintf(stderr, "-E                     use handicap info from go_strength.\n");
  3608.    fprintf(stderr, "OR:\n");
  3609.    fprintf(stderr, "\"%s -r\" for your current rank.\n", argv[0]);
  3610.    fprintf(stderr, "\"%s -h\" for help.\n", argv[0]);
  3611.    fprintf(stderr, "\"%s -R # {k|d|p} to set your rank to # kyu/dan/pro dan respectively\n", argv[0]);
  3612.    fprintf(stderr, "\"%s -R {+|-} to increase/decrease your rank respectively\n", argv[0]);
  3613.    exit(0);
  3614. }
  3615. SHAR_EOF
  3616. fi
  3617. if test -f 'putpiece.c'
  3618. then
  3619.     echo shar: "will not over-write existing file 'putpiece.c'"
  3620. else
  3621. cat << \SHAR_EOF > 'putpiece.c'
  3622. #include "std.disclaimer"
  3623. #include "go.h"
  3624. #define DELAY 30000
  3625.  
  3626. int lastx, lasty;
  3627.  
  3628. extern int logflg;
  3629.  
  3630. putpiece(cx, cy, cur, blinkflg, switchB)
  3631.     int cx, cy;
  3632.     int cur;
  3633.     int blinkflg;
  3634.     int switchB;
  3635. {
  3636.    if (blinkflg)
  3637.       /*Beep()*/;
  3638.    if (b(cx, cy) == NONE) {
  3639.       int c, d;
  3640.       savelast();
  3641.       c = !cur + 1;
  3642.       d = cur + 1;
  3643.       setboard(cx, cy, d);
  3644.       if (NoMove(cx, cy, c, d)) {
  3645.      b(cx, cy) = 0;
  3646.      Plt(&board, cx, cy);
  3647.       } else {
  3648.      Kill(cx, cy, d);
  3649.  
  3650.      if (!compboard()) {
  3651.         homemes();
  3652.         addmes("- That's a KO. You can't");
  3653.         addmes("  go there.");
  3654.         restlast();
  3655.      } else {
  3656.         lastx = cx;
  3657.         lasty = cy;
  3658.         if (switchB) {
  3659.            SEND(MMOVE);
  3660.            SendCoord(cx, cy);
  3661.            sprintf(buf, "%d", cur);
  3662.            SEND(buf);
  3663.         }
  3664.         Plt(&board, cx, cy);
  3665.         REFRESH();
  3666.         if (blinkflg)
  3667.            blink(cx, cy, d);
  3668.         if (logflg)
  3669.            dolog(cx, cy, d);
  3670.         if (switchB)
  3671.            NextPlr();
  3672.         saveboard0();
  3673.      }
  3674.       }
  3675.    }
  3676. }
  3677.  
  3678. ShowLast()
  3679. {
  3680.    blink(lastx, lasty, b(lastx, lasty));
  3681. }
  3682.  
  3683. blink(x, y, d)
  3684.     int x, y, d;
  3685. {
  3686.    extern int numberblink;
  3687.    int blinks;
  3688.    int mask;
  3689.    struct timeval tv;
  3690.    if (!AreWe(HANDICAP)) {
  3691.       for (blinks = numberblink; blinks--;) {
  3692.      mask = sockmask[0];
  3693.      tv.tv_sec = 0;
  3694.      tv.tv_usec = 200000;
  3695.      if (select(sizeof(mask), &mask, 0, 0, &tv))
  3696.         break;
  3697.      b(x, y) = b(x, y) ? 0 : d;
  3698.      Plt(&board, x, y);
  3699.      REFRESH();
  3700.       }
  3701.       b(x, y) = d;
  3702.       Plt(&board, x, y);
  3703.       REFRESH();
  3704.    }
  3705. }
  3706.  
  3707.  
  3708. GetCoord(x, y)
  3709.     int *x, *y;
  3710. {
  3711.    RECV(buf);
  3712.    *x = atoi(buf);
  3713.    RECV(buf);
  3714.    *y = atoi(buf);
  3715. }
  3716.  
  3717. SendCoord(x, y)
  3718.     int x, y;
  3719. {
  3720.    sprintf(buf, "%d", x);
  3721.    SEND(buf);
  3722.    sprintf(buf, "%d", y);
  3723.    SEND(buf);
  3724. }
  3725. SHAR_EOF
  3726. fi
  3727. if test -f 'score.c'
  3728. then
  3729.     echo shar: "will not over-write existing file 'score.c'"
  3730. else
  3731. cat << \SHAR_EOF > 'score.c'
  3732. #include "std.disclaimer"
  3733. #include "go.h"
  3734. #include <curses.h>
  3735.  
  3736. Score()
  3737. {
  3738.    extern int handicaps;
  3739.    char temp[100];
  3740.    float komi, s1, s2, s1space, s2space;
  3741.    int i, j;
  3742.  
  3743.    s1 = s2 = 0.0;
  3744.    Tally();
  3745.    for (i = 0; i < MAXX; i++) {
  3746.       for (j = 0; j < MAXY; j++) {
  3747.      if (b(i, j) == 4) {
  3748.         s1++;
  3749.      } else if (b(i, j) == 5) {
  3750.         s2++;
  3751.      }
  3752.       }
  3753.    }
  3754.    komi = (handicaps > 0 || dimensions != 19) ? 0.0 : KOMI;
  3755.    s1space = s1;
  3756.    s2space = s2;
  3757.    s2 += hama[1];
  3758.    s1 += hama[0];
  3759.    s2 = s2 + komi;
  3760.    if (s1 > s2)
  3761.       sprintf(temp, "Black has won by %g points!", s1 - s2);
  3762.    else if (s2 > s1)
  3763.       sprintf(temp, "White has won by %g points!", s2 - s1);
  3764.    else
  3765.       sprintf(temp, "It was a tie game!");
  3766.  
  3767.    homemes();
  3768.    addmes("Final Results:");
  3769.    addmes(temp);
  3770.  
  3771.    if (s1 != s2) {
  3772.       iwon = (player && (s1 > s2)) || (!player && (s1 < s2));
  3773.       savestr();
  3774.    }
  3775.    GetAKey();
  3776.    clear();
  3777.    move(1, 0);
  3778.    printw("------------------------------------------------\n");
  3779.    printw("-       Final Results (Japanese counting)      -\n");
  3780.    printw("------------------------------------------------\n");
  3781.    printw("-     Territory + Captured + Komi = Final Score\n");
  3782.    printw("-Black:  %3.1f       %3.1f        0         %3.1f\n",
  3783.       s1space, (float) hama[0], s1);
  3784.    printw("-White:  %3.1f       %3.1f        %1.1f         %3.1f\n",
  3785.       s2space, (float) hama[1], komi, s2);
  3786.    printw("-------------------------------------------------\n");
  3787.    printw("\n%s\n", temp);
  3788.    refresh();
  3789.    testsave();
  3790.    move(20, 0);
  3791.    refresh();
  3792.    Exit();
  3793. }
  3794.  
  3795.  
  3796.  
  3797.  
  3798.  
  3799. Tally()
  3800. {
  3801.    int i, j;
  3802.    for (i = 0; i < MAXX; i++)
  3803.       for (j = 0; j < MAXY; j++)
  3804.      if (b(i, j) == NONE)
  3805.         fill(i, j, Owner(i, j));
  3806. }
  3807.  
  3808.  
  3809.  
  3810. static int fillwith;
  3811.  
  3812. fill(x, y, type)
  3813.     int x, y, type;
  3814. {
  3815.    fillwith = type;
  3816.    InitBoard(&marks);
  3817.    fill0(x, y);
  3818. }
  3819.  
  3820. fill0(x, y)
  3821.     int x, y;
  3822. {
  3823.    if (ir(x, y) && b(x, y) == NONE && m(x, y) == NONE) {
  3824.       m(x, y) = MARK;
  3825.       b(x, y) = fillwith;
  3826.       fill0(x - 1, y);
  3827.       fill0(x + 1, y);
  3828.       fill0(x, y - 1);
  3829.       fill0(x, y + 1);
  3830.    }
  3831. }
  3832. SHAR_EOF
  3833. fi
  3834. if test -f 'strength.c'
  3835. then
  3836.     echo shar: "will not over-write existing file 'strength.c'"
  3837. else
  3838. cat << \SHAR_EOF > 'strength.c'
  3839. #include "std.disclaimer"
  3840. #include "go.h"
  3841. #include <pwd.h>
  3842.  
  3843. FILE *strfile;
  3844. char filename[500];
  3845. extern int strength, opponstr;
  3846. extern float wins;
  3847.  
  3848. GetStr()
  3849. {
  3850.    int id;
  3851.    struct passwd *pw;
  3852.    char *dir;
  3853.    id = geteuid();
  3854.    pw = getpwuid(id);
  3855.    dir = pw->pw_dir;
  3856.    strcpy(filename, dir);
  3857.    strcat(filename, GOFILE);
  3858.    /* fprintf(stderr,"FILENAME:%s\n",filename); */
  3859.    if ((strfile = fopen(filename, "r")) != NULL) {
  3860.       fscanf(strfile, "%d", &strength);
  3861.       fscanf(strfile, "%f", &wins);
  3862.       fclose(strfile);
  3863.    } else {
  3864.       strength = 0;
  3865.       wins = 0.0;
  3866.    }
  3867.  
  3868. }
  3869.  
  3870.  
  3871.  
  3872.  
  3873. savestr()
  3874. {
  3875.    float getdelta(), newwins;
  3876.    newwins = getdelta();
  3877.    if (newwins * wins < 0.0)
  3878.       wins = newwins;
  3879.    else
  3880.       wins += newwins;
  3881.    savestr0();
  3882. }
  3883.  
  3884. savestr0()
  3885. {
  3886.    if ((strfile = fopen(filename, "w")) != NULL) {
  3887.       if ((wins >= WINSUP && strength < MAXSTR)) {
  3888.      fprintf(strfile, "%d 0.0\n", strength + 1);
  3889.       } else if ((wins <= -WINSUP && strength > 1)) {
  3890.      fprintf(strfile, "%d 0.0\n", strength - 1);
  3891.       } else {
  3892.      fprintf(strfile, "%d %f\n", strength, wins);
  3893.       }
  3894.       fclose(strfile);
  3895.    }
  3896. }
  3897.  
  3898.  
  3899. float getdelta()
  3900. {
  3901.    if (iwon) {            /* i won */
  3902.       if (strength < opponstr)    /* i'm weaker */
  3903.      return ((opponstr - strength) / 10.0 + 1.0);
  3904.       else
  3905.      return (((strength - opponstr) > 20) ? 2.0 : 1.0);
  3906.    } else {
  3907.       if (strength < opponstr)
  3908.      return (-1.0);
  3909.       else
  3910.      return (-((strength - opponstr) / 20.0 + 1.0));
  3911.    }
  3912. }
  3913.  
  3914. showstr()
  3915. {
  3916.    GetStr();
  3917.    if (strength < 31) {
  3918.       printf("Your strength is about: %d kyu.\n", 31 - strength);
  3919.    } else if (strength < 40) {
  3920.       printf("Your strength is about: %d dan.\n", strength - 30);
  3921.    } else if (strength < MAXSTR + 1) {
  3922.       printf("Your strength is about: %d professional dan.\n", strength - 39);
  3923.    } else {
  3924.       printf("Your are at maximum strength.\n");
  3925.    }
  3926.    if (wins >= 0)
  3927.       printf("You have also won %d games in a row.\n", (int) (wins / 2.0));
  3928.    else
  3929.       printf("You have also lost %d games in a row.\n", -(int) (wins));
  3930. }
  3931. SHAR_EOF
  3932. fi
  3933. if test -f 'tick.c'
  3934. then
  3935.     echo shar: "will not over-write existing file 'tick.c'"
  3936. else
  3937. cat << \SHAR_EOF > 'tick.c'
  3938. #include "std.disclaimer"
  3939. #include "go.h"
  3940.  
  3941. DEBUG(extern FILE * debug;
  3942. )
  3943. printtimes()
  3944. {
  3945.    showtime(TRUE, &mytime);
  3946.    showtime(FALSE, &opptime);
  3947. }
  3948.  
  3949. showbyo()
  3950. {
  3951.    char buf[40];
  3952.    sprintf(buf, "Byoyomi: %d stones in %d sec", byostones, byosec);
  3953.    addmes(buf);
  3954.    if (byoextends > 0) {
  3955.       sprintf(buf, "Byoyomi may be extended %d times", byoextends);
  3956.       addmes(buf);
  3957.    }
  3958. }
  3959.  
  3960. inittick()
  3961. {
  3962.    mytime.left.tv_sec = opptime.left.tv_sec = totalmin * 60;
  3963.    mytime.left.tv_usec = opptime.left.tv_usec = 0;
  3964.    mytime.byoyomi = opptime.byoyomi = FALSE;
  3965.    printtimes();
  3966. }
  3967.  
  3968. /* compute t -= d */
  3969. static timediff(t, d)
  3970.     register struct timeval *t, *d;
  3971. {
  3972.    while (d->tv_usec > t->tv_usec) {
  3973.       t->tv_usec += 1000000;
  3974.       t->tv_sec--;
  3975.    }
  3976.    t->tv_sec -= d->tv_sec;
  3977.    t->tv_usec -= d->tv_usec;
  3978.    while (t->tv_usec > 1000000) {
  3979.       t->tv_usec -= 1000000;
  3980.       t->tv_sec++;
  3981.    }
  3982. }
  3983.  
  3984. starttick(myturn)
  3985.     bool myturn;
  3986. {
  3987.    struct timing *t = (myturn) ? &mytime : &opptime;
  3988.    struct timeval now;
  3989.    gettimeofday(&now, NULL);
  3990.    t->start = now;
  3991.  
  3992.    DEBUG(fprintf(debug, "StartTick for %d.   Remaining %d\n",
  3993.          myturn, t->left.tv_sec);
  3994.    fflush(debug);
  3995.    )
  3996. }
  3997.  
  3998. stoptick(myturn)
  3999.     bool myturn;
  4000. {
  4001.    struct timing *t = (myturn) ? &mytime : &opptime;
  4002.    struct timeval now;
  4003.    long left;
  4004.  
  4005.    if (!timedgame)
  4006.       return;
  4007.    t->stones--;
  4008.    if (t->byoyomi && t->stones <= 0) {
  4009.       /* get another packet of byoyomi stones */
  4010.       /* set time to the next larger multiple of byosec */
  4011.       for (left = 0; left <= t->left.tv_sec; left += byosec) {
  4012.       }
  4013.       t->left.tv_sec = left;
  4014.       t->left.tv_usec = 0;
  4015.       t->stones = byostones;
  4016.    } else {
  4017.       gettimeofday(&now, NULL);
  4018.       /* left -=  (now - start) */
  4019.       timediff(&now, &t->start);
  4020.       timediff(&t->left, &now);
  4021.    }
  4022.  
  4023.    showtime(myturn, t);
  4024.  
  4025.    DEBUG(fprintf(debug, "StopTick for %d.   Remaining %d\n",
  4026.          myturn, t->left.tv_sec);
  4027.    fflush(debug);
  4028.    )
  4029. }
  4030.  
  4031.  
  4032.  
  4033. tick(myturn)
  4034.     bool myturn;
  4035. {
  4036.    struct timing *t = (myturn) ? &mytime : &opptime;
  4037.    struct timeval now, temp;
  4038.  
  4039.    if (!ticking)
  4040.       return;
  4041.    gettimeofday(&now, NULL);
  4042.  
  4043.    temp = now;
  4044.    /* left -=  (now - start) */
  4045.    timediff(&now, &t->start);
  4046.    timediff(&t->left, &now);
  4047.    t->start = temp;
  4048.  
  4049.    if (t->left.tv_sec < 0) {
  4050.       /* OOPS out of time */
  4051.       if (t->byoyomi) {
  4052.      if (myturn) {
  4053.         /* SIGH.  lost by running out of time */
  4054.         SEND(MTIMELOSE);
  4055.         dodecided(TRUE,
  4056.               "Your clock ran out.",
  4057.               "\nYou lost by exceeding time limit\n");
  4058.      }
  4059.       } else {
  4060.      t->byoyomi = TRUE;
  4061.      Beep();
  4062.      homemes();
  4063.      addmes("- You are in byoyomi.");
  4064.      t->extends = byoextends;
  4065.      t->left.tv_sec = byosec * (t->extends + 1);
  4066.      t->left.tv_usec = 0;
  4067.      t->stones = byostones;
  4068.       }
  4069.    }
  4070.    showtime(myturn, t);
  4071. }
  4072.  
  4073.  
  4074. dosettiming()
  4075. {
  4076.    if (!getint("Minutes per player [untimed]: ", &totalmin) || totalmin == 0) {
  4077.       timedgame = FALSE;
  4078.       SEND(MSETTIME);
  4079.       sendint(0);
  4080.       printtimes();
  4081.       return;
  4082.    }
  4083.    timedgame = TRUE;
  4084.    if (!getint("Stones / byoyomi period [20]: ", &byostones))
  4085.       byostones = 20;
  4086.    if (!getint("Seconds / byoyomi period [400]: ", &byosec))
  4087.       byosec = 400;
  4088.    if (!getint("Byoyomi timeouts allowed [0]: ", &byoextends))
  4089.       byoextends = 0;
  4090.    sendtimestart();
  4091. }
  4092.  
  4093. sendtimestart()
  4094. {
  4095.    SEND(MSETTIME);
  4096.    sendint(totalmin);
  4097.    SEND(MSETBYO);
  4098.    sendint(byosec);
  4099.    sendint(byostones);
  4100.    sendint(byoextends);
  4101.    showbyo();
  4102.    inittick();
  4103. }
  4104.  
  4105.  
  4106.  
  4107. static void tmesg(who, t)
  4108.     char *who;
  4109.     struct timing *t;
  4110. {
  4111.    long secs;
  4112.    char buf[50];
  4113.    secs = t->left.tv_sec;
  4114.    if (t->byoyomi)
  4115.       sprintf(buf, "%s clock %d:%02d:%02d for %d stones",
  4116.           who, secs / 3600, (secs % 3600) / 60, secs % 60, t->stones);
  4117.    else
  4118.       sprintf(buf, "%s clock %d:%02d:%02d",
  4119.           who, secs / 3600, (secs % 3600) / 60, secs % 60);
  4120.    SEND(MMESSAGE);
  4121.    SEND(buf);
  4122. }
  4123.  
  4124. sendtimemesg()
  4125. {
  4126.    long secs, y;
  4127.    char buf[50];
  4128.    y = opptime.left.tv_sec;
  4129.    secs = mytime.left.tv_sec;
  4130.    if (opptime.byoyomi || mytime.byoyomi) {
  4131.       tmesg("Your", &opptime);
  4132.       tmesg("My", &mytime);
  4133.    } else {
  4134.       sprintf(buf, "Your clock %d:%02d:%02d   Mine %d:%02d:%02d",
  4135.           y / 3600, (y % 3600) / 60, y % 60,
  4136.           secs / 3600, (secs % 3600) / 60, secs % 60);
  4137.       SEND(MMESSAGE);
  4138.       SEND(buf);
  4139.    }
  4140. }
  4141.  
  4142.  
  4143. /* To really provide a pause-clock option we need to provide it as primitives
  4144.  * in tick.c.  After the changes listed below, the clock is paused with
  4145.  * pausetick(myturn) and restarted with resumetick(myturn) (Probably need to
  4146.  * add SEND messages so the opponent can be synchronized.) */
  4147.  
  4148.  
  4149. pausetick(myturn)
  4150.     bool myturn;
  4151. {
  4152.    struct timing *t = (myturn) ? &mytime : &opptime;
  4153.    struct timeval now;
  4154.    gettimeofday(&now, NULL);
  4155.  
  4156.    /* left -=  (now - start) */
  4157.    timediff(&now, &t->start);
  4158.    timediff(&t->left, &now);
  4159.    ticking = FALSE;
  4160. }
  4161.  
  4162.  
  4163. resumetick(myturn)
  4164.     bool myturn;
  4165. {
  4166.    struct timing *t = (myturn) ? &mytime : &opptime;
  4167.    struct timeval now;
  4168.    gettimeofday(&now, NULL);
  4169.    t->start = now;
  4170.    ticking = TRUE;
  4171. }
  4172. SHAR_EOF
  4173. fi
  4174. if test -f 'traps.c'
  4175. then
  4176.     echo shar: "will not over-write existing file 'traps.c'"
  4177. else
  4178. cat << \SHAR_EOF > 'traps.c'
  4179. #include "std.disclaimer"
  4180. #include "go.h"
  4181. #include <signal.h>
  4182. #include <curses.h>
  4183.  
  4184. trap_sigint()
  4185. {
  4186.    char c;
  4187.    extern char waiting;
  4188.  
  4189.    signal(SIGINT, SIG_IGN);
  4190.    if (waiting) {
  4191.       CLEAR();
  4192.       Exit();
  4193.    }
  4194.    clear();
  4195.    mvaddstr(22, 1, "Quit (y/n)?");
  4196.    refresh();
  4197.    c = GetAKey0();
  4198.    while (c != 'n' && c != 'N' && c != 'y' && c != 'Y') {
  4199.       if (c == '\f')
  4200.      refresh();
  4201.       c = GetAKey();
  4202.    }
  4203.    if (c == 'y') {
  4204.       SEND(MEXIT);
  4205.       CLEAR();
  4206.       Exit();
  4207.    }
  4208.    touchwin(stdscr);
  4209.    PrintBoard(&board);
  4210.  
  4211.    signal(SIGINT, trap_sigint);
  4212. }
  4213.  
  4214.  
  4215. /* set up all the core dump signal vectors to the signal handler given */
  4216.  
  4217. setcore(f)
  4218.     int (*f) ();
  4219. {
  4220.    signal(SIGQUIT, f);
  4221.    signal(SIGILL, f);
  4222.    signal(SIGTRAP, f);
  4223.    signal(SIGIOT, f);
  4224.    signal(SIGEMT, f);
  4225.    signal(SIGFPE, f);
  4226.    signal(SIGBUS, f);
  4227.    signal(SIGSEGV, f);
  4228.    signal(SIGSYS, f);
  4229. }
  4230.  
  4231. /* very fatal error occured twice.  Time to die. We have been surrounded :) */
  4232.  
  4233. trap_cdumpII()
  4234. {
  4235.    setcore(SIG_IGN);
  4236.    fprintf(stderr, "Save failed! Fatal error! Committing processide...\n");
  4237.    exit(666);
  4238. }
  4239.  
  4240. /* The first core dump signal goes here, then to cdumpII The first signal
  4241.  * attempts to save the game and leave cleanly. the second version just dies :( */
  4242.  
  4243. trap_cdump()
  4244. {
  4245.    int trap_cdumpII();
  4246.    setcore(trap_cdumpII);
  4247.    fprintf(stderr, "core dump attempted- attempting save...\n");
  4248.    savegame();
  4249.    fprintf(stderr, "save successful.\n\n");
  4250.    Exit();
  4251. }
  4252. SHAR_EOF
  4253. fi
  4254. if test -f 'var.c'
  4255. then
  4256.     echo shar: "will not over-write existing file 'var.c'"
  4257. else
  4258. cat << \SHAR_EOF > 'var.c'
  4259. #include "std.disclaimer"
  4260. #include <sys/file.h>
  4261. #include "go.h"
  4262.  
  4263. BOARD backup, board, marks;
  4264.  
  4265. int handin, handicaps = 0,    /* handicap indentation */
  4266.    dimensions, myport, cx = 0, cy = 0, curplr = 0, hama[2] =
  4267. {0, 0}, MAXX, MAXY, beepflg, disable = 0, status, sock, sockmask[2], myturn,
  4268.    player, iwon, opponstr, strength, loadflg, logflg, usemess, inverse, totalmin = 60,
  4269.    byosec = 400, byostones = 20, byoextends = 0;
  4270.  
  4271. float wins;
  4272.  
  4273. char loadname[128], logname[128], *myname, *hisname, ticking = TRUE, opphastiming = FALSE,
  4274.    timedgame = FALSE, buf[MAXBUF], pieces[] =
  4275. {
  4276.    '.' + INVERSE,
  4277.    BLACK + INVERSE,
  4278.    'O' + INVERSE,
  4279.    '=' + INVERSE,
  4280.    '+' + INVERSE,
  4281.    '-' + INVERSE
  4282. };
  4283.  
  4284. FILE *logfile;
  4285.  
  4286. struct timing mytime =
  4287. {
  4288.    {3600, 0}, FALSE, 0, 0}, opptime =
  4289. {
  4290.    {3600, 0}, FALSE, 0, 0};
  4291.  
  4292.  
  4293. char waiting=1;
  4294. SHAR_EOF
  4295. fi
  4296. if test -f 'go.h'
  4297. then
  4298.     echo shar: "will not over-write existing file 'go.h'"
  4299. else
  4300. cat << \SHAR_EOF > 'go.h'
  4301. #include "std.disclaimer"
  4302. #include <sys/types.h>
  4303. #include <sys/socket.h>
  4304. #include <sys/time.h>
  4305. #include <errno.h>
  4306. #include <stdio.h>
  4307.  
  4308.  
  4309. #define bool char
  4310.  
  4311. #define TRUE (1)
  4312. #define FALSE (0)
  4313.  
  4314.  
  4315. /* keep the following in synch with table in doother.c */
  4316.  
  4317. #define MSCORE        "SCORE"
  4318. #define MQUIT        "QUIT"
  4319. #define MACCEPT        "ACCEPT"
  4320. #define MEXIT        "EXIT"
  4321. #define MDECLINE        "DECLINE"
  4322. #define MCANCEL        "CANCEL"
  4323. #define MPLAY        "PLAY"
  4324. #define MMOVE        "MOVE"
  4325. #define MLOAD        "LOAD"
  4326. #define MDELETE        "DELETE"
  4327. #define MCLEAR        "CLEAR"
  4328. #define MPASS        "PASS"
  4329. #define MMESSAGE    "MESSAGE"
  4330. #define MHANDICAP    "HANDICAP"
  4331. #define MSWITCH        "SWITCH"
  4332. #define MRESIGN        "RESIGN"
  4333. #define MTIME        "TIME"
  4334. #define MSETTIME        "SETTIME"
  4335. #define MSETBYO        "SETBYO"
  4336. #define MTIMELOSE    "TIMELOSE"
  4337. #define MPAUSE    "PAUSE"
  4338.  
  4339. #define MSIZE        "SIZE"
  4340. #define MHAND        "HANDI"
  4341. #define MSTR        "STREN"
  4342. #define MMODE        "MODE"
  4343.  
  4344. #define AreWe(s) (status & s)
  4345. #define SetStat(s) status=status | s;
  4346. #define ClrStat(s) status=status & ~s;
  4347. #define    HELP_CMD "/usr/ucb/more /usr/public/go.doc"
  4348.  
  4349. #define MAXDIM 19        /* maximum dimension */
  4350. #define MINDIM 9        /* minimum board dimension */
  4351. #define DEFAULTPORT 525        /* default port to connect with */
  4352.  
  4353. #define GOFILE "/.go_strength"    /* information on player's strength */
  4354. #define DEFAULTSTR 1        /* default strength if never played */
  4355. #define MAXSTR 48        /* count from 1... maxstr */
  4356. #define WINSUP 6        /* how many wins (losses) in a row are needed to
  4357. * go up a rank if you are weaker than
  4358. * the other player. */
  4359. #define KOMI    5.5        /* standard komi- add to white at end of game */
  4360.  
  4361.  
  4362. #define FD_INPUT   0
  4363. #define C_NOTHING  0
  4364. #define C_REDRAW   1
  4365. #define C_INVERSE  2
  4366. #define C_SAVE     3
  4367. #define C_LOAD     4
  4368. #define C_QUIT     5
  4369. #define C_TALLY    6
  4370. #define C_CANCEL   7
  4371. #define C_CLEAR    8
  4372. #define C_MESSAGE  9
  4373. #define C_RESIGN   10
  4374. #define C_SWITCH   11
  4375. #define C_LAST     12
  4376. #define C_PASS     13
  4377. #define C_HELP     14
  4378. #define C_SETBLACK 15
  4379. #define C_SETWHITE 16
  4380. #define C_PLAY   17
  4381. #define C_SETTIME  18
  4382. #define C_SETHAND  19
  4383. #define C_PAUSE    20
  4384. #define C_PANIC    21
  4385.  
  4386. #define P1 1            /* board types - player 1 pieces */
  4387. #define P2 2            /* player 2 pieces */
  4388. #define NONE 0            /* nothing */
  4389. #define MARK 3            /* neutral/marks for searches */
  4390.  
  4391.  
  4392. #define FASTMOVE 3        /* speed with <shift><dir> */
  4393. #define REDRAW '\014'        /* ^l */
  4394. #define MAXBUF 200        /* maximum line buffer */
  4395.  
  4396. #define DEBUG(m)
  4397.  
  4398. #define WHEN break; case
  4399. #define OTHERWISE break; default
  4400.  
  4401. #define UNSET 2
  4402.  
  4403.  
  4404. #define error(x) { fprintf(stderr,x); testsave(); Exit(); }
  4405.  
  4406. typedef struct { 
  4407.     char d[MAXDIM][MAXDIM]; 
  4408. BOARD;
  4409. #define b(x1,y1) board.d[x1][y1]    /* JOE CODE- lazy hack. */
  4410. #define m(x2,y2) marks.d[x2][y2]    /* my apologies */
  4411.  
  4412. #define HITAKEYMES "[Hit any key]"
  4413.  
  4414. #define SCORE        0x01        /* state values */
  4415. #define EXIT        0x02
  4416. #define PLAY        0x04
  4417. #define HANDICAP    0x08
  4418. #define PAUSED    0x10
  4419.  
  4420. extern int parm;
  4421. extern bool haveparm;
  4422.  
  4423. extern struct timing {
  4424.     struct timeval start;
  4425.     struct timeval left;
  4426.     bool byoyomi;
  4427.     int stones;
  4428.     int extends;
  4429. } mytime, opptime;
  4430.  
  4431. extern int totalmin, byosec, byostones, byoextends;
  4432. extern bool opphastiming, timedgame;
  4433. extern BOARD backup,board,marks;
  4434. extern int curplr,hama[],MAXX,MAXY,cx,cy;
  4435. extern int disable,myturn,sock,sockmask[],status,player,dimensions;
  4436. extern char *blanks;
  4437. extern char pieces[], buf[], ticking;
  4438. extern bool iamserver;
  4439. extern int iwon;
  4440.  
  4441.  
  4442. SHAR_EOF
  4443. fi
  4444. if test -f 'std.disclaimer'
  4445. then
  4446.     echo shar: "will not over-write existing file 'std.disclaimer'"
  4447. else
  4448. cat << \SHAR_EOF > 'std.disclaimer'
  4449.  
  4450. SHAR_EOF
  4451. fi
  4452. exit 0
  4453. #    End of shell archive
  4454.