home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1994 March / Source_Code_CD-ROM_Walnut_Creek_March_1994.iso / compsrcs / games / vmsnet / ldb / part11 < prev    next >
Internet Message Format  |  1993-04-07  |  49KB

  1. Path: uunet!zaphod.mps.ohio-state.edu!usc!news.service.uci.edu!unogate!mvb.saic.com!dayton.saic.com!dayvd.dayton.saic.com!ake
  2. From: ake@dayvd.dayton.saic.com (Earle Ake)
  3. Newsgroups: vmsnet.sources.games
  4. Subject: ldb - Long Distance Backgammon [11/16]
  5. Date: 8 Apr 93 11:00:49 EST
  6. Organization: Science Applications Intl Corp - Dayton, OH
  7. Lines: 1317
  8. Message-ID: <1993Apr8.110049.1@dayvd.dayton.saic.com>
  9. NNTP-Posting-Host: dayvd.dayton.saic.com
  10. Xref: uunet vmsnet.sources.games:672
  11.  
  12. -+-+-+-+-+-+-+-+ START OF PART 11 -+-+-+-+-+-+-+-+
  13. X`09j`20=`20optlookup(`26argv`5Bi`5D`5B1`5D);
  14. X`09if`20(j`20==`20-2)`20`7B
  15. X`09`09printf("%s:`5Ctambiguous`20option:`20%s`5Cn`5Cn",*argv,argv`5Bi`5D);
  16. X`09`09usage(0);`09`09/*`20print`20short`20help`20*/
  17. X`09`09ldbexit(STAT_ABORT);
  18. X`09`09`7D
  19. X`09if`20(j`20<`200)`20`7B
  20. X`09`09printf("%s:`5Ctunrecognized`20option:`20%s`5Cn`5Cn",*argv,argv`5Bi`5D);
  21. X`09`09usage(0);`09`09/*`20print`20short`20help`20*/
  22. X`09`09ldbexit(STAT_ABORT);
  23. X`09`09`7D
  24. X`09switch`20(options`5Bj`5D.index)`20`7B
  25. X`09case`20OPT_START:`09`09`09/*`20start`20a`20game`20*/
  26. X`09`09i++;
  27. X`09`09if`20(argv`5Bi`5D`20==`20NULL)`20`7B
  28. X`09`09`09printf("%s:`20-start`20needs`20argument`5Cn",*argv);
  29. X`09`09`09usage(0);
  30. X`09`09`09ldbexit(STAT_ABORT);
  31. X`09`09`09`7D
  32. X`09`09if`20(start_addr`20!=`20NULL)`20`7B
  33. X`09`09`09printf("%s:`20only`20one`20-start`20allowed.`5Cn",*argv);
  34. X`09`09`09usage(0);
  35. X`09`09`09ldbexit(STAT_ABORT);
  36. X`09`09`09`7D
  37. X`09`09start_addr`20=`20argv`5Bi`5D;
  38. X`09`09break;
  39. X`09case`20OPT_RSTART:`09`09/*`20remote`20start`20*/
  40. X`09`09i++;
  41. X`09`09if`20(`20(argv`5Bi`5D`20==`20NULL)`20`7C`7C`20(argv`5Bi+1`5D`20==`20NULL
  42. V)`20)`20`7B
  43. X`09`09`09printf("%s:`20-remotestart`20needs`20two`20arguments`5Cn",*argv);
  44. X`09`09`09usage(0);
  45. X`09`09`09ldbexit(STAT_ABORT);
  46. X`09`09`09`7D
  47. X`09`09if`20(rst1`20!=`20NULL)`20`7B
  48. X`09`09`09printf("%s:`20only`20one`20-remotestart`20allowed.`5Cn",*argv);
  49. X`09`09`09usage(0);
  50. X`09`09`09ldbexit(STAT_ABORT);
  51. X`09`09`09`7D
  52. X`09`09rst1`20=`20argv`5Bi`5D;
  53. X`09`09rst2`20=`20argv`5Bi+1`5D;
  54. X`09`09i++;
  55. X`09`09break;
  56. X`09case`20OPT_READ:
  57. X`09`09Pflag`20=`200;`09`09/*`20just`20read,`20no`20processing`20*/
  58. X`09`09break;
  59. X`09case`20OPT_PLAY:
  60. X`09`09Rflag`20=`200;`09`09/*`20just`20process,`20no`20read`20*/
  61. X`09`09break;
  62. X`09case`20OPT_MYADDR:`09`09/*`20set`20my`20e-mail`20address`20*/
  63. X`09`09i++;
  64. X`09`09if`20(argv`5Bi`5D`20==`20NULL)`20`7B
  65. X`09`09`09printf("%s:`20-myaddr`20needs`20argument`5Cn",*argv);
  66. X`09`09`09usage(0);
  67. X`09`09`09ldbexit(STAT_ABORT);
  68. X`09`09`09`7D
  69. X`09`09strcpy(rc.myaddr,argv`5Bi`5D);`09/*`20copy`20in`20new`20address`20*/
  70. X`09`09break;
  71. X`09case`20OPT_HELP:`09`09`09/*`20print`20long`20help`20*/
  72. X`09`09usage(1);
  73. X`09`09ldbexit(STAT_NORM);
  74. X`09case`20OPT_NOTIFY:
  75. X`09`09i++;
  76. X`09`09if`20(argv`5Bi`5D`20==`20NULL)`20`7B
  77. X`09`09`09printf("%s:`20-notify`20needs`20argument`5Cn",*argv);
  78. X`09`09`09usage(0);
  79. X`09`09`09ldbexit(STAT_ABORT);
  80. X`09`09`09`7D
  81. X`09`09notify`20=`20argv`5Bi`5D;
  82. X`09`09break;
  83. X`09case`20OPT_COLOR:`09`09`09/*`20set`20colors`20*/
  84. X`09`09if`20(argv`5B++i`5D`20==`20NULL)`20`7B
  85. X`09`09`09printf("%s:`20-color`20option`20needs`20argument`5Cn",*argv);
  86. X`09`09`09usage(0);
  87. X`09`09`09ldbexit(STAT_ABORT);
  88. X`09`09`09`7D
  89. X`09`09cr_mycolor`20=`20argv`5Bi`5D`5B0`5D;`09/*`20first`20char`20is`20my`20col
  90. Vor`20*/
  91. X`09`09cr_opcolor`20=`20argv`5Bi`5D`5B1`5D;`20/*`20second`20char`20is`20opponen
  92. Vt's`20color`20*/
  93. X`09`09if`20(`20(!`20isprint(cr_mycolor))`20`7C`7C`20(cr_mycolor`20==`20'`20')
  94. V`20)`20`7B
  95. X`09`09`09printf("%s:`20invalid`20color:`20%d`5Cn",*argv,cr_mycolor);
  96. X`09`09`09usage(0);
  97. X`09`09`09ldbexit(STAT_ABORT);
  98. X`09`09`09`7D
  99. X`09`09if`20(`20(!`20isprint(cr_opcolor))`20`7C`7C`20(cr_opcolor`20==`20'`20')
  100. V`20)`20`7B
  101. X`09`09`09printf("%s:`20invalid`20color:`20%d`5Cn",*argv,cr_opcolor);
  102. X`09`09`09usage(0);
  103. X`09`09`09ldbexit(STAT_ABORT);
  104. X`09`09`09`7D
  105. X`09`09c`20=`20cr_mycolor;
  106. X`09`09if`20(isupper(c))
  107. X`09`09`09c`20=`20tolower(c);
  108. X`09`09c2`20=`20cr_opcolor;
  109. X`09`09if`20(isupper(c2))
  110. X`09`09`09c2`20=`20tolower(c2);
  111. X`09`09if`20(c`20==`20c2)`20`7B
  112. X`09`09`09printf("%s:`20duplicate`20color:`20%c`5Cn",*argv,cr_mycolor);
  113. X`09`09`09usage(0);
  114. X`09`09`09ldbexit(STAT_ABORT);
  115. X`09`09`09`7D
  116. X`09`09break;
  117. X`09case`20OPT_DIRECTION:`09`09/*`20set`20direction`20*/
  118. X`09`09if`20(argv`5B++i`5D`20==`20NULL)`20`7B
  119. X`09`09`09printf("%s:`20-direction`20option`20needs`20argument`5Cn",*argv);
  120. X`09`09`09usage(0);
  121. X`09`09`09ldbexit(STAT_ABORT);
  122. X`09`09`09`7D
  123. X`09`09c`20=`20argv`5Bi`5D`5B0`5D;
  124. X`09`09if`20(isupper(c))
  125. X`09`09`09c`20=`20tolower(c);
  126. X`09`09if`20(c`20==`20'u')
  127. X`09`09`09cr_mydir`20=`201;`09`09/*`20I`20play`20up`20*/
  128. X`09`09else`20if`20(c`20==`20'd')
  129. X`09`09`09cr_mydir`20=`20-1;`09`09/*`20I`20play`20down`20*/
  130. X`09`09else`20`7B
  131. X`09`09`09printf("%s:`20invalid`20direction:`20%s`5Cn",*argv,argv`5Bi`5D);
  132. X`09`09`09usage(0);
  133. X`09`09`09ldbexit(STAT_ABORT);
  134. X`09`09`09`7D
  135. X`09`09break;
  136. X`09case`20OPT_JACOBY:
  137. X`09`09flags`20`7C=`20F_JACOBY;
  138. X`09`09break;
  139. X`09case`20OPT_CRAWFORD:
  140. X`09`09flags`20`7C=`20F_CRAWFORD;
  141. X`09`09break;
  142. X`09case`20OPT_EUROPE:
  143. X`09`09flags`20`7C=`20F_EUROPE;
  144. X`09`09break;
  145. X`09case`20OPT_PERM:
  146. X`09`09flags`20`7C=`20F_PERM;
  147. X`09`09break;
  148. X`09case`20OPT_MATCH:
  149. X`09`09if`20(argv`5B++i`5D`20==`20NULL)`20`7B
  150. X`09`09`09printf("%s:`20-match`20option`20needs`20argument`5Cn",*argv);
  151. X`09`09`09usage(0);
  152. X`09`09`09ldbexit(STAT_ABORT);
  153. X`09`09`09`7D
  154. X`09`09if`20(!`20isdigit(*argv`5Bi`5D))`20`7B
  155. X`09`09`09printf("%s:`20-match`20needs`20numeric`20argument`5Cn",*argv);
  156. X`09`09`09usage(0);
  157. X`09`09`09ldbexit(STAT_ABORT);
  158. X`09`09`09`7D
  159. X`09`09match`20=`20atoi(argv`5Bi`5D);
  160. X`09`09break;
  161. X`09case`20OPT_SCORE:
  162. X`09`09if`20(start_addr`20!=`20NULL)
  163. X`09`09`09printf("warning:`20-start`20not`20processed.`5Cn");
  164. X`09`09if`20(rst1`20!=`20NULL)
  165. X`09`09`09printf("warning:`20-remotestart`20not`20processed.`5Cn");
  166. X`09`09printscore();
  167. X`09`09ldbexit(STAT_NORM);
  168. X`09case`20OPT_BCAST:`09`09`09`09/*`20broadcast`20a`20message`20*/
  169. X`09`09if`20(argv`5B++i`5D`20==`20NULL)`20`7B`09/*`20no`20arg,`20read`20stdin
  170. V`20*/
  171. X`09`09`09if`20(`20(fp`20=`20fopen(rc.tempfile,"w"))`20==`20NULL)`20`7B
  172. X`09`09`09`09printf("%s:`20can't`20write`20temp`20file`20%s`5Cn",
  173. X`09`09`09`09`09*argv,rc.tempfile);
  174. X`09`09`09`09ldbexit(STAT_ABORT);
  175. X`09`09`09`09`7D
  176. X`09`09`09while`20(fgets(subj,sizeof(subj),stdin)`20!=`20NULL)
  177. X`09`09`09`09fputs(subj,fp);
  178. X`09`09`09fclose(fp);
  179. X`09`09`09bcfile`20=`20rc.tempfile;
  180. X`09`09`09`7D
  181. X`09`09else
  182. X`09`09`09bcfile`20=`20argv`5Bi`5D;`09/*`20just`20read`20named`20file`20*/
  183. X`09`09sprintf(subj,"LDB`20Broadcast`20Message`20from`20%s",rc.myname);
  184. X`09`09for`20(p`20=`20phead;`20p`20!=`20NULL;`20p`20=`20p->next)`09`7B`20/*`20f
  185. Vor`20all`20people`20*/
  186. X`09`09`09if`20(p->equiv`20!=`20NULL)`09/*`20it's`20an`20equiv`20record`20*/
  187. X`09`09`09`09continue;`09/*`20skip`20it`20*/
  188. X`09`09`09for`20(g`20=`20ghead;`20g`20!=`20NULL;`20g`20=`20g->next)`09/*`20cur
  189. V`20opp?`20*/
  190. X`09`09`09`09if`20(strcmp(g->opaddr,p->addr)`20==`200)
  191. X`09`09`09`09`09break;
  192. X`09`09`09if`20(g`20==`20NULL)`09/*`20not`20a`20current`20opponent`20*/
  193. X`09`09`09`09continue;`09/*`20skip`20it`20*/
  194. X`09`09`09TSendFile(p->addr,bcfile,subj);`20/*`20send`20msg`20*/
  195. X`09`09`09`7D
  196. X`09`09break;
  197. X`09case`20OPT_CONTROL:`09`09`09/*`20control`20my`20games`20*/
  198. X`09`09control();
  199. X`09`09if`20(start_addr`20!=`20NULL)
  200. X`09`09`09printf("warning:`20-start`20not`20processed.`5Cn");
  201. X`09`09if`20(rst1`20!=`20NULL)
  202. X`09`09`09printf("warning:`20-remotestart`20not`20processed.`5Cn");
  203. X`09`09ldbexit(STAT_NORM);
  204. X`09case`20OPT_RECONS:`09`09`09/*`20reconstruct`20a`20game`20*/
  205. X`09`09if`20(argv`5B++i`5D`20==`20NULL)`20`7B
  206. X`09`09`09printf("%s:`20-reconstruct`20option`20needs`20argument`5Cn",
  207. X`09`09`09`09*argv);
  208. X`09`09`09usage(0);
  209. X`09`09`09ldbexit(STAT_ABORT);
  210. X`09`09`09`7D
  211. X`09`09recons(argv`5Bi`5D);
  212. X`09`09if`20(start_addr`20!=`20NULL)
  213. X`09`09`09printf("warning:`20-start`20not`20processed.`5Cn");
  214. X`09`09if`20(rst1`20!=`20NULL)
  215. X`09`09`09printf("warning:`20-remotestart`20not`20processed.`5Cn");
  216. X`09`09ldbexit(STAT_NORM);
  217. X`09default:
  218. X`09`09fprintf(stderr,
  219. X`09`09`20`20`20"Sorry,`20the`20%s`20option`20is`20not`20implemented`20yet.`5Cn
  220. V",
  221. X`09`09`09options`5Bj`5D.name);
  222. X`09`09ldbexit(STAT_ABORT);
  223. X`09`09`7D
  224. X`09`7D
  225. X
  226. Xif`20(start_addr`20!=`20NULL)
  227. X`09startgame(start_addr,cr_mydir,cr_mycolor,cr_opcolor,flags,match,0);
  228. Xif`20(rst1`20!=`20NULL)
  229. X`09remotestart(rst1,rst2,flags,match);
  230. X
  231. Xif`20(`20(Pflag`20==`200)`20`26`26`20(Rflag`20==`200)`20)`20`7B`09/*`20user
  232. V`20gave`20both`20-play`20and`20-read`20*/
  233. X`09Pflag`20=`201;`09`09`09/*`20turn`20both`20back`20on`20*/
  234. X`09Rflag`20=`201;
  235. X`09`7D
  236. Xwhile`20(i`20<`20argc)`09`09/*`20if`20files`20given`20on`20command`20line,`20r
  237. Vead`20them`20*/
  238. X`09readmail(argv`5Bi++`5D);
  239. Xif`20(Rflag)`09`09`09/*`20if`20we`20are`20supposed`20to`20read`20default`20fil
  240. Ve`20*/
  241. X`09readmail(rc.mfile);`09/*`20do`20that`20too`20*/
  242. Xi`20=`200;
  243. Xfor`20(g`20=`20ghead;`20g`20!=`20NULL;`20g`20=`20g->next)`09`7B`20/*`20does
  244. V`20any`20game`20need`20our`20input?`20*/
  245. X`09check_timeout(g);`09/*`20check`20for`20access`20timeouts`20*/
  246. X`09if`20(`20(g->state`20>=`20OPSTATES)`20`26`26
  247. X`09`20`20`20`20`20!`20(`20(g->state`20==`20ST_GAMEOVER)`20`26`26`20(g->flags
  248. V`20`26`20F_DISPLAYED)`20)`20)
  249. X`09`09i++;
  250. X`09`7D
  251. Xif`20(`20(i`20==`200)`20`7C`7C`20(Pflag`20==`200)`20)`20`7B`09`09/*`20if`20not
  252. V,`20exit`20*/
  253. X`09writegames(rc.gfile,rc.gbackup,rc.pfile);`09/*`20save`20games`20*/
  254. X`09ldbexit(STAT_NORM);
  255. X`09`7D
  256. XTInitialize();`09`09`09`09`09/*`20fire`20up`20the`20transport`20*/
  257. XFeInitialize();`09`09`09`09`09/*`20fire`20up`20the`20front`20end`20*/
  258. XFeDrawScreen();`09`09`09`09/*`20draw`20the`20screen`20outline`20*/
  259. Xfor`20(g`20=`20ghead,`20done`20=`200;`20(g`20!=`20NULL)`20`26`26`20(done`20>=
  260. V`200);`20g`20=`20g->next)
  261. X`09while`20(`20(done`20=`20process(g))`20>`200);`09/*`20process`20game`20til
  262. V`20done`20*/
  263. XFeFinishSession();`09`09`09`09/*`20close`20down`20the`20front`20end`20*/
  264. XTFinishSession();`09`09`09`09/*`20close`20down`20the`20transport`20*/
  265. Xwritegames(rc.gfile,rc.gbackup,rc.pfile);`09/*`20save`20the`20games`20in`20a
  266. V`20file`20*/
  267. Xldbexit(STAT_NORM);
  268. X`7D
  269. X
  270. X
  271. X/*----------------------------------------------------------------------
  272. X`20*`09ldbsignal`20--`20signal`20handler
  273. X`20*
  274. X`20*`20This`20function`20is`20called`20when`20the`20user`20hits`20the`20interr
  275. Vupt`20character.
  276. X`20*`20It`20is`20currently`20a`20very`20simple`20function;`20it`20saves`20the
  277. V`20games`20in`20the
  278. X`20*`20INTGFILE`20file,`20closes`20down`20the`20front`20end`20and`20the`20tran
  279. Vsport,`20and`20exits.
  280. X`20*----------------------------------------------------------------------
  281. X`20*/
  282. X
  283. Xldbsignal()
  284. X`7B
  285. X
  286. Xwritegames(INTGFILE,NULL,INTPFILE);
  287. XFeFinishSession();`09/*`20let`20front-end`20close`20down`20gracefully`20*/
  288. XTFinishSession();`09/*`20let`20transport`20close`20down`20gracefully`20*/
  289. Xfprintf(stderr,"WARNING:`20games`20saved`20in`20%s`20and`20%s`5Cn",INTGFILE,IN
  290. VTPFILE);
  291. Xldbexit(STAT_ABORT);
  292. X`7D
  293. X
  294. X
  295. X/*----------------------------------------------------------------------
  296. X`20*`09usage`20--`20print`20command`20line`20options.
  297. X`20*
  298. X`20*`20This`20function`20prints`20a`20help`20message.`20`20This`20can`20be`20e
  299. Vither`20in`20the
  300. X`20*`20short`20or`20long`20format.`20`20The`20short`20format`20merely`20lists
  301. V`20all`20options
  302. X`20*`20in`20a`20very`20dense`20format.`20`20The`20long`20format`20prints`20eac
  303. Vh`20option`20on
  304. X`20*`20a`20separate`20line,`20along`20with`20a`20short`20explanation`20of`20it
  305. Vs`20purpose.
  306. X`20*----------------------------------------------------------------------
  307. X`20*/
  308. X
  309. Xusage(help)
  310. Xint`20help;`09`09/*`200`20=`20short`20message,`201`20=`20long`20message`20*/
  311. X`7B
  312. Xstruct`20opt`20*o;
  313. Xint`20l;
  314. X
  315. Xprintf("options:`5Cn");
  316. Xif`20(help)`20`7B`09`09/*`20print`20out`20the`20whole`20shootin'`20match`20*/
  317. X`09for`20(o`20=`20options;`20o->name`20!=`20NULL;`20o++)
  318. X`09`09printf("`5Ct-%s%s%s`5Cn",o->name,o->args,o->help);
  319. X#if`20PATCHLEVEL`20==`200
  320. X`09printf("`5CnLdb`20version`20%d.%d`20by`20Perry`20R.`20Ross.`20`20Mail`20com
  321. Vments`5Cn",
  322. X`09`09VERSION,REVISION);
  323. X#else
  324. X`09printf(
  325. X`09"`5CnLdb`20version`20%d.%d`20(patch`20%d)`20by`20Perry`20R.`20Ross.`20`20Ma
  326. Vil`5Cncomments",
  327. X`09VERSION,REVISION,PATCHLEVEL);
  328. X#endif
  329. X`09printf("or`20suggestions`20to`20`5C"%s`5C".`5Cn",AUTHOR_EMAIL);
  330. X`09`7D
  331. Xelse`20`7B
  332. X`09l`20=`200;
  333. X`09printf("`5Ct");
  334. X`09for`20(o`20=`20options;`20o->name`20!=`20NULL;`20o++)`20`7B
  335. X`09`09if`20(`20(l`20+=`20(strlen(o->name)+strlen(o->args)+3))`20>`2055)`20`7B
  336. X`09`09`09printf("`5Cn`5Ct");
  337. X`09`09`09l`20=`200;
  338. X`09`09`09`7D
  339. X`09`09printf("`5B-%s%s`5D`20",o->name,o->args);
  340. X`09`09`7D
  341. X`09printf("`5Cn`5Cn");
  342. X`09`7D
  343. X`7D
  344. X
  345. X
  346. X/*----------------------------------------------------------------------
  347. X`20*`09remotestart`20--`20start`20a`20game`20between`20two`20other`20people
  348. X`20*
  349. X`20*`20This`20function`20tells`20a`20user`20to`20start`20a`20game`20with`20ano
  350. Vther`20user.
  351. X`20*`20Neither`20user`20needs`20to`20be`20the`20one`20running`20remotestart;
  352. V`20although
  353. X`20*`20this`20would`20work,`20-start`20is`20a`20more`20efficient`20way`20to
  354. V`20do`20that.
  355. X`20*`20Remotestart`20could`20be`20used`20to`20start`20games`20between`20oppone
  356. Vnts`20in
  357. X`20*`20a`20tournament,`20or`20to`20set`20up`20a`20pickup`20game`20facility,
  358. V`20where`20people
  359. X`20*`20wanting`20to`20play`20would`20mail`20to`20a`20central`20machine,`20whic
  360. Vh`20would
  361. X`20*`20pair`20players`20by`20some`20criteria`20(such`20as`20ability)`20and`20s
  362. Vtart`20a
  363. X`20*`20game`20between`20them.
  364. X`20*----------------------------------------------------------------------
  365. X`20*/
  366. X
  367. Xremotestart(u1,u2,flags,match)
  368. Xchar`20*u1,`20*u2;
  369. Xint`20flags;
  370. Xint`20match;
  371. X`7B
  372. Xstruct`20packet`20p;
  373. Xchar`20colors`5B4`5D;
  374. Xchar`20mbuf`5B8`5D;
  375. X
  376. Xp.version`20=`20LDB_VER;`09`09/*`20fill`20in`20a`20packet`20*/
  377. Xp.timestamp`20=`20time(`20(long`20*)0);`09/*`20give`20it`20a`20timestamp`20*/
  378. Xp.gameid`20=`20"REMOTESTART";`09/*`20give`20it`20a`20phony`20gameid`20*/
  379. Xp.opcode`20=`20RSTART;`09`09/*`20remote`20start`20opcode`20*/
  380. Xp.name`20=`20NULL;`09`09`09/*`20we`20don't`20need`20to`20send`20a`20name`20*/
  381. Xp.addr`20=`20u2;`09`09`09/*`20put`20opponent's`20address`20in`20packet`20*/
  382. Xp.comment`20=`20NULL;`09`09/*`20don't`20have`20a`20comment`20*/
  383. Xp.comment2`20=`20NULL;
  384. Xp.seq`20=`201;`09`09`09/*`20start`20with`20sequence`20number`201`20*/
  385. Xp.notify`20=`20notify;`09`09/*`20send`20notify`20address`20if`20any`20*/
  386. Xclearmvs(p.mvs);`09`09/*`20no`20moves`20to`20send`20*/
  387. Xsprintf(colors,"%c%c",cr_mycolor,cr_opcolor);
  388. Xp.colors`20=`20colors;
  389. Xp.dir`20=`20(cr_mydir`20>`200)`20?`20"up"`20:`20"down";
  390. Xp.autodbl`20=`20NULL;
  391. Xp.jacoby`20=`20(flags`20`26`20F_JACOBY)`20?`20"yes"`20:`20NULL;`09`09/*`20jaco
  392. Vby`20rule?`20*/
  393. Xp.crawford`20=`20(flags`20`26`20F_CRAWFORD)`20?`20"yes"`20:`20NULL;`09/*`20cra
  394. Vwford`20rule?`20*/
  395. Xp.european`20=`20(flags`20`26`20F_EUROPE)`20?`20"yes"`20:`20NULL;`09`09/*`20eu
  396. Vropean`20scoring?`20*/
  397. Xp.perm`20=`20(flags`20`26`20F_PERM)`20?`20"yes"`20:`20NULL;`09`09/*`20perm`20g
  398. Vame?`20*/
  399. Xif`20(match`20>`200)`20`7B`09`09/*`20match`20play`20*/
  400. X`09sprintf(mbuf,"%d",match);`09/*`20make`20it`20a`20string`20*/
  401. X`09p.match`20=`20mbuf;`09`09`09/*`20and`20put`20it`20in`20the`20packet`20*/
  402. X`09`7D
  403. Xelse
  404. X`09p.match`20=`20NULL;`09`09`09/*`20not`20a`20match,`20omit`20this`20field`20*
  405. V/
  406. Xp.gameptr`20=`20NULL;`09`09/*`20just`20in`20case`20*/
  407. XTSendPacket(`26p,u1);`09`09/*`20send`20the`20remote`20start`20command`20to`20u
  408. V1`20*/
  409. X`7D
  410. X
  411. X
  412. X/*----------------------------------------------------------------------
  413. X`20*`09optlookup`20--`20find`20command`20line`20option`20in`20options`20table
  414. X`20*
  415. X`20*`20This`20function`20looks`20up`20a`20command`20line`20switch`20in`20the
  416. V`20options`20table,
  417. X`20*`20returning`20the`20index`20into`20options`5B`5D.`20`20It`20returns`20-1
  418. V`20if`20the`20option
  419. X`20*`20was`20not`20found,`20and`20-2`20if`20the`20option`20was`20ambiguous.
  420. V`20`20Options`20may`20be
  421. X`20*`20abbreviated`20to`20the`20shortest`20unique`20substring`20of`20the`20opt
  422. Vion.
  423. X`20*----------------------------------------------------------------------
  424. X`20*/
  425. X
  426. Xoptlookup(optstr)
  427. Xchar`20*optstr;
  428. X`7B
  429. Xint`20i,`20j,`20l,`20n;
  430. X
  431. Xn`20=`200;
  432. Xif`20(`20(l`20=`20strlen(optstr))`20==`200)`09`09`09/*`20empty`20option`20stri
  433. Vng`20*/
  434. X`09return(-1);`09`09`09`09/*`20that's`20no`20good`20*/
  435. Xfor`20(i`20=`200;`20options`5Bi`5D.name`20!=`20NULL;`20i++)`09/*`20look`20for
  436. V`20arg`20*/
  437. X`09if`20(strncmp(options`5Bi`5D.name,optstr,l)`20==`200)`20`7B`09/*`20found
  438. V`20it`20*/
  439. X`09`09j`20=`20i;`09`09`09`09/*`20remember`20index`20*/
  440. X`09`09n++;`09`09`09`09/*`20count`20how`20many`20*/
  441. X`09`09`7D
  442. Xif`20(n`20==`200)`09`09`09`09`09/*`20didn't`20find`20it`20*/
  443. X`09return(-1);`09`09`09`09/*`20return`20error`20*/
  444. Xif`20(n`20>`201)`09`09`09`09`09/*`20found`20more`20than`201`20match`20*/
  445. X`09return(-2);`09`09`09`09/*`20return`20error`20*/
  446. Xreturn(j);`09`09`09`09`09/*`20return`20the`20index`20*/
  447. X`7D
  448. $ call unpack MAIN.C;1 1400802312 ""
  449. $!
  450. $ create 'f'
  451. X/*`09misc.c`09`098/8/91
  452. X`20*
  453. X`20*`20Copyright`201991`20`20Perry`20R.`20Ross
  454. X`20*
  455. X`20*`20Permission`20to`20use,`20copy,`20modify,`20and`20distribute`20this`20so
  456. Vftware`20and`20its
  457. X`20*`20documentation`20without`20fee`20is`20hereby`20granted,`20subject`20to
  458. V`20the`20restrictions
  459. X`20*`20detailed`20in`20the`20README`20file,`20which`20is`20included`20here`20b
  460. Vy`20reference.
  461. X`20*`20Any`20other`20use`20requires`20written`20permission`20from`20the`20auth
  462. Vor.`20`20This`20software
  463. X`20*`20is`20distributed`20"as`20is"`20without`20any`20warranty,`20including
  464. V`20any`20implied
  465. X`20*`20warranties`20of`20merchantability`20or`20fitness`20for`20a`20particular
  466. V`20purpose.
  467. X`20*`20The`20author`20shall`20not`20be`20liable`20for`20any`20damages`20result
  468. Ving`20from`20the
  469. X`20*`20use`20of`20this`20software.`20`20By`20using`20this`20software,`20the
  470. V`20user`20agrees
  471. X`20*`20to`20these`20terms.
  472. X`20*/
  473. X
  474. X#include`20"ldb.h"
  475. X
  476. X
  477. X/*----------------------------------------------------------------------
  478. X`20*`09rolldice`20--`20roll`20two`20dice
  479. X`20*
  480. X`20*`20This`20function`20calls`20Rolldie`20twice`20and`20fills`20in`20the`20ga
  481. Vme`20structure
  482. X`20*`20with`20the`20resulting`20values.`20`20If`20the`20two`20calls`20to`20Rol
  483. Vldie`20return`20the
  484. X`20*`20same`20number,`20the`20mvs`20field`20is`20filled`20in`20so`20that`20the
  485. V`20user`20has`204`20rolls
  486. X`20*`20to`20use,`20otherwise`20the`20rolls`20are`20stored`20in`20the`20first
  487. V`20two`20elements
  488. X`20*`20of`20the`20mvs`20field`20and`20the`20last`20two`20are`20marked`20unused
  489. V.
  490. X`20*----------------------------------------------------------------------
  491. X`20*/
  492. X
  493. Xrolldice(g)
  494. Xstruct`20game`20*g;
  495. X`7B
  496. X
  497. Xclearmvs(g->mvs);`09`09`09/*`20clear`20old`20stuff`20*/
  498. Xg->mvs`5B0`5D.roll`20=`20Rolldie();`20`20`20`20`20`20`20`20`20`20`20`20`20/*
  499. V`20roll`20the`20dice`20*/
  500. Xg->mvs`5B1`5D.roll`20=`20Rolldie();
  501. Xg->rolls`5Bg->mvs`5B0`5D.roll`20-`201`5D++;`09`09/*`20keep`20count`20of`20what
  502. V`20rolls`20we`20got`20*/
  503. Xg->rolls`5Bg->mvs`5B1`5D.roll`20-`201`5D++;
  504. Xif`20(g->mvs`5B0`5D.roll`20==`20g->mvs`5B1`5D.roll)`20`7B`09/*`20hot`20damn,
  505. V`20we`20got`20doubles`20*/
  506. X`09g->mvs`5B2`5D.roll`20=`20g->mvs`5B0`5D.roll;`09/*`20copy`20roll`20into`20tw
  507. Vo`20*/
  508. X`09g->mvs`5B3`5D.roll`20=`20g->mvs`5B0`5D.roll;`09/*`20more`20moves`20*/
  509. X`09g->doubles`5Bg->mvs`5B1`5D.roll`20-`201`5D++;`09/*`20keep`20track`20of`20do
  510. Vubles`20*/
  511. X`09`7D
  512. Xlegalmoves(g);`09`09`09/*`20calculate`20the`20#`20of`20moves`20`26`20hi`20roll
  513. V`20*/
  514. X`7D
  515. X
  516. X
  517. X
  518. X/*----------------------------------------------------------------------
  519. X`20*`09sendpkt`20--`20send`20a`20packet`20to`20the`20opponent
  520. X`20*
  521. X`20*`20This`20function`20fills`20in`20the`20fields`20of`20a`20packet`20and`20p
  522. Vasses`20that
  523. X`20*`20packet`20to`20the`20transport`20using`20TSendPacket.`20`20It`20also`20s
  524. Vtores`20the
  525. X`20*`20opcode`20sent`20in`20the`20lastop`20field`20of`20the`20game,`20so`20the
  526. V`20packet
  527. X`20*`20can`20be`20regenerated`20if`20necessary.`20`20Sendpkt`20returns`201`20i
  528. Vf`20the
  529. X`20*`20packet`20was`20sent,`20and`200`20if`20an`20error`20occurred.
  530. X`20*----------------------------------------------------------------------
  531. X`20*/
  532. X
  533. Xsendpkt(g,op)
  534. Xstruct`20game`20*g;
  535. Xchar`20op;
  536. X`7B
  537. Xstatic`20char`20colors`5B4`5D,`20adbl`5B10`5D,`20mch`5B10`5D;
  538. Xchar`20cmt`5B60`5D,`20cmt2`5B60`5D,`20*sendaddr;
  539. Xint`20i,`20status;
  540. X
  541. Xif`20(FeIsActive)
  542. X`09FeMessage("Sending...");
  543. Xsendaddr`20=`20g->opaddr;`09`09/*`20this`20is`20overridden`20for`20NOTIFY`20*/
  544. V
  545. Xif`20(`20(op`20!=`20RESEND)`20`26`26`20(op`20!=`20NOTIFY)`20)
  546. X`09g->lastop`20=`20op;`09`09`09/*`20save`20last`20op`20for`20resend`20*/
  547. Xfor`20(i`20=`200;`20i`20<`204;`20i++)
  548. X`09g->blot`5Bi`5D`20=`200;`09`09`09/*`20clear`20blots`20hit`20*/
  549. Xif`20(*rc.chkpt`20==`20'y')`20`7B
  550. X`09writegames(rc.gfile,rc.gbackup,rc.pfile);
  551. X`09rc.gbackup`20=`20NULL;`09/*`20only`20backup`20old`20file`20once`20*/
  552. X`09`7D
  553. XP.version`20=`20LDB_VER;`09`09`09/*`20these`20fields`20go`20in`20all`20packets
  554. V`20*/
  555. XP.gameid`20=`20g->gameid;
  556. XP.opcode`20=`20op;
  557. XP.seq`20=`20g->seq;
  558. XP.jacoby`20=`20NULL;
  559. XP.crawford`20=`20NULL;
  560. XP.european`20=`20NULL;
  561. XP.perm`20=`20NULL;
  562. XP.match`20=`20NULL;
  563. Xif`20(g->opver`20>`20100)`20`7B`09/*`20versions`20after`201.0`20rot13`20commen
  564. Vts`20*/
  565. X`09if`20(g->mycmt`20!=`20NULL)`20`7B
  566. X`09`09strncpy(cmt,g->mycmt,sizeof(cmt));`09/*`20make`20copy`20*/
  567. X`09`09cmt`5Bsizeof(cmt)-1`5D`20=`20'`5C0';`09`09/*`20null`20term`20*/
  568. X`09`09P.comment`20=`20cmt;`09`09`09/*`20save`20pointer`20*/
  569. X`09`09rotate(P.comment);`09`09`09/*`20rot13`20the`20copy`20*/
  570. X`09`09`7D
  571. X`09else
  572. X`09`09P.comment`20=`20NULL;
  573. X`09if`20(g->mycmt2`20!=`20NULL)`20`7B
  574. X`09`09strncpy(cmt2,g->mycmt2,sizeof(cmt2));`09/*`20make`20copy`20*/
  575. X`09`09cmt2`5Bsizeof(cmt2)-1`5D`20=`20'`5C0';`09`09/*`20null`20term`20*/
  576. X`09`09P.comment2`20=`20cmt2;`09`09`09/*`20save`20pointer`20*/
  577. X`09`09rotate(P.comment2);`09`09`09/*`20rot13`20the`20copy`20*/
  578. X`09`09`7D
  579. X`09else
  580. X`09`09P.comment2`20=`20NULL;
  581. X`09`7D
  582. Xelse`20`7B`09`09`09`09/*`20version`201.0`20sends`20comments`20as`20cleartext
  583. V`20*/
  584. X`09P.comment`20=`20g->mycmt;
  585. X`09P.comment2`20=`20g->mycmt2;
  586. X`09`7D
  587. Xif`20(g->flags`20`26`20F_SENTNAME)`20`7B
  588. X`09P.name`20=`20NULL;
  589. X`09P.notify`20=`20NULL;
  590. X`09`7D
  591. Xelse`20`7B
  592. X`09P.name`20=`20rc.myname;
  593. X`09P.notify`20=`20g->notify;
  594. X`09g->flags`20`7C=`20F_SENTNAME;
  595. X`09`7D
  596. XP.addr`20=`20NULL;`09`09`09`09/*`20these`20fields`20only`20used`20by`20START
  597. V`20*/
  598. XP.colors`20=`20NULL;
  599. XP.dir`20=`20NULL;
  600. XP.autodbl`20=`20NULL;`09`09`09/*`20used`20by`20START`20and`20TIE`20*/
  601. XP.timestamp`20=`20time((long`20*)`200);`09`09/*`20attach`20timestamp`20*/
  602. Xif`20(g->lastacc`20<`20P.timestamp)`09`09/*`20update`20last`20access`20time
  603. V`20*/
  604. X`09g->lastacc`20=`20P.timestamp;`09/*`20but`20don't`20let`20time`20go`20backwa
  605. Vrds`20*/
  606. Xclearmvs(P.mvs);
  607. Xswitch`20(op)`20`7B`09`09`09`09/*`20now`20do`20operation-specific`20stuff`20*/
  608. V
  609. Xcase`20START:
  610. X`09P.addr`20=`20g->myaddr;`09`09/*`20send`20opponent`20my`20email`20address
  611. V`20*/
  612. X`09P.mvs`5B0`5D.roll`20=`20g->mvs`5B0`5D.roll;`09/*`20send`20initial`20die`20r
  613. Voll`20*/
  614. X`09sprintf(colors,"%c%c",g->mycolor,g->opcolor);
  615. X`09P.colors`20=`20colors;
  616. X`09P.dir`20=`20(g->mydir`20>`200)`20?`20"down"`20:`20"up";
  617. X`09sprintf(adbl,"%d",rc.autodouble);
  618. X`09P.autodbl`20=`20adbl;
  619. X`09if`20(g->flags`20`26`20F_JACOBY)`09/*`20enable`20jacoby`20*/
  620. X`09`09P.jacoby`20=`20"yes";
  621. X`09if`20(g->flags`20`26`20F_CRAWFORD)`09/*`20enable`20crawford`20*/
  622. X`09`09P.crawford`20=`20"yes";
  623. X`09if`20(g->flags`20`26`20F_EUROPE)`09/*`20enable`20european`20rule`20*/
  624. X`09`09P.european`20=`20"yes";
  625. X`09if`20(g->flags`20`26`20F_PERM)`09`09/*`20game`20is`20permanent`20*/
  626. X`09`09P.perm`20=`20"yes";
  627. X`09if`20(g->mtotal`20>`200)`20`7B`09`09/*`20enable`20match`20play`20*/
  628. X`09`09sprintf(mch,"%d",g->mtotal);
  629. X`09`09P.match`20=`20mch;
  630. X`09`09`7D
  631. X`09break;
  632. Xcase`20USTART:
  633. X`09P.mvs`5B0`5D.roll`20=`20g->mvs`5B0`5D.roll;`09/*`20send`20both`20initial
  634. V`20dice`20*/
  635. X`09P.mvs`5B1`5D.roll`20=`20g->mvs`5B1`5D.roll;
  636. X`09break;
  637. Xcase`20MSTART:
  638. Xcase`20RESTART:`09`09`09`09/*`20retry`20initial`20roll`20*/
  639. X`09P.mvs`5B0`5D.roll`20=`20g->mvs`5B0`5D.roll;`09/*`20send`20new`20roll`20*/
  640. X`09break;
  641. Xcase`20TIE:
  642. X`09if`20(g->adcnt`20>`200)`20`7B`09`09/*`20send`20current`20autodouble`20count
  643. V`20*/
  644. X`09`09sprintf(adbl,"%d",g->adcnt);
  645. X`09`09P.autodbl`20=`20adbl;
  646. X`09`09`7D
  647. X`09break;
  648. Xcase`20MOVE:
  649. X`09for`20(i`20=`200;`20i`20<`204;`20i++)
  650. X`09`09P.mvs`5Bi`5D`20=`20g->mvs`5Bi`5D;
  651. X`09break;
  652. Xcase`20NOTIFY:
  653. X`09P.addr`20=`20g->myaddr;
  654. X`09P.seq`20=`200;`09`09`09/*`20no`20sequences`20for`20notify`20packets`20*/
  655. X`09P.notify`20=`20NULL;
  656. X`09P.name`20=`20rc.myname;
  657. X`09i`20=`20gvalue(g,`26status);
  658. X`09sprintf(cmt,"%d`20%d`20%d",g->term,status,i);
  659. X`09P.comment`20=`20cmt;`09/*`20send`20term`20code,`20game`20val,`20`26`20bg
  660. V`20flag`20*/
  661. X`09P.comment2`20=`20g->opaddr;`09/*`20send`20opponent`20address`20*/
  662. X`09if`20(`20(sendaddr`20=`20g->notify)`20==`20NULL)
  663. X`09`09return;`09`09/*`20shouldn't`20happen`20*/
  664. X`09`7D
  665. Xstatus`20=`20TSendPacket(`26P,sendaddr);`09`09/*`20send`20the`20packet`20*/
  666. Xif`20(FeIsActive)`09`09`09`09/*`20clear`20"Sending..."`20from`20mesg`20line
  667. V`20*/
  668. X`09FeMessage(NULL);
  669. Xreturn(status);
  670. X`7D
  671. X
  672. X
  673. X
  674. X/*----------------------------------------------------------------------
  675. X`20*`09resendpkt`20--`20resend`20the`20last`20packet
  676. X`20*
  677. X`20*`20This`20function`20takes`20a`20game`20structure`20and`20causes`20the`20l
  678. Vast`20packet`20sent
  679. X`20*`20in`20that`20game`20to`20be`20resent.
  680. X`20*
  681. X`20*`20The`20F_SENTNAME`20flag`20is`20cleared`20before`20resending,`20causing
  682. V`20our`20personal
  683. X`20*`20name`20to`20be`20resent.`20`20This`20is`20because`20the`20packet`20bein
  684. Vg`20resent`20might`20have
  685. X`20*`20been`20the`20one`20that`20sent`20the`20personal`20name`20(and`20set`20t
  686. Vhe`20F_SENTNAME`20flag),
  687. X`20*`20and`20since`20the`20F_SENTNAME`20flag`20is`20now`20set,`20the`20persona
  688. Vl`20name`20would`20not
  689. X`20*`20be`20included`20in`20the`20resent`20packet.
  690. X`20*----------------------------------------------------------------------
  691. X`20*/
  692. X
  693. Xresendpkt(g)
  694. Xstruct`20game`20*g;
  695. X`7B
  696. X
  697. Xg->flags`20`26=`20`7EF_SENTNAME;
  698. Xsendpkt(g,g->lastop);
  699. X`7D
  700. X
  701. X
  702. X
  703. X/*----------------------------------------------------------------------
  704. X`20*`09str2mv`20--`20decode`20move`20string`20to`20struct`20mv
  705. X`20*
  706. X`20*`20This`20function`20takes`20a`20string`20representation`20of`20a`20move,
  707. V`20decodes`20it,
  708. X`20*`20and`20places`20the`20information`20into`20a`20mv`20structure.`20`20This
  709. V`20format`20is:
  710. X`20*
  711. X`20*`09roll/move
  712. X`20*
  713. X`20*`20where`20roll`20is`20the`20die`20value`20used`20in`20the`20move,`20and
  714. V`20is`20a`20single
  715. X`20*`20digit`20in`20`5B1..6`5D,`20and`20move`20is`20one`20of`20the`20following
  716. V:
  717. X`20*
  718. X`20*`09a`201`20or`202`20digit`20number`20in`20`5B1..24`5D
  719. X`20*`09`09This`20designates`20the`20point`20the`20move`20originates`20from.
  720. X`20*`09`09This`20number`20is`20stored`20in`20the`20"pt"`20field`20of`20the`20m
  721. Vove
  722. X`20*`09`09structure`20without`20modification.
  723. X`20*`09the`20string`20"BAR"
  724. X`20*`09`09This`20means`20the`20piece`20is`20coming`20off`20the`20bar.
  725. X`20*`09`09Zero`20is`20stored`20in`20the`20"pt"`20field`20of`20the`20move`20str
  726. Vucture,
  727. X`20*`09`09regardless`20of`20whether`20the`20player's`20bar`20point`20is`200
  728. V`20or`2025.
  729. X`20*`09`09Apply()`20and`20FeDrawMove`20understand`20this`20and`20convert`200
  730. V`20to
  731. X`20*`09`09the`20appropriate`20bar`20point`20before`20using`20it.
  732. X`20*`09the`20string`20"UNUSED"
  733. X`20*`09`09This`20means`20the`20roll`20is`20unused.`20`20-1`20is`20stored`20in
  734. V`20the
  735. X`20*`09`09"pt"`20field`20of`20the`20mv`20structure.
  736. X`20*----------------------------------------------------------------------
  737. X`20*/
  738. X
  739. Xstr2mv(s,m)
  740. Xchar`20*s;
  741. Xstruct`20mv`20*m;
  742. X`7B
  743. Xchar`20*p,`20*strchr();
  744. X
  745. Xif`20(`20(p`20=`20strchr(s,'/'))`20==`20NULL)`20`7B
  746. X`09message("ERROR:`20malformed`20move:`20%s`5Cn",s);
  747. X`09return;
  748. X`09`7D
  749. Xif`20(`20(`20(m->roll`20=`20atoi(s))`20<`200)`20`7C`7C`20(m->roll`20>`206)`20)
  750. V`20`7B
  751. X`09message("ERROR:`20invalid`20roll:`20%d`5Cn",m->roll);
  752. X`09return;
  753. X`09`7D
  754. Xp++;
  755. Xif`20(`20(m->roll`20==`200)`20`7C`7C`20(*p`20==`20'U')`20`7C`7C`20(*p`20==`20'
  756. Vu')`20)
  757. X`09m->pt`20=`20-1;`09`09/*`20this`20roll`20is`20unused`20*/
  758. Xelse`20if`20(`20(*p`20==`20'B')`20`7C`7C`20(*p`20==`20'b')`20)
  759. X`09m->pt`20=`200;`09`09/*`20move`20from`20bar`20*/
  760. Xelse`20if`20(`20(`20(m->pt`20=`20atoi(p))`20<`200)`20`7C`7C`20(m->pt`20>`2025)
  761. V`20)`20`7B
  762. X`09message("ERROR:`20invalid`20point:`20%d`5Cn",m->pt);
  763. X`09return;
  764. X`09`7D
  765. X`7D
  766. X
  767. X
  768. X/*----------------------------------------------------------------------
  769. X`20*`09mv2str`20--`20encode`20move`20string`20from`20struct`20mv
  770. X`20*
  771. X`20*`20This`20function`20forms`20a`20string`20representation`20of`20a`20move
  772. V`20based`20on
  773. X`20*`20the`20information`20in`20a`20mv`20structure.`20`20This`20format`20is:
  774. X`20*
  775. X`20*`09roll/move
  776. X`20*
  777. X`20*`20where`20roll`20is`20the`20die`20value`20stored`20in`20mv->roll,`20and
  778. V`20move`20is:
  779. X`20*
  780. X`20*`09mv->pt`20if`20mv->pt`20is`20in`20`5B1..24`5D
  781. X`20*`09the`20string`20"BAR",`20if`20mv->pt`20is`200`20or`2025
  782. X`20*`09the`20string`20"UNUSED",`20if`20mv->pt`20is`20<`200
  783. X`20*----------------------------------------------------------------------
  784. X`20*/
  785. X
  786. Xmv2str(m,s)
  787. Xstruct`20mv`20*m;
  788. Xchar`20*s;
  789. X`7B
  790. X
  791. Xif`20(m->roll`20<=`200)`20`7B`09`09/*`20non-existant`20roll`20*/
  792. X`09strcpy(s,"0/0");`09/*`20should`20be`20skipped`20by`20nvwrite`20*/
  793. X`09return;`09`09`09/*`20so`20we`20should`20never`20get`20here`20*/
  794. X`09`7D
  795. Xif`20(m->pt`20<`200)
  796. X`09sprintf(s,"%d/UNUSED",m->roll);
  797. Xelse`20if`20(`20(m->pt`20==`20DOWNBAR)`20`7C`7C`20(m->pt`20==`20UPBAR)`20)
  798. X`09sprintf(s,"%d/BAR",m->roll);
  799. Xelse
  800. X`09sprintf(s,"%d/%d",m->roll,m->pt);
  801. X`7D
  802. X
  803. X
  804. X/*----------------------------------------------------------------------
  805. X`20*`09clearmvs`20--`20mark`20all`20entries`20in`20a`20mv`20array`20empty
  806. X`20*
  807. X`20*`20This`20function`20marks`20all`20elements`20of`20a`20mv`20array`20as`20b
  808. Veing`20unused.
  809. X`20*----------------------------------------------------------------------
  810. X`20*/
  811. X
  812. X
  813. Xclearmvs(m)
  814. Xstruct`20mv`20*m;
  815. X`7B
  816. Xint`20i;
  817. X
  818. Xfor`20(i`20=`200;`20i`20<`204;`20i++)`20`7B
  819. X`09m`5Bi`5D.roll`20=`20-1;
  820. X`09m`5Bi`5D.pt`20=`20-1;
  821. X`09`7D
  822. X`7D
  823. X
  824. X
  825. X
  826. X/*----------------------------------------------------------------------
  827. X`20*`09canmove`20--`20see`20if`20a`20roll`20is`20usable`20in`20a`20range`20of
  828. V`20points
  829. X`20*
  830. X`20*`20This`20function`20trys`20to`20use`20a`20roll`20over`20a`20range`20of
  831. V`20points.`20`20If`20it
  832. X`20*`20finds`20a`20point`20where`20a`20roll`20could`20be`20used,`20it`20return
  833. Vs`201,`20otherwise
  834. X`20*`20it`20returns`200.`20`20The`20board`20is`20not`20changed.
  835. X`20*----------------------------------------------------------------------
  836. X`20*/
  837. X
  838. Xcanmove(g,r,p1,p2)
  839. Xstruct`20game`20*g;`09`09/*`20the`20game`20structure`20*/
  840. Xint`20r;`09`09`09/*`20which`20element`20of`20g->mvs`20*/
  841. Xint`20p1,`20p2;`09`09/*`20the`20range`20of`20points`20to`20try`20*/
  842. X`7B
  843. Xint`20i,`20op;
  844. X
  845. Xif`20(p1`20>`20p2)`20`7B
  846. X`09i`20=`20p1;
  847. X`09p1`20=`20p2;
  848. X`09p2`20=`20i;
  849. X`09`7D
  850. Xop`20=`20g->mvs`5Br`5D.pt;`09`09/*`20so`20we`20can`20restore`20it`20*/
  851. Xfor`20(i`20=`20p1;`20i`20<=`20p2;`20i++)`20`7B
  852. X`09g->mvs`5Br`5D.pt`20=`20i;`09`09/*`20try`20from`20this`20point`20*/
  853. X`09if`20(apply(g,WHO_ME,r,A_CHKONLY,NULL)`20>=`200)`20`7B
  854. X`09`09g->mvs`5Br`5D.pt`20=`20op;
  855. X`09`09return(1);
  856. X`09`09`7D
  857. X`09`7D
  858. Xg->mvs`5Br`5D.pt`20=`20op;
  859. Xreturn(0);
  860. X`7D
  861. X
  862. X
  863. X/*----------------------------------------------------------------------
  864. X`20*`09rotate`20--`20rot13`20a`20buffer
  865. X`20*
  866. X`20*`20This`20function`20performs`20the`20popular`20"rot13"`20conversion`20to
  867. V`20a`20buffer.
  868. X`20*`20The`20buffer`20is`20modified`20in`20place.`20`20This`20conversion`20mak
  869. Ves`20a
  870. X`20*`20string`20unreadable`20by`20adding`2013`20to`20letters`20in`20`5BA-Ma-m
  871. V`5D`20and`20subtracting
  872. X`20*`2013`20from`20letters`20in`20`5BN-Zn-z`5D.`20`20All`20other`20characters
  873. V`20are`20unchanged.
  874. X`20*`20Applying`20the`20rot13`20transformation`20again`20returns`20the`20buffe
  875. Vr`20to`20normal.
  876. X`20*----------------------------------------------------------------------
  877. X`20*/
  878. X
  879. Xrotate(buf)
  880. Xchar`20*buf;
  881. X`7B
  882. Xregister`20char`20*s;
  883. X
  884. Xfor`20(s`20=`20buf;`20*s;`20s++)`20`7B
  885. X`09if`20(!`20isalpha(*s))
  886. X`09`09continue;
  887. X`09if`20(`20((*s`20>=`20'A')`20`26`26`20(*s`20<=`20'M'))`20`7C`7C`20((*s`20>=
  888. V`20'a')`20`26`26`20(*s`20<=`20'm'))`20)
  889. X`09`09*s`20+=`20(char)`2013;
  890. X`09else
  891. X`09`09*s`20-=`20(char)`2013;
  892. X`09`7D
  893. X`7D
  894. X
  895. X
  896. X/*----------------------------------------------------------------------
  897. X`20*`09message`20--`20print`20a`20message`20in`20proper`20way
  898. X`20*
  899. X`20*`20This`20function`20checks`20to`20see`20if`20the`20front`20end`20is`20act
  900. Vive.`20`20If
  901. X`20*`20so,`20it`20calls`20FeMessage,`20otherwise`20it`20prints`20on`20stderr
  902. V`20and
  903. X`20*`20sets`20the`20FeWaitInit`20flag`20so`20that`20when`20FeInitialize`20is
  904. V`20called,
  905. X`20*`20it`20will`20wait`20for`20return`20to`20be`20pressed`20before`20clearing
  906. V`20the`20screen.
  907. X`20*----------------------------------------------------------------------
  908. X`20*/
  909. X
  910. Xmessage(s,a1,a2,a3)
  911. Xchar`20*s;
  912. Xint`20a1,`20a2,`20a3;
  913. X`7B
  914. Xchar`20buf`5B80`5D;
  915. X
  916. Xif`20(FeIsActive)`20`7B
  917. X`09sprintf(buf,`20s,`20a1,`20a2,`20a3);
  918. X`09FeMessage(buf);
  919. X`09`7D
  920. Xelse`20`7B
  921. X`09fprintf(stderr,s,a1,a2,a3);
  922. X`09FeWaitInit++;
  923. X`09if`20(FeWaitInit`20>`2022)`20`7B
  924. X`09`09fprintf(stderr,"Press`20<return>`20to`20continue...");
  925. X`09`09fgets(buf,sizeof(buf),stdin);
  926. X`09`09FeWaitInit`20=`200;
  927. X`09`09`7D
  928. X`09`7D
  929. X`7D
  930. X
  931. X
  932. X/*----------------------------------------------------------------------
  933. X`20*`09fatal`20--`20terminate`20program`20with`20error`20message
  934. X`20*
  935. X`20*`20This`20function`20prints`20a`20message`20to`20stderr`20and`20exits.
  936. X`20*----------------------------------------------------------------------
  937. X`20*/
  938. X
  939. Xfatal(msg)
  940. Xchar`20*msg;
  941. X`7B
  942. X
  943. XFeFinishSession();
  944. XTFinishSession();
  945. Xfprintf(stderr,"%s`5Cn",msg);
  946. Xldbexit(STAT_ABORT);
  947. X`7D
  948. X
  949. X
  950. X/*----------------------------------------------------------------------
  951. X`20*`09ldbexit`20--`20terminate`20program`20in`20an`20orderly`20fashion
  952. X`20*
  953. X`20*`20This`20function`20can`20be`20called`20at`20any`20time,`20and`20ensures
  954. V`20that`20the
  955. X`20*`20front`20end`20and`20the`20transport`20are`20closed`20down`20cleanly`20b
  956. Vefore
  957. X`20*`20exiting.
  958. X`20*----------------------------------------------------------------------
  959. X`20*/
  960. X
  961. Xldbexit(code)
  962. Xint`20code;
  963. X`7B
  964. X
  965. XFeFinishSession();
  966. XTFinishSession();
  967. Xrelease_lock(rc.lockfile);
  968. Xfflush(stdout);
  969. Xfflush(stderr);
  970. Xexit(code);
  971. X`7D
  972. X
  973. X
  974. X/*----------------------------------------------------------------------
  975. X`20*`09pipcount`20--`20calculate`20a`20pip`20count`20for`20both`20players
  976. X`20*
  977. X`20*`20This`20function`20takes`20a`20board`20and`20a`20pointer`20to`20a`20game
  978. V`20structure
  979. X`20*`20and`20calculates`20a`20pip`20count`20for`20both`20players.`20`20These
  980. V`20are`20returned
  981. X`20*`20in`20*mp`20and`20*op.
  982. X`20*----------------------------------------------------------------------
  983. X`20*/
  984. X
  985. Xpipcount(b,g,mp,op)
  986. Xboard`20b;`09`09`09/*`20the`20board`20*/
  987. Xstruct`20game`20*g;`09`09`09/*`20the`20game`20*/
  988. Xint`20*mp;`09`09`09/*`20where`20to`20store`20my`20pip`20count`20*/
  989. Xint`20*op;`09`09`09/*`20where`20to`20store`20opponent's`20pip`20count`20*/
  990. X`7B
  991. Xint`20direction`5B2`5D;
  992. Xint`20player;`09`09`09/*`20me`20=`200;`20op`20=`201`20*/
  993. Xint`20PIP`5B2`5D;`09`09`09/*`20mypip`20=`200;`20oppip`20=`201`20*/
  994. Xint`20i;`09`09`09`09/*`20counter`20*/
  995. X
  996. XPIP`5BWHO_ME`5D`20=`200;`09`09`09/*`20initialize`20my`20PIP`20count`20*/
  997. XPIP`5BWHO_OPP`5D`20=`200;`09`09`09/*`20initialize`20op`20PIP`20count`20*/
  998. Xdirection`5BWHO_ME`5D`20=`20g->mydir;`09`09/*`20my`20direction`20of`20travel
  999. V`20*/
  1000. Xdirection`5BWHO_OPP`5D`20=`20g->opdir;`09`09/*`20op`20direction`20of`20travel
  1001. V`20*/
  1002. X
  1003. Xfor`20(i`20=`200;`20i`20<=`20DOWNBAR;`20i++)`20`7B`09/*`20for`20each`20point
  1004. V`20on`20the`20board`20*/
  1005. X
  1006. X`09if`20(b`5Bi`5D.qty`20>`200)`20`7B
  1007. X`09`09player`20=`20(b`5Bi`5D.color`20==`20g->mycolor)`20?`20WHO_ME`20:`20WHO_O
  1008. VPP;
  1009. X`09`09if`20((i`20==`20UPBAR)`20`7C`7C`20(i`20==`20DOWNBAR))
  1010. X`09`09`09PIP`5Bplayer`5D`20+=`20b`5Bi`5D.qty`20*`2025;
  1011. X`09`09else`20`7B
  1012. X`09`09`09if`20(direction`5Bplayer`5D`20==`201)
  1013. X`09`09`09`09PIP`5Bplayer`5D`20+=`20b`5Bi`5D.qty`20*`20(25`20-`20i);
  1014. X`09`09`09else
  1015. X`09`09`09`09PIP`5Bplayer`5D`20+=`20b`5Bi`5D.qty`20*`20i;
  1016. X`09`09`09`7D
  1017. X`09`09`7D
  1018. X`09`7D
  1019. X*mp`20=`20PIP`5BWHO_ME`5D;`09`09/*`20return`20my`20pip`20count`20*/
  1020. X*op`20=`20PIP`5BWHO_OPP`5D;`09`09/*`20return`20opponent's`20pip`20count`20*/
  1021. X`7D
  1022. X
  1023. X
  1024. X/*----------------------------------------------------------------------
  1025. X`20*`09gvalue`20--`20calculate`20the`20game`20value
  1026. X`20*
  1027. X`20*`20This`20function`20takes`20a`20completed`20game`20and`20calculates`20its
  1028. V`20value,
  1029. X`20*`20taking`20into`20account`20gammons,`20backgammons,`20and`20the`20Jacoby
  1030. V`20and
  1031. X`20*`20European`20rules.`20`20These`20are:
  1032. X`20*`09-`20Gammon`20(when`20the`20loser`20does`20not`20bear`20off`20any`20piec
  1033. Ves)
  1034. X`20*`09`20`20counts`20as`20double`20the`20game`20value`20shown`20on`20the`20cu
  1035. Vbe.
  1036. X`20*`09-`20Backgammon`20(when`20the`20loser`20does`20not`20bear`20off`20any
  1037. V`20pieces
  1038. X`20*`09`20`20and`20has`20pieces`20in`20the`20winner's`20home`20board)`20counts
  1039. V`20as
  1040. X`20*`09`20`20triple`20the`20game`20value`20shown`20on`20the`20cube.
  1041. X`20*`09-`20Jacoby`20rule`20(if`20enabled)`20states`20that`20Gammons`20and`20Ba
  1042. Vckgammons
  1043. X`20*`09`20`20count`20as`20single`20games`20if`20neither`20player`20doubled`20d
  1044. Vuring`20the`20game.
  1045. X`20*`09-`20European`20rule`20(if`20enabled)`20states`20the`20Backgammons`20cou
  1046. Vnt`20double,
  1047. X`20*`09`20`20not`20triple,`20the`20game`20value`20shown`20on`20the`20cube.
  1048. X`20*`20The`20game`20value`20is`20returned`20in`20*vp;`20the`20return`20value
  1049. V`20is`201`20for`20a`20gammon,
  1050. X`20*`202`20for`20a`20backgammon,`20and`200`20for`20neither.
  1051. X`20*
  1052. X`20*`20If`20the`20game`20was`20conceded,`20gvalue()`20scores`20a`20gammon`20if
  1053. V`20the`20loser`20has
  1054. X`20*`20not`20borne`20off`20any`20pieces,`20and`20a`20backgammon`20if`20the`20l
  1055. Voser`20has`20any`20pieces
  1056. X`20*`20in`20the`20winners`20inner`20table.`20`20This`20prevents`20players`20fr
  1057. Vom`20conceding`20to
  1058. X`20*`20avoid`20a`20gammon/backgammon.
  1059. X`20*----------------------------------------------------------------------
  1060. X`20*/
  1061. X
  1062. Xgvalue(g,vp)
  1063. Xstruct`20game`20*g;
  1064. Xint`20*vp;
  1065. X`7B
  1066. Xint`20bf;
  1067. Xint`20p1,`20p2;
  1068. X
  1069. Xbf`20=`200;`09`09`09`09/*`20init`20to`20no`20gammon/backgammon`20*/
  1070. X*vp`20=`20g->gameval;`09`09/*`20init`20to`20game`20value`20on`20cube`20*/
  1071. Xif`20(`20(g->term`20==`20T_ILOSE)`20`7C`7C`20(g->term`20==`20T_ICONCEDE)`20)
  1072. V`20`7B
  1073. X`09if`20(g->board`5BOFFPT(g->mydir)`5D.qty`20==`200)`20`7B
  1074. X`09`09p1`20=`20(g->opdir`20>`200)`20?`2019`20:`200;/*`20check`20op's`20inner
  1075. V`20tbl*/
  1076. X`09`09p2`20=`20(g->opdir`20>`200)`20?`2025`20:`206;`09/*`20for`20my`20pieces
  1077. V`20*/
  1078. X`09`09if`20(addpcs(g->board,g->mycolor,p1,p2)`20>`200)
  1079. X`09`09`09bf`20=`202;`09`09`09/*`20flag`20a`20backgammon`20*/
  1080. X`09`09else
  1081. X`09`09`09bf`20=`201;`09`09`09/*`20flag`20a`20gammon`20*/
  1082. X`09`09`7D
  1083. X`09`7D
  1084. Xelse`20if`20(`20(g->term`20==`20T_IWIN)`20`7C`7C`20(g->term`20==`20T_OPCONCEDE
  1085. V)`20)`20`7B
  1086. X`09if`20(g->board`5BOFFPT(g->opdir)`5D.qty`20==`200)`20`7B
  1087. X`09`09p1`20=`20(g->mydir`20>`200)`20?`2019`20:`200;`09/*`20check`20my`20inner
  1088. V`20tbl*/
  1089. X`09`09p2`20=`20(g->mydir`20>`200)`20?`2025`20:`206;`09/*`20for`20op's`20pieces
  1090. V`20*/
  1091. X`09`09if`20(addpcs(g->board,g->opcolor,p1,p2)`20>`200)
  1092. X`09`09`09bf`20=`202;`09`09`09/*`20flag`20a`20backgammon`20*/
  1093. X`09`09else
  1094. X`09`09`09bf`20=`201;`09`09`09/*`20flag`20a`20gammon`20*/
  1095. X`09`09`7D
  1096. X`09`7D
  1097. Xif`20(`20(g->flags`20`26`20F_JACOBY)`20`26`26`20(g->gameval`20==`20(1`20<<`20g
  1098. V->adcnt))`20)
  1099. X`09return(bf);`09/*`20jacoby`20enabled`20`26`20no`20doubles,`20don't`20mult
  1100. V`20game`20val`20*/
  1101. Xif`20(`20(g->flags`20`26`20F_EUROPE)`20`26`26`20(bf`20==`202)`20)`20`7B
  1102. X`09*vp`20*=`202;`09/*`20european`20rule`20enabled,`20bg`20=`202`20multiplier
  1103. V`20*/
  1104. X`09return(bf);
  1105. X`09`7D
  1106. Xif`20(bf`20==`202)
  1107. X`09*vp`20*=`203;`09/*`20backgammon`20=`203`20multiplier`20*/
  1108. Xelse`20if`20(bf`20==`201)
  1109. X`09*vp`20*=`202;`09/*`20gammon`20=`202`20multipler`20*/
  1110. Xreturn(bf);`09`09/*`20return`20gammon/backgammon/neither`20flag`20*/
  1111. X`7D
  1112. X
  1113. X
  1114. X/*----------------------------------------------------------------------
  1115. X`20*`09iscontact`20--`20determine`20if`20contact`20is`20possible`20for`20a`20g
  1116. Vame
  1117. X`20*
  1118. X`20*`20This`20function`20returns`201`20if`20it`20is`20possible`20for`20any`20p
  1119. Viece`20to`20hit
  1120. X`20*`20any`20other`20piece,`200`20if`20both`20players`20have`20moved`20past
  1121. V`20each`20other
  1122. X`20*`20and`20the`20game`20is`20a`20race.
  1123. X`20*----------------------------------------------------------------------
  1124. X`20*/
  1125. X
  1126. Xiscontact(g)
  1127. Xstruct`20game`20*g;
  1128. X`7B
  1129. Xint`20dc,`20dn,`20i;
  1130. X
  1131. Xif`20(g->mydir`20>`200)`09`09/*`20which`20color`20is`20down-bound?`20*/
  1132. X`09dc`20=`20g->opcolor;
  1133. Xelse
  1134. X`09dc`20=`20g->mycolor;
  1135. Xdn`20=`20g->board`5BDOWNOFF`5D.qty;`09`09/*`20start`20with`20#`20pcs`20borne
  1136. V`20off`20*/
  1137. Xfor`20(i`20=`200;`20(i`20<=`2024)`20`26`26`20(dn`20<`2015);`20i++)`20`7B
  1138. X`09if`20(g->board`5Bi`5D.qty`20==`200)
  1139. X`09`09continue;
  1140. X`09if`20(g->board`5Bi`5D.color`20!=`20dc)`09/*`20found`20some`20upbound`20piec
  1141. Ves`20*/
  1142. X`09`09return(1);`09`09/*`20that`20are`20in`20hitting`20range`20*/
  1143. X`09dn`20+=`20g->board`5Bi`5D.qty;`09`09/*`20keep`20count`20of`20down`20pcs`20f
  1144. Vound`20*/
  1145. X`09`7D
  1146. Xif`20(dn`20>=`2015)`09`09`09`09/*`20found`20all`20down`20pcs`20*/
  1147. X`09return(0);`09`09`09/*`20no`20more`20contact`20for`20this`20game`20*/
  1148. Xreturn(1);
  1149. X`7D
  1150. X
  1151. X
  1152. X/*----------------------------------------------------------------------
  1153. X`20*`09crawford_check`20--`20is`20this`20the`20crawford`20rule`20game`20for
  1154. V`20a`20match?
  1155. X`20*
  1156. X`20*`20This`20function`20sets`20the`20F_CRGAME`20and`20F_CRDONE`20flags`20for
  1157. V`20a`20match.
  1158. X`20*`20F_CRGAME`20is`20set`20if`20this`20is`20the`20crawford`20rule`20game`20f
  1159. Vor`20the`20match.
  1160. X`20*`20F_CRDONE`20is`20set`20after`20the`20crawford`20rule`20game`20has`20been
  1161. V`20played.
  1162. X`20*
  1163. X`20*`20F_CRGAME`20is`20set`20if:
  1164. X`20*`09F_CRAWFORD`20is`20set`09AND
  1165. X`20*`09F_CRDONE`20is`20not`20set`09AND
  1166. X`20*`09a`20player`20is`20within`20one`20point`20of`20winning`20the`20match.
  1167. X`20*`20otherwise`20F_CRGAME`20is`20cleared.
  1168. X`20*
  1169. X`20*`20F_CRDONE`20is`20set`20if:
  1170. X`20*`09F_CRAWFORD`20is`20set`09AND
  1171. X`20*`09F_CRGAME`20was`20set`20(before`20the`20above)
  1172. X`20*`20otherwise`20F_CRDONE`20is`20not`20changed.
  1173. X`20*----------------------------------------------------------------------
  1174. X`20*/
  1175. X
  1176. Xcrawford_check(g)
  1177. Xstruct`20game`20*g;
  1178. X`7B
  1179. Xint`20old_crgame;
  1180. X
  1181. Xold_crgame`20=`20g->flags`20`26`20F_CRGAME;`09`09/*`20save`20F_CRGAME`20*/
  1182. Xif`20(`20((g->flags`20`26`20(F_CRAWFORD`7CF_CRDONE))`20==`20F_CRAWFORD)`20`26
  1183. V`26
  1184. X`20`20`20`20`20(`20(g->mcurrent`5BWHO_ME`5D`20==`20g->mtotal-1)`20`7C`7C
  1185. X`20`20`20`20`20`20`20(g->mcurrent`5BWHO_OPP`5D`20==`20g->mtotal-1)`20)`20)
  1186. X`09g->flags`20`7C=`20F_CRGAME;`09`09/*`20this`20is`20the`20crawford`20rule`20g
  1187. Vame`20*/
  1188. Xelse
  1189. X`09g->flags`20`26=`20`7EF_CRGAME;`09`09/*`20not`20the`20crawford`20game,`20cle
  1190. Var`20flag`20*/
  1191. Xif`20(`20(g->flags`20`26`20F_CRAWFORD)`20`26`26`20old_crgame)
  1192. X`09g->flags`20`7C=`20F_CRDONE;`09`09/*`20crawford`20rule`20game`20is`20over
  1193. V`20*/
  1194. X`7D
  1195. $ call unpack MISC.C;1 138558963 ""
  1196. $!
  1197. $ create 'f'
  1198. X/*`09move.c`09`098/5/91
  1199. X`20*
  1200. X`20*`20Copyright`201991`20`20Perry`20R.`20Ross
  1201. X`20*
  1202. X`20*`20Permission`20to`20use,`20copy,`20modify,`20and`20distribute`20this`20so
  1203. Vftware`20and`20its
  1204. X`20*`20documentation`20without`20fee`20is`20hereby`20granted,`20subject`20to
  1205. V`20the`20restrictions
  1206. X`20*`20detailed`20in`20the`20README`20file,`20which`20is`20included`20here`20b
  1207. Vy`20reference.
  1208. X`20*`20Any`20other`20use`20requires`20written`20permission`20from`20the`20auth
  1209. Vor.`20`20This`20software
  1210. X`20*`20is`20distributed`20"as`20is"`20without`20any`20warranty,`20including
  1211. V`20any`20implied
  1212. X`20*`20warranties`20of`20merchantability`20or`20fitness`20for`20a`20particular
  1213. V`20purpose.
  1214. X`20*`20The`20author`20shall`20not`20be`20liable`20for`20any`20damages`20result
  1215. Ving`20from`20the
  1216. X`20*`20use`20of`20this`20software.`20`20By`20using`20this`20software,`20the
  1217. V`20user`20agrees
  1218. X`20*`20to`20these`20terms.
  1219. X`20*/
  1220. X
  1221. X#include`20"ldb.h"
  1222. X
  1223. X/*-----------------------------------------------------------------------
  1224. X`20*`09apply`20--`20apply`20a`20move`20to`20a`20board
  1225. X`20*
  1226. X`20*`20Apply`20applies`20a`20move`20to`20a`20board,`20detecting`20the`20follow
  1227. Ving`20errors:
  1228. X`20*`09RJ_NOROLL`09The`20mv`20struct`20did`20not`20contain`20a`20valid`20roll.
  1229. V
  1230. X`20*`09RJ_ONBAR`09The`20move`20attempted`20to`20move`20from`20a`20point`20othe
  1231. Vr`20than
  1232. X`20*`09`09`09the`20bar`20when`20pieces`20are`20on`20the`20bar.
  1233. X`20*`09RJ_NOOFF`09The`20move`20attempted`20to`20move`20pieces`20off`20before
  1234. V`20all
  1235. X`20*`09`09`09pieces`20are`20in`20the`20inner`20table.
  1236. X`20*`09RJ_NOPIECE`09The`20move`20attempted`20to`20take`20a`20piece`20from`20an
  1237. V`20empty`20point.
  1238. X`20*`09RJ_NOTYOURS`09The`20move`20attempted`20to`20move`20the`20opponent's`20p
  1239. Viece.
  1240. X`20*`09RJ_OCC`09`09The`20move`20attempted`20to`20move`20to`20an`20occupied`20p
  1241. Voint.
  1242. X`20*`09RJ_EXACT`09The`20move`20attempted`20to`20bear`20off`20a`20piece`20with
  1243. V`20a
  1244. X`20*`09`09`09larger`20roll`20than`20necessary`20when`20that`20piece`20was
  1245. X`20*`09`09`09not`20the`20outermost`20piece.
  1246. X`20*`20If`20the`20move`20was`20legal,`20apply`20returns:
  1247. X`20*`09MVOK`09`09if`20no`20blot`20was`20hit,`20or
  1248. X`20*`09point`20number`09where`20the`20blot`20was`20before`20it`20was`20hit.
  1249. X`20*`20Note`20that`20blot`20numbers`20are`20in`20the`20range`20`5B1-24`5D,`20M
  1250. VVOK`20is`200,`20and
  1251. X`20*`20the`20reject`20codes`20are`20negative.`20`20When`20the`20move`20is`20re
  1252. Vjected,
  1253. X`20*`20the`20board`20is`20unchanged.`20`20When`20a`20blot`20is`20hit,`20it`20i
  1254. Vs`20moved`20to`20the
  1255. X`20*`20appropriate`20bar`20point`20automatically.
  1256. X`20*
  1257. X`20*`20If`20A_REDRAW`20is`20set`20in`20flags,`20apply`20redraws`20the`20releva
  1258. Vnt`20portions`20of
  1259. X`20*`20the`20screen`20to`20reflect`20the`20move.`20`20If`20A_CHKONLY`20is`20se
  1260. Vt`20in`20flags,`20the
  1261. X`20*`20move`20is`20checked`20but`20the`20board`20is`20not`20modified.
  1262. X`20*-----------------------------------------------------------------------
  1263. X`20*/
  1264. X
  1265. Xapply(g,who,mn,flags,dest)
  1266. Xstruct`20game`20*g;`09`09`09/*`20game`20structure`20*/
  1267. Xint`20who;`09`09`09/*`20WHO_OPP`20=`20opponent,`20WHO_ME`20=`20me`20*/
  1268. Xint`20mn;`09`09`09`09/*`20which`20element`20of`20mv`20array`20*/
  1269. Xint`20flags;`09`09`09/*`20A_*`20*/
  1270. Xint`20*dest;`09`09`09/*`20where`20to`20store`20destination`20point`20*/
  1271. X`7B
  1272. Xint`20i,`20j,`20blot;
  1273. Xint`20op,`20np;
  1274. Xint`20dir;
  1275. Xchar`20clr;
  1276. Xstruct`20mv`20*m;
  1277. Xregister`20struct`20point`20*b`20=`20g->board;
  1278. X
  1279. Xdir`20=`20(who`20==`20WHO_ME)`20?`20g->mydir`20:`20g->opdir;
  1280. Xclr`20=`20(who`20==`20WHO_ME)`20?`20g->mycolor`20:`20g->opcolor;
  1281. Xblot`20=`20MVOK;`09`09`09/*`20no`20blot`20hit`20yet`20*/
  1282. Xm`20=`20(who`20==`20WHO_ME)`20?`20`26g->mvs`5Bmn`5D`20:`20`26g->opmvs`5Bmn`5D;
  1283. V
  1284. Xif`20(m->roll`20<=`200)`09`09/*`20sanity`20check`20*/
  1285. X`09return(RJ_NOROLL);`09/*`20reject`20move`20*/
  1286. Xop`20=`20m->pt;`09`09/*`20starting`20point`20number`20*/
  1287. Xif`20(op`20<`200)`09`09/*`20this`20roll`20is`20unused`20*/
  1288. X`09return(MVOK);`09/*`20and`20that's`20ok`20*/
  1289. Xif`20(`20(op`20==`200)`20`7C`7C`20(op`20==`2025)`20)`09/*`20moving`20off`20bar
  1290. V`20*/
  1291. X`09op`20=`20BARPT(dir);`09/*`20use`20correct`20bar`20point`20*/
  1292. Xelse`20`7B`09`09`09/*`20not`20moving`20off`20bar`20*/
  1293. X`09j`20=`20BARPT(dir);`09/*`20make`20sure`20no`20pieces`20still`20on`20bar`20*
  1294. V/
  1295. X`09if`20(b`5Bj`5D.qty`20>`200)
  1296. X`09`09return(RJ_ONBAR);`09/*`20can't`20move,`20pieces`20on`20bar`20*/
  1297. X`09`7D
  1298. Xnp`20=`20op`20+`20m->roll*dir;`09/*`20move`20piece`20correct`20number`20of`20p
  1299. Vts`20*/
  1300. Xif`20(`20(np`20<=`200)`20`7C`7C`20(np`20>=`2025)`20)`20`7B
  1301. X`09i`20=`20(dir`20>`200)`20?`2019`20:`201;
  1302. X`09j`20=`20(dir`20>`200)`20?`2024`20:`206;
  1303. X`09if`20(addpcs(b,clr,i,j)+b`5BOFFPT(dir)`5D.qty`20<`2015)`20/*`20all`20pcs
  1304. V`20not`20*/
  1305. X`09`09return(RJ_NOOFF);`09/*`20in`20inner`20table,`20can't`20move`20off`20*/
  1306. X`09if`20(`20(np`20!=`200)`20`26`26`20(np`20!=`2025)`20)`20`7B/*`20using`20bigg
  1307. Ver`20roll`20than`20needed`20*/
  1308. X`09`09i`20=`20(dir`20>`200)`20?`2019`20`20`20:`20op+1;`20/*`20check`20for`20pc
  1309. Vs`20on`20higher`20pts`20*/
  1310. X`09`09j`20=`20(dir`20>`200)`20?`20op-1`20:`206;
  1311. X`09`09if`20(addpcs(b,clr,i,j)`20>`200)`09/*`20there`20are`20some`20*/
  1312. X`09`09`09return(RJ_EXACT);`09/*`20must`20use`20roll`20on`20them`20*/
  1313. X`09`09`7D
  1314. X`09np`20=`20OFFPT(dir);`09/*`20this`20piece`20is`20moving`20off`20*/
  1315. X`09`7D
  1316. Xif`20(b`5Bop`5D.qty`20<=`200)`09`09/*`20no`20piece`20here`20to`20move`20*/
  1317. X`09return(RJ_NOPIECE);
  1318. Xif`20(b`5Bop`5D.color`20!=`20clr)`09/*`20trying`20to`20move`20opponent's`20pie
  1319. Vces?`20*/
  1320. X`09return(RJ_NOTYOURS);
  1321. Xif`20(b`5Bnp`5D.qty`20==`200)`09`09/*`20moving`20to`20an`20empty`20point`20*/
  1322. X`09b`5Bnp`5D.color`20=`20b`5Bop`5D.color;`09/*`20copy`20color`20*/
  1323. Xif`20(b`5Bnp`5D.color`20!=`20b`5Bop`5D.color)`20`7B`09/*`20moving`20to`20occup
  1324. Vied`20pt`20*/
  1325. X`09if`20(b`5Bnp`5D.qty`20==`201)`20`7B`09`09/*`20whacked`20a`20blot`20*/
  1326. X`09`09blot`20=`20np;`09`09/*`20save`20point`20number`20for`20return`20*/
  1327. X`09`09if`20(`20(flags`20`26`20A_CHKONLY)`20==`200)`20`7B
  1328. +-+-+-+-+-+-+-+-  END  OF PART 11 +-+-+-+-+-+-+-+-
  1329.