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

  1. Path: uunet!caen!sol.ctr.columbia.edu!howland.reston.ans.net!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 [07/16]
  5. Date: 8 Apr 93 10:56:49 EST
  6. Organization: Science Applications Intl Corp - Dayton, OH
  7. Lines: 1365
  8. Message-ID: <1993Apr8.105649.1@dayvd.dayton.saic.com>
  9. NNTP-Posting-Host: dayvd.dayton.saic.com
  10. Xref: uunet vmsnet.sources.games:668
  11.  
  12. -+-+-+-+-+-+-+-+ START OF PART 7 -+-+-+-+-+-+-+-+
  13. V`20purpose.
  14. X`20*`20The`20author`20shall`20not`20be`20liable`20for`20any`20damages`20result
  15. Ving`20from`20the
  16. X`20*`20use`20of`20this`20software.`20`20By`20using`20this`20software,`20the
  17. V`20user`20agrees
  18. X`20*`20to`20these`20terms.
  19. X`20*/
  20. X
  21. X#include`20"ldb.h"
  22. X
  23. X/*----------------------------------------------------------------------
  24. X`20*`09newboard`20--`20set`20up`20a`20board`20array`20for`20a`20new`20game
  25. X`20*
  26. X`20*`20This`20function`20initializes`20a`20board`20array`20so`20that`20it`20is
  27. V`20set`20up
  28. X`20*`20properly`20for`20a`20new`20game.`20`20It`20is`20passed`20two`20characte
  29. Vrs`20that`20are
  30. X`20*`20used`20to`20draw`20the`20pieces`20for`20the`20board.`20`20C1`20is`20the
  31. V`20color`20for`20the
  32. X`20*`20upbound`20player,`20and`20c2`20is`20the`20color`20for`20the`20downbound
  33. V`20player.
  34. X`20*----------------------------------------------------------------------
  35. X`20*/
  36. X
  37. Xnewboard(b,c1,c2)
  38. Xboard`20b;
  39. Xchar`20c1,`20c2;
  40. X`7B
  41. Xint`20i;
  42. X
  43. Xfor`20(i`20=`200;`20i`20<`20BOARDSIZE;`20i++)`20`7B
  44. X`09b`5Bi`5D.qty`20=`200;`09`09`09/*`20init`20to`20empty`20*/
  45. X`09b`5Bi`5D.color`20=`20'-';`09`09/*`20init`20to`20invalid`20color`20*/
  46. X`09`7D
  47. Xb`5B1`5D.qty`20=`202;`09`09`09`09/*`202`20c1's`20on`201`20point`20*/
  48. Xb`5B1`5D.color`20=`20c1;
  49. Xb`5B6`5D.qty`20=`205;`09`09`09`09/*`205`20c2's`20on`206`20point`20*/
  50. Xb`5B6`5D.color`20=`20c2;
  51. Xb`5B8`5D.qty`20=`203;`09`09`09`09/*`203`20c2's`20on`208`20point`20*/
  52. Xb`5B8`5D.color`20=`20c2;
  53. Xb`5B12`5D.qty`20=`205;`09`09`09`09/*`205`20c1's`20on`2012`20point`20*/
  54. Xb`5B12`5D.color`20=`20c1;
  55. Xb`5B13`5D.qty`20=`205;`09`09`09`09/*`205`20c2's`20on`2013`20point`20*/
  56. Xb`5B13`5D.color`20=`20c2;
  57. Xb`5B17`5D.qty`20=`203;`09`09`09`09/*`203`20c1's`20on`2017`20point`20*/
  58. Xb`5B17`5D.color`20=`20c1;
  59. Xb`5B19`5D.qty`20=`205;`09`09`09`09/*`205`20c1's`20on`2019`20point`20*/
  60. Xb`5B19`5D.color`20=`20c1;
  61. Xb`5B24`5D.qty`20=`202;`09`09`09`09/*`202`20c2's`20on`2024`20point`20*/
  62. Xb`5B24`5D.color`20=`20c2;
  63. X`7D
  64. X
  65. X
  66. X/*----------------------------------------------------------------------
  67. X`20*`09copyboard`20--`20make`20a`20copy`20a`20board`20array
  68. X`20*
  69. X`20*`20This`20is`20a`20convenience`20function`20that`20copies`20an`20entire
  70. V`20board.`20The
  71. X`20*`20source`20is`20given`20as`20"f",`20and`20the`20destination`20as`20"t".
  72. X`20*----------------------------------------------------------------------
  73. X`20*/
  74. X
  75. Xcopyboard(f,t)
  76. Xboard`20f,`20t;
  77. X`7B
  78. Xint`20i;
  79. X
  80. Xfor`20(i`20=`200;`20i`20<`20BOARDSIZE;`20i++)
  81. X`09t`5Bi`5D`20=`20f`5Bi`5D;
  82. X`7D
  83. $ call unpack BOARD.C;1 560470732 ""
  84. $!
  85. $ create 'f'
  86. X/*`09check.c`09`0910/29/91
  87. X`20*
  88. X`20*`20Copyright`201991`20`20Perry`20R.`20Ross
  89. X`20*
  90. X`20*`20Permission`20to`20use,`20copy,`20modify,`20and`20distribute`20this`20so
  91. Vftware`20and`20its
  92. X`20*`20documentation`20without`20fee`20is`20hereby`20granted,`20subject`20to
  93. V`20the`20restrictions
  94. X`20*`20detailed`20in`20the`20README`20file,`20which`20is`20included`20here`20b
  95. Vy`20reference.
  96. X`20*`20Any`20other`20use`20requires`20written`20permission`20from`20the`20auth
  97. Vor.`20`20This`20software
  98. X`20*`20is`20distributed`20"as`20is"`20without`20any`20warranty,`20including
  99. V`20any`20implied
  100. X`20*`20warranties`20of`20merchantability`20or`20fitness`20for`20a`20particular
  101. V`20purpose.
  102. X`20*`20The`20author`20shall`20not`20be`20liable`20for`20any`20damages`20result
  103. Ving`20from`20the
  104. X`20*`20use`20of`20this`20software.`20`20By`20using`20this`20software,`20the
  105. V`20user`20agrees
  106. X`20*`20to`20these`20terms.
  107. X`20*/
  108. X
  109. X#include`20"ldb.h"
  110. X
  111. X/*======================================================================
  112. X`20*`20This`20file`20contains`20the`20functions`20that`20check`20for`20unused
  113. V`20moves.
  114. X`20*======================================================================
  115. X`20*/
  116. X
  117. X
  118. XPRIVATE`20int`20maxused,`20hiused,`20nlegal;
  119. X
  120. Xstruct`20legal`20*rmlegal();
  121. X
  122. X/*----------------------------------------------------------------------
  123. X`20*`09legalmoves`20--`20calculate`20all`20legal`20moves`20for`20a`20game
  124. X`20*
  125. X`20*`20This`20function`20is`20called`20after`20the`20dice`20have`20been`20roll
  126. Ved`20to`20search
  127. X`20*`20all`20possible`20combinations`20of`20moves`20to`20see`20which`20ones
  128. V`20are`20legal.
  129. X`20*`20While`20this`20function`20is`20working,`20it`20keeps`20a`20list`20of
  130. V`20legal`20moves,
  131. X`20*`20but`20this`20list`20is`20deleted`20before`20returning.`20`20For`20the
  132. V`20purposes
  133. X`20*`20of`20checking`20a`20move,`20it`20suffices`20to`20only`20keep`20the`20nu
  134. Vmber`20of`20usable
  135. X`20*`20dice`20and`20the`20highest`20numbered`20usable`20dice.`20`20Any`20move
  136. V`20that`20uses`20as
  137. X`20*`20many`20dice`20as`20can`20be`20used,`20and`20uses`20the`20highest`20usab
  138. Vle`20dice,`20is
  139. X`20*`20legal.`20`20These`20values`20are`20stored`20in`20the`20maxused`20and
  140. V`20hiused`20fields
  141. X`20*`20of`20the`20game`20structure.
  142. X`20*
  143. X`20*`20legalmoves`20performs`20an`20exhaustive`20search`20of`20all`20possible
  144. V`20move
  145. X`20*`20combinations,`20storing`20the`20combinations`20that`20are`20not`20rejec
  146. Vted
  147. X`20*`20by`20apply()`20in`20an`20instance`20of`20struct`20legal,`20which`20is
  148. V`20linked`20into
  149. X`20*`20the`20doubly-linked`20list`20headed`20by`20lhead.`20`20Note`20that,`20a
  150. Vt`20this`20point,
  151. X`20*`20this`20list`20may`20contain`20many`20combinations`20that`20are`20not
  152. V`20legal`20because
  153. X`20*`20they`20do`20not`20use`20all`20possible`20dice,`20or`20they`20use`20a
  154. V`20smaller`20dice`20when
  155. X`20*`20a`20larger`20one`20is`20usable.`20`20These`20illegal`20combinations`20a
  156. Vre`20trimmed`20from
  157. X`20*`20the`20list`20by`20trimunused()`20and`20trimlowused().`20`20Finally,`20d
  158. Vuplicate`20combinations
  159. X`20*`20are`20removed`20from`20the`20list`20by`20trimequal().`20`20Duplicate
  160. V`20moves`20are`20those`20that
  161. X`20*`20use`20the`20same`20rolls`20to`20move`20from`20the`20same`20points,`20bu
  162. Vt`20possibly`20in`20a
  163. X`20*`20different`20order,`20for`20example`20(3/8`201/6)`20and`20(1/6`203/8).
  164. V`20`20This`20allows
  165. X`20*`20detection`20of`20the`20case`20where`20there`20is`20only`20one`20legal
  166. V`20move,`20in`20which
  167. X`20*`20case`20this`20move`20is`20automatically`20applied`20(if`20rc.automove
  168. V`20is`20set).
  169. X`20*`20If`20the`20list`20is`20empty,`20there`20are`20no`20legal`20moves.`20
  170. V`20Otherwise,`20the
  171. X`20*`20highest`20roll`20used`20in`20the`20list`20is`20stored`20in`20g->hiused,
  172. V`20and`20the`20largest
  173. X`20*`20number`20of`20rolls`20used`20in`20the`20list`20is`20stored`20in`20g->ma
  174. Vxused.`20`20This`20information
  175. X`20*`20is`20used`20by`20check().
  176. X`20*----------------------------------------------------------------------
  177. X`20*/
  178. X
  179. Xlegalmoves(g)
  180. Xstruct`20game`20*g;
  181. X`7B
  182. Xstruct`20game`20tmp;
  183. Xint`20i;
  184. Xstruct`20legal`20*l;
  185. X
  186. Xtmp`20=`20*g;`09`09`09/*`20we`20don't`20want`20to`20change`20actual`20game`20*
  187. V/
  188. Xfor`20(i`20=`200;`20i`20<`204;`20tmp.mvs`5Bi++`5D.pt`20=`20-1);`09/*`20mark
  189. V`20all`20unused`20*/
  190. Xmaxused`20=`20-1;`09`09`09/*`20init`20to`20not`20all`20used`20*/
  191. Xhiused`20=`200;`09`09`09/*`20init`20to`200`20*/
  192. Xnlegal`20=`200;`09`09`09/*`20init`20to`20no`20legal`20moves*/
  193. Xlhead`20=`20NULL;
  194. Xltail`20=`20NULL;
  195. Xif`20(tmp.mvs`5B0`5D.roll`20==`20tmp.mvs`5B1`5D.roll)
  196. X`09scanmvs(`26tmp,0,3);`09/*`20there`20is`20only`20one`20ordering`20*/
  197. Xelse`20`7B
  198. X`09scanmvs(`26tmp,0,1);`09`09/*`20scan`20for`20one`20ordering`20*/
  199. X`09i`20=`20tmp.mvs`5B0`5D.roll;`09/*`20reverse`20rolls`20*/
  200. X`09tmp.mvs`5B0`5D.roll`20=`20tmp.mvs`5B1`5D.roll;
  201. X`09tmp.mvs`5B1`5D.roll`20=`20i;
  202. X`09for`20(i`20=`200;`20i`20<`204;`20tmp.mvs`5Bi++`5D.pt`20=`20-1);`09/*`20mark
  203. V`20all`20unused`20*/
  204. X`09scanmvs(`26tmp,0,1);`09`09/*`20scan`20for`20other`20ordering`20*/
  205. X`09`7D
  206. Xtrimunused();`09`09/*`20zap`20combinations`20that`20leave`20usable`20rolls`20u
  207. Vnused`20*/
  208. Xtrimlowused();`09`09/*`20zap`20combinations`20that`20use`20the`20wrong`20die
  209. V`20*/
  210. Xtrimequal();`09`09/*`20zap`20duplicates`20*/
  211. Xg->maxused`20=`20maxused;`09/*`20store`20maxused`20and`20hiused`20into`20the
  212. V`20game`20structure`20*/
  213. Xg->hiused`20=`20hiused;
  214. Xif`20(nlegal`20==`200)`20`7B`09/*`20check`20for`20no`20legal`20moves`20*/
  215. X`09if`20(g->dispmsg`20!=`20NULL)
  216. X`09`09free(g->dispmsg);
  217. X`09g->dispmsg`20=`20save("You`20don't`20have`20any`20legal`20moves.");
  218. X`09`7D
  219. Xelse`20if`20(nlegal`20==`201)`20`7B`09/*`20check`20for`20only`20one`20legal
  220. V`20move`20*/
  221. X`09if`20(g->dispmsg`20!=`20NULL)
  222. X`09`09free(g->dispmsg);
  223. X`09g->dispmsg`20=`20save("You`20only`20have`20one`20legal`20move.");
  224. X`09if`20(*rc.automove`20==`20'y')`20`7B`09/*`20you`20want`20the`20move`20appli
  225. Ved?`20*/
  226. X`09`09if`20(`20(lhead->nmove==0)`20`26`26`20(lhead->mvs`5B0`5D.roll!=g->mvs
  227. V`5B0`5D.roll))
  228. X`09`09`09g->mvs`5B1`5D`20=`20g->mvs`5B0`5D;
  229. X`09`09for`20(i`20=`200;`20i`20<=`20lhead->nmove;`20i++)`20`7B
  230. X`09`09`09g->mvs`5Bi`5D`20=`20lhead->mvs`5Bi`5D;
  231. X`09`09`09apply(g,WHO_ME,i,0,NULL);
  232. X`09`09`09`7D
  233. X`09`09`7D
  234. X`09`7D
  235. X
  236. X`09/*`20we`20have`20no`20use`20for`20the`20legal`20moves`20list,`20so`20free
  237. V`20it`20*/
  238. X`09/*`20maybe`20in`20the`20future`20we`20will`20have`20a`20use`20for`20it`20*/
  239. V
  240. X
  241. Xfor`20(l`20=`20lhead;`20l`20!=`20NULL;`20l`20=`20l->next)
  242. X`09free(l);
  243. Xlhead`20=`20NULL;
  244. Xltail`20=`20NULL;
  245. X`7D
  246. X
  247. X
  248. X/*----------------------------------------------------------------------
  249. X`20*`09scanmvs`20--`20search`20for`20all`20possible`20combinations`20of`20a
  250. V`20move
  251. X`20*
  252. X`20*`20This`20function`20takes`20a`20single`20die`20and`20tries`20to`20use`20i
  253. Vt`20on`20every`20point
  254. X`20*`20of`20the`20board.`20`20For`20every`20point`20it`20is`20successful,`20it
  255. V`20adds`20the
  256. X`20*`20combination`20to`20the`20legal`20moves`20list`20and`20performs`20a`20re
  257. Vcursive`20descent
  258. X`20*`20searching`20for`20all`20legal`20combinations`20of`20the`20remaining`20d
  259. Vice.
  260. X`20*----------------------------------------------------------------------
  261. X`20*/
  262. Xscanmvs(g,mn,max)
  263. Xstruct`20game`20*g;
  264. Xint`20mn,`20max;
  265. X`7B
  266. Xint`20i;
  267. Xboard`20sv;
  268. X
  269. Xcopyboard(g->board,sv);`09`09/*`20save`20the`20board`20*/
  270. Xfor`20(i`20=`200;`20i`20<=`2024;`20i++)`20`7B
  271. X`09if`20(i`20==`200)
  272. X`09`09g->mvs`5Bmn`5D.pt`20=`20BARPT(g->mydir);`09/*`20use`20correct`20barpt
  273. V`20*/
  274. X`09else
  275. X`09`09g->mvs`5Bmn`5D.pt`20=`20i;
  276. X`09if`20(apply(g,WHO_ME,mn,0,NULL)`20<`200)`09/*`20can't`20move`20from`20this
  277. V`20pt`20*/
  278. X`09`09continue;
  279. X`09addlegal(mn,g->mvs`5Bmn`5D.roll,g->mvs`5Bmn`5D.pt);`09/*`20add`20to`20list
  280. V`20*/
  281. X`09if`20(mn`20<`20max)
  282. X`09`09scanmvs(g,mn+1,max);`09`09/*`20try`20all`20remaining`20comb's`20*/
  283. X`09copyboard(sv,g->board);`09`09`09/*`20restore`20board`20*/
  284. X`09`7D
  285. X`7D
  286. X
  287. X
  288. X/*----------------------------------------------------------------------
  289. X`20*`09addlegal`20--`20add`20a`20move`20combination`20to`20the`20list
  290. X`20*
  291. X`20*`20This`20function`20adds`20an`20instance`20of`20struct`20legal`20to`20the
  292. V`20legal`20moves`20list.
  293. X`20*`20The`20arguments`20to`20addlegal`20only`20specify`20the`20usage`20of`20o
  294. Vne`20particular
  295. X`20*`20die,`20by`20specifying`20its`20"move`20number".`20`20For`20example,`20f
  296. Vor`20a`20roll`20of
  297. X`20*`205`202,`20the`205`20is`20move`20number`200`20and`20the`202`20is`20move
  298. V`20number`201.`20`20The`20usage
  299. X`20*`20of`20all`20lower`20numbered`20rolls`20is`20copied`20from`20the`20previo
  300. Vus`20entry`20in`20the
  301. X`20*`20moves`20list`20(since`20that`20entry`20was`20added`20by`20the`20higher
  302. V`20level`20scanmvs
  303. X`20*`20before`20the`20current`20scanmvs`20was`20called),`20and`20all`20higher-
  304. Vnumbered`20rolls
  305. X`20*`20are`20marked`20unused.
  306. X`20*----------------------------------------------------------------------
  307. X`20*/
  308. X
  309. Xaddlegal(mn,r,pt)
  310. Xint`20mn,`20r,`20pt;
  311. X`7B
  312. Xint`20i;
  313. Xstruct`20legal`20*n;
  314. X
  315. Xif`20(`20(n`20=`20(struct`20legal`20*)`20calloc(sizeof(struct`20legal),1))`20=
  316. V=`20NULL)
  317. X`09fatal("Out`20of`20memory!");
  318. Xclearmvs(n->mvs);
  319. Xif`20(ltail`20!=`20NULL)
  320. X`09for`20(i`20=`200;`20i`20<`20mn;`20i++)`09`09/*`20copy`20prefix`20from`20pre
  321. Vv`20move`20*/
  322. X`09`09n->mvs`5Bi`5D`20=`20ltail->mvs`5Bi`5D;
  323. Xn->mvs`5Bmn`5D.roll`20=`20r;`09`09/*`20copy`20in`20this`20move`20*/
  324. Xn->mvs`5Bmn`5D.pt`20=`20pt;
  325. Xn->next`20=`20NULL;`09`09`09/*`20this`20is`20end`20of`20list`20*/
  326. Xif`20(lhead`20==`20NULL)`20`7B`09`09/*`20link`20into`20list`20*/
  327. X`09n->prev`20=`20NULL;
  328. X`09lhead`20=`20n;
  329. X`09ltail`20=`20n;
  330. X`09`7D
  331. Xelse`20`7B
  332. X`09n->prev`20=`20ltail;
  333. X`09ltail->next`20=`20n;
  334. X`09ltail`20=`20n;
  335. X`09`7D
  336. Xn->himove`20=`200;
  337. Xfor`20(i`20=`200;`20i`20<=`20mn;`20i++)`09/*`20search`20for`20highest`20used
  338. V`20move`20*/
  339. X`09if`20(n->mvs`5Bi`5D.roll`20>`20n->himove)
  340. X`09`09n->himove`20=`20n->mvs`5Bi`5D.roll;
  341. Xif`20(mn`20>`20maxused)`09`09/*`20keep`20track`20of`20whether`20it`20is`20poss
  342. Vible`20*/
  343. X`09maxused`20=`20mn;`09/*`20to`20use`20all`20of`20the`20rolls`20*/
  344. Xnlegal++;
  345. Xn->nmove`20=`20mn;`09`09/*`20store`20number`20of`20moves`20used`20by`20this
  346. V`20entry`20*/
  347. X`7D
  348. X
  349. X
  350. X/*----------------------------------------------------------------------
  351. X`20*`09trimunused`20--`20remove`20moves`20that`20do`20not`20use`20all`20possib
  352. Vle`20rolls
  353. X`20*
  354. X`20*`20This`20function`20scans`20the`20move`20list`20and`20deletes`20combinati
  355. Vons`20that
  356. X`20*`20leave`20usable`20rolls`20unused.
  357. X`20*----------------------------------------------------------------------
  358. X`20*/
  359. X
  360. Xtrimunused()
  361. X`7B
  362. Xstruct`20legal`20*l;
  363. X
  364. Xl`20=`20lhead;
  365. Xwhile`20(l`20!=`20NULL)`20`7B
  366. X`09if`20(l->nmove`20<`20maxused)
  367. X`09`09l`20=`20rmlegal(l);
  368. X`09else
  369. X`09`09l`20=`20l->next;
  370. X`09`7D
  371. X`7D
  372. X
  373. X
  374. X/*----------------------------------------------------------------------
  375. X`20*`09trimlowused`20--`20remove`20moves`20that`20do`20not`20use`20the`20large
  376. Vst`20possible`20roll
  377. X`20*
  378. X`20*`20This`20function`20scans`20the`20move`20list`20and`20deletes`20combinati
  379. Vons`20that
  380. X`20*`20do`20not`20use`20the`20highest`20usable`20roll.
  381. X`20*----------------------------------------------------------------------
  382. X`20*/
  383. X
  384. Xtrimlowused()
  385. X`7B
  386. Xstruct`20legal`20*l;
  387. X
  388. Xl`20=`20lhead;
  389. Xwhile`20(l`20!=`20NULL)`20`7B
  390. X`09if`20(l->himove`20<`20hiused)
  391. X`09`09l`20=`20rmlegal(l);
  392. X`09else
  393. X`09`09l`20=`20l->next;
  394. X`09`7D
  395. X`7D
  396. X
  397. X
  398. X/*----------------------------------------------------------------------
  399. X`20*`09trimequal`20--`20remove`20duplicate`20moves
  400. X`20*
  401. X`20*`20This`20function`20scans`20the`20move`20list`20and`20deletes`20combinati
  402. Vons`20that
  403. X`20*`20are`20duplicates.
  404. X`20*----------------------------------------------------------------------
  405. X`20*/
  406. X
  407. Xtrimequal()
  408. X`7B
  409. Xstruct`20legal`20*l,`20*p;
  410. Xstruct`20mv`20m1`5B4`5D,`20m2`5B4`5D;
  411. Xint`20i,`20n;
  412. X
  413. Xfor`20(l`20=`20lhead;`20l`20!=`20NULL;`20l`20=`20l->next)`20`7B
  414. X`09extractmvs(l,m1);
  415. X`09n`20=`20l->nmove;
  416. X`09p`20=`20l->next;
  417. X`09while`20(p`20!=`20NULL)`20`7B
  418. X`09`09if`20(p->nmove`20!=`20n)`20`7B
  419. X`09`09`09p`20=`20p->next;
  420. X`09`09`09continue;
  421. X`09`09`09`7D
  422. X`09`09extractmvs(p,m2);
  423. X`09`09for`20(i`20=`200;`20i`20<=`20n;`20i++)
  424. X`09`09`09if`20((m1`5Bi`5D.roll`20!=`20m2`5Bi`5D.roll)`7C`7C(m1`5Bi`5D.pt`20!=
  425. V`20m2`5Bi`5D.pt))
  426. X`09`09`09`09break;
  427. X`09`09if`20(i`20<=`20n)
  428. X`09`09`09p`20=`20p->next;
  429. X`09`09else
  430. X`09`09`09p`20=`20rmlegal(p);
  431. X`09`09`7D
  432. X`09`7D
  433. X`7D
  434. X
  435. X
  436. X/*----------------------------------------------------------------------
  437. X`20*`09rmlegal`20--`20remove`20a`20struct`20legal`20from`20the`20move`20list
  438. X`20*
  439. X`20*`20This`20function`20unlinks`20an`20entry`20from`20the`20move`20list`20and
  440. V`20free's`20it.
  441. X`20*----------------------------------------------------------------------
  442. X`20*/
  443. X
  444. Xstruct`20legal`20*rmlegal(l)
  445. Xstruct`20legal`20*l;
  446. X`7B
  447. Xstruct`20legal`20*t;
  448. X
  449. Xt`20=`20l;
  450. Xif`20(l`20==`20lhead)`20`7B
  451. X`09lhead`20=`20l->next;
  452. X`09l`20=`20lhead;
  453. X`09`7D
  454. Xelse`20`7B
  455. X`09if`20(`20(l->prev->next`20=`20l->next)`20!=`20NULL)
  456. X`09`09l->next->prev`20=`20l->prev;
  457. X`09l`20=`20l->next;
  458. X`09`7D
  459. Xfree(t);
  460. Xnlegal--;
  461. Xreturn(l);
  462. X`7D
  463. X
  464. X
  465. X/*----------------------------------------------------------------------
  466. X`20*`09extractmvs`20--`20extract`20a`20struct`20legal`20into`20a`20struct`20mv
  467. V
  468. X`20*
  469. X`20*`20This`20function`20copies`20the`20information`20from`20a`20move`20list
  470. V`20entry`20into
  471. X`20*`20an`20instance`20of`20struct`20mv,`20and`20then`20sorts`20the`20rolls
  472. V`20in`20the`20struct`20mv
  473. X`20*`20by`20increasing`20dice`20value`20(and`20by`20increasing`20point`20numbe
  474. Vr`20for`20equal
  475. X`20*`20rolls).`20`20Sorting`20the`20rolls`20makes`20it`20easier`20for`20trimeq
  476. Vual`20to`20check
  477. X`20*`20for`20duplicate`20entries,`20it`20has`20no`20value`20as`20far`20as`20th
  478. Ve`20game`20is`20concerned.
  479. X`20*----------------------------------------------------------------------
  480. X`20*/
  481. X
  482. Xextractmvs(l,m)
  483. Xstruct`20legal`20*l;
  484. Xstruct`20mv`20*m;
  485. X`7B
  486. Xint`20i,`20n,`20s;
  487. Xstruct`20mv`20tmp;
  488. X
  489. Xclearmvs(m);
  490. Xfor`20(i`20=`200;`20i`20<=`20l->nmove;`20i++)`09`09/*`20extract`20the`20moves
  491. V`20*/
  492. X`09m`5Bi`5D`20=`20l->mvs`5Bi`5D;
  493. Xn`20=`20l->nmove;
  494. Xdo`20`7B`09`09`09/*`20sort`20by`20increasing`20roll`20then`20increasing`20poin
  495. Vt`20*/
  496. X`09s`20=`200;
  497. X`09for`20(i`20=`200;`20i`20<`20n;`20i++)`20`7B`09`09/*`20long`20live`20bubbles
  498. Vort`20*/
  499. X`09`09if`20(m`5Bi`5D.roll`20<`20m`5Bi+1`5D.roll)
  500. X`09`09`09continue;
  501. X`09`09else`20if`20(`20(m`5Bi`5D.roll`20==`20m`5Bi+1`5D.roll)`20`26`26`20(m`5Bi
  502. V`5D.pt`20<`20m`5Bi+1`5D.pt)`20)
  503. X`09`09`09continue;
  504. X`09`09tmp`20=`20m`5Bi`5D;
  505. X`09`09m`5Bi`5D`20=`20m`5Bi+1`5D;
  506. X`09`09m`5Bi+1`5D`20=`20tmp;
  507. X`09`09s`20=`201;
  508. X`09`09`7D
  509. X`09n--;
  510. X`09`7D`20while`20(s);
  511. X`7D
  512. X
  513. X
  514. X/*----------------------------------------------------------------------
  515. X`20*`09checkused`20--`20check`20that`20a`20move`20uses`20the`20correct`20rolls
  516. V
  517. X`20*
  518. X`20*`20This`20function`20is`20called`20just`20before`20a`20move`20is`20sent
  519. V`20to`20the
  520. X`20*`20opponent.`20`20It`20uses`20the`20values`20stored`20in`20g->maxused`20an
  521. Vd`20g->hiused
  522. X`20*`20to`20make`20sure`20that`20the`20move`20uses`20all`20usable`20rolls,`20a
  523. Vnd`20that`20it
  524. X`20*`20uses`20the`20highest`20usable`20roll.`20`20As`20a`20special`20case,`20i
  525. Vt`20considers
  526. X`20*`20to`20be`20legal`20any`20move`20where`20all`20pieces`20are`20borne`20off
  527. V.`20`20This
  528. X`20*`20takes`20care`20of`20the`20special`20case`20where`20there`20is`20one`20p
  529. Viece
  530. X`20*`20left`20to`20bear`20off,`20and`20two`20rolls,`20one`20of`20which`20is
  531. V`20too`20small
  532. X`20*`20to`20bear`20off.`20`20Normally,`20ldb`20would`20insist`20that`20the`20s
  533. Vmaller
  534. X`20*`20roll`20be`20used,`20then`20the`20larger`20one,`20so`20that`20both`20rol
  535. Vls
  536. X`20*`20would`20be`20used.`20`20If`20one`20roll`20is`20large`20enough`20to`20be
  537. Var`20the`20last
  538. X`20*`20man`20off,`20though,`20there`20is`20no`20need`20to`20force`20the`20othe
  539. Vr`20roll`20to`20be`20used.
  540. X`20*----------------------------------------------------------------------
  541. X`20*/
  542. X
  543. Xcheckused(g)
  544. Xstruct`20game`20*g;
  545. X`7B
  546. Xint`20h,`20i;
  547. X
  548. Xif`20(g->board`5BOFFPT(g->mydir)`5D.qty`20==`2015)`09/*`20special`20case,`20if
  549. V`20all`20pcs`20*/
  550. X`09return(0);`09`09/*`20are`20off,`20then`20all`20rolls`20have`20been`20used
  551. V`20*/
  552. Xh`20=`200;
  553. Xfor`20(i`20=`200;`20i`20<=`20g->maxused;`20i++)`20`7B
  554. X`09if`20(g->mvs`5Bi`5D.pt`20<`200)`20`7B
  555. X`09`09FeMessage("You`20left`20a`20roll`20unused.");
  556. X`09`09return(1);
  557. X`09`09`7D
  558. X`09if`20(h`20<`20g->mvs`5Bi`5D.roll)
  559. X`09`09h`20=`20g->mvs`5Bi`5D.roll;
  560. X`09`7D
  561. Xif`20(g->hiused`20>`20h)`20`7B
  562. X`09FeMessage("You`20can`20use`20the`20higher`20roll.");
  563. X`09return(1);
  564. X`09`7D
  565. Xreturn(0);
  566. X`7D
  567. $ call unpack CHECK.C;1 421838177 ""
  568. $!
  569. $ create 'f'
  570. X/*`09control.c`09`099/12/91
  571. X`20*
  572. X`20*`20Copyright`201991`20`20Perry`20R.`20Ross
  573. X`20*
  574. X`20*`20Permission`20to`20use,`20copy,`20modify,`20and`20distribute`20this`20so
  575. Vftware`20and`20its
  576. X`20*`20documentation`20without`20fee`20is`20hereby`20granted,`20subject`20to
  577. V`20the`20restrictions
  578. X`20*`20detailed`20in`20the`20README`20file,`20which`20is`20included`20here`20b
  579. Vy`20reference.
  580. X`20*`20Any`20other`20use`20requires`20written`20permission`20from`20the`20auth
  581. Vor.`20`20This`20software
  582. X`20*`20is`20distributed`20"as`20is"`20without`20any`20warranty,`20including
  583. V`20any`20implied
  584. X`20*`20warranties`20of`20merchantability`20or`20fitness`20for`20a`20particular
  585. V`20purpose.
  586. X`20*`20The`20author`20shall`20not`20be`20liable`20for`20any`20damages`20result
  587. Ving`20from`20the
  588. X`20*`20use`20of`20this`20software.`20`20By`20using`20this`20software,`20the
  589. V`20user`20agrees
  590. X`20*`20to`20these`20terms.
  591. X`20*/
  592. X
  593. X#include`20"ldb.h"
  594. X
  595. X/*----------------------------------------------------------------------
  596. X`20*`09control`20--`20control`20a`20game
  597. X`20*
  598. X`20*`20This`20function`20is`20called`20to`20process`20the`20-control`20command
  599. V`20line`20option.
  600. X`20*`20It`20currently`20allows`20the`20following:
  601. X`20*`20`20`20`20-`09The`20board`20may`20be`20inverted.`20`20The`20points`20are
  602. V`20still`20numbered`20the
  603. X`20*`09same,`20the`20board`20is`20merely`20drawn`20upside`20down.`20`20This
  604. V`20can`20help`20users
  605. X`20*`09who`20are`20playing`20a`20number`20of`20games`20simultaneously`20by`20a
  606. Vllowing`20him
  607. X`20*`09to`20make`20all`20of`20his`20games`20move`20in`20the`20same`20direction
  608. V`20on`20the`20screen.
  609. X`20*`20`20`20`20-`20The`20last`20packet`20sent`20may`20be`20resent.`20`20This
  610. V`20is`20useful`20when`20moves
  611. X`20*`09are`20lost`20in`20the`20mail,`20or`20if`20players`20forget`20whose`20tu
  612. Vrn`20it`20is.
  613. X`20*`09Ldb`20rejects`20packets`20that`20have`20already`20been`20received,`20so
  614. V`20both
  615. X`20*`09players`20may`20simply`20resend`20their`20last`20packet,`20and`20ldb
  616. V`20will`20display
  617. X`20*`09the`20board`20to`20the`20player`20who`20is`20supposed`20to`20move.
  618. X`20*----------------------------------------------------------------------
  619. X`20*/
  620. X
  621. Xcontrol()
  622. X`7B
  623. Xregister`20struct`20game`20*g;
  624. Xstatic`20char`20*m`5B`5D`20=`20`7B"Invert","Resend","Get`20Resend","Screen`20D
  625. Vump","Delete`20Game",
  626. X`09`09`09"Next`20Game","Quit",NULL`7D;
  627. Xchar`20buf`5B60`5D,`20c,`20done;
  628. Xint`20mod;
  629. Xchar`20pm`20=`20'`5C0';
  630. Xstatic`20char`20oldmsg`5B`5D`20=`20"Your`20opponent's`20ldb`20does`20not`20sup
  631. Vport`20resend`20requests.";
  632. Xstatic`20char`20gmover`5B`5D`20=`20"This`20game`20is`20over`20--`20you`20canno
  633. Vt`20request`20a`20resend.";
  634. X
  635. Xif`20(ghead`20==`20NULL)`20`7B
  636. X`09printf("You`20don't`20have`20any`20games`20in`20progress.`5Cn");
  637. X`09printf("Use`20the`20-start`20option`20to`20start`20one.`5Cn");
  638. X`09usage(0);
  639. X`09ldbexit(STAT_ABORT);
  640. X`09`7D
  641. Xmod`20=`200;`09`09`09`09/*`20init`20to`20no`20mods`20*/
  642. Xrc.chkpt`20=`20"no";`09`09`09/*`20disable`20checkpoint`20in`20sendpkt`20*/
  643. XFeInitialize();`09`09`09`09/*`20initialize`20front`20end`20*/
  644. XFeDrawScreen();`09`09`09`09/*`20draw`20board`20outline`20*/
  645. Xdone`20=`200;
  646. Xfor`20(g`20=`20ghead;`20(done`20<`202)`20`26`26`20(g`20!=`20NULL);`20g`20=`20g
  647. V->next)`20`7B/*`20for`20all`20games`20*/
  648. X`09g->curbd`20=`20BD_CUR;`09`09/*`20make`20sure`20we`20draw`20the`20current
  649. V`20bd`20*/
  650. X`09FeDrawGame(g);
  651. X`09FeDrawMenu(m);
  652. X`09sprintf(buf,"Current`20state:`20%s",states`5Bg->state`5D);
  653. X`09FeMessage(buf);
  654. X`09done`20=`200;
  655. X`09GameState`20=`20STATE_CONTROL;
  656. X`09while`20(!`20done)`20`7B
  657. X`09`09c`20=`20FeMenu(m,0,0,"`20`5Cn`5Cr",pm);
  658. X`09`09pm`20=`20c;
  659. X`09`09switch`20(c)`20`7B
  660. X`09`09case`20'I':`09`09`09/*`20invert`20board`20*/
  661. X`09`09`09g->flags`20`5E=`20F_INVERT;`09/*`20toggle`20invert`20bit`20*/
  662. X`09`09`09FeDrawGame(g);`09`09/*`20redraw`20the`20screen`20*/
  663. X`09`09`09mod++;`09`09`09/*`20games`20have`20been`20modified`20*/
  664. X`09`09`09break;
  665. X`09`09case`20'R':`09`09`09/*`20resend`20last`20packet`20*/
  666. X`09`09`09if`20((g->state>=OPSTATES)`26`26(g->state!=ST_GAMEOVER))`20`7B
  667. X`09`09`09`09FeMessage("Can't`20resend`20--`20it`20is`20your`20move.");
  668. X`09`09`09`09break;
  669. X`09`09`09`09`7D
  670. X`09`09`09resendpkt(g);
  671. X`09`09`09FeMessage("Last`20packet`20re-sent.");
  672. X`09`09`09break;
  673. X`09`09case`20'G':
  674. X`09`09`09if`20(g->state`20==`20ST_GAMEOVER)`20`7B
  675. X`09`09`09`09FeMessage(gmover);
  676. X`09`09`09`09break;
  677. X`09`09`09`09`7D
  678. X`09`09`09if`20(g->opver`20<`20110)`20`7B
  679. X`09`09`09`09FeMessage(oldmsg);
  680. X`09`09`09`09break;
  681. X`09`09`09`09`7D
  682. X`09`09`09sendpkt(g,RESEND);
  683. X`09`09`09FeMessage("Resend`20requested.");
  684. X`09`09`09break;
  685. X`09`09case`20'S':`09`09`09/*`20dump`20screen`20*/
  686. X`09`09`09FeMessage(buf);`09`09/*`20restore`20state`20msg`20*/
  687. X`09`09`09FeDumpScreen("ldb_screen.dmp");`09/*`20do`20the`20dump`20*/
  688. X`09`09`09FeMessage("Screen`20dumped`20to`20ldb_screen.dmp");
  689. X`09`09`09break;
  690. X`09`09case`20'D':`09`09`09/*`20delete`20game`20*/
  691. X`09`09`09mod++;`09`09`09/*`20games`20have`20been`20modified`20*/
  692. X`09`09`09if`20(g->flags`20`26`20F_DELETE)`20`7B`09/*`20undelete`20*/
  693. X`09`09`09`09g->flags`20`26=`20`7EF_DELETE;
  694. X`09`09`09`09FeMessage("Game`20undeleted.");
  695. X`09`09`09`09`7D
  696. X`09`09`09else`20`7B
  697. X`09`09`09`09g->flags`20`7C=`20F_DELETE;`09/*`20delete`20*/
  698. X`09`09`09`09FeMessage(
  699. X`09`09`09`09`20"Game`20deleted`20--`20press`20D`20again`20to`20undelete.");
  700. X`09`09`09`09`7D
  701. X`09`09`09break;
  702. X`09`09case`20'Q':`09`09`09/*`20exit`20ldb`20*/
  703. X`09`09`09done`20=`202;`09`09/*`202`20means`20Really`20done`20*/
  704. X`09`09`09break;
  705. X`09`09case`20'`20':
  706. X`09`09case`20'`5Cn':
  707. X`09`09case`20'`5Cr':
  708. X`09`09`09FeOnMenuItem(m,'N');`09/*`20highlight`20Next`20Game`20item`20*/
  709. X`09`09`09pm`20=`20'N';`09`09/*`20remember`20to`20unhighlight`20*/
  710. X`09`09`09/*`20Fall`20through`20*/
  711. X`09`09case`20'N':
  712. X`09`09`09done`20=`201;`09/*`201`20means`20just`20done`20with`20this`20game`20*
  713. V/
  714. X`09`09`09break;`09`09/*`20go`20to`20next`20game`20*/
  715. X`09`09`09`7D
  716. X`09`09`7D
  717. X`09`7D
  718. XFeFinishSession();
  719. Xwhile`20(mod)`20`7B
  720. X`09printf("Save`20changes?`20`5Byn`5D:`20");
  721. X`09fflush(stdout);
  722. X`09if`20(`20(`20(c`20=`20getchar())`20==`20'y')`20`7C`7C`20(c`20==`20'Y')`20)
  723. V`20`7B
  724. X`09`09writegames(rc.gfile,rc.gbackup,rc.pfile);
  725. X`09`09break;
  726. X`09`09`7D
  727. X`09if`20(`20(c`20==`20'n')`20`7C`7C`20(c`20==`20'N')`20)`20`7B
  728. X`09`09printf("Changes`20discarded.`5Cn");
  729. X`09`09break;
  730. X`09`09`7D
  731. X`09if`20(`20(c`20!=`20'`5Cn')`20`26`26`20(c`20!=`20EOF)`20)
  732. X`09`09while`20(`20(`20(c`20=`20getchar())`20!=`20'`5Cn')`20`26`26`20(c`20!=
  733. V`20EOF)`20);
  734. X`09printf("Please`20respond`20with`20y`20or`20n.`5Cn");
  735. X`09`7D
  736. X`7D
  737. X
  738. X
  739. X/*----------------------------------------------------------------------
  740. X`20*`09recons`20--`20reconstruct`20games`20from`20opponent's`20.ldbdata
  741. X`20*
  742. X`20*`20This`20function`20allows`20a`20game`20to`20be`20reconstructed`20when
  743. V`20the`20.ldbdata
  744. X`20*`20file`20has`20been`20irretrievably`20lost.`20`20The`20opponent`20merely
  745. V`20mails
  746. X`20*`20his`20.ldbdata`20file,`20and`20we`20scan`20it`20for`20all`20the`20impor
  747. Vtant`20information.
  748. X`20*`20Games`20that`20are`20in`20the`20OPSTART`20or`20GAMEOVER`20states`20cann
  749. Vot`20be`20reconstructed
  750. X`20*`20due`20to`20the`20lack`20of`20adequate`20information,`20but`20these`20ga
  751. Vmes`20either`20have
  752. X`20*`20not`20started`20or`20are`20already`20over.`20`20If`20the`20game`20is
  753. V`20in`20state`20OPSTART
  754. X`20*`20because`20the`20next`20game`20of`20a`20match`20is`20being`20started,
  755. V`20the`20match`20can
  756. X`20*`20be`20rescued`20by`20starting`20a`20new`20match`20that`20plays`20up`20to
  757. V`20the`20number`20of
  758. X`20*`20points`20remaining`20in`20the`20old`20match.
  759. X`20*
  760. X`20*`20Before`20sending`20the`20.ldbdata`20file,`20your`20opponent`20should
  761. V`20incorporate
  762. X`20*`20any`20moves`20you`20sent`20before`20you`20lost`20your`20file.`20`20If
  763. V`20your`20move`20is`20lost
  764. X`20*`20as`20well,`20it`20may`20be`20necessary`20for`20you`20to`20replay`20your
  765. V`20last`20move,`20with
  766. X`20*`20a`20new`20roll.`20`20This`20should`20not`20be`20considered`20cheating,
  767. V`20as`20it`20is`20unavoidable.
  768. X`20*`20Alternatively,`20if`20you`20remember`20your`20last`20roll,`20you`20coul
  769. Vd`20plug`20the`20rolls
  770. X`20*`20into`20your`20.ldbdata`20after`20the`20reconstruct.
  771. X`20*
  772. X`20*`20You`20will`20have`20to`20edit`20the`20mail`20header`20off`20the`20file
  773. V`20before`20feeding`20it
  774. X`20*`20to`20-reconstruct.`20`20The`20first`20line`20of`20the`20file`20MUST`20b
  775. Ve`20the`20first`20line
  776. X`20*`20of`20the`20data`20file.
  777. X`20*
  778. X`20*`20Because`20data`20fields`20are`20frequently`20added`20to`20data`20files
  779. V`20between
  780. X`20*`20revisions,`20-reconstruct`20is`20only`20guaranteed`20to`20work`20when
  781. V`20you
  782. X`20*`20are`20using`20the`20same`20ldb`20revision`20as`20your`20opponent.
  783. X`20*
  784. X`20*`20If`20you`20started`20the`20game`20being`20reconstructed,`20and`20you
  785. V`20used`20the
  786. X`20*`20-myaddr`20argument`20when`20you`20started`20it,`20you`20will`20need`20t
  787. Vo`20use
  788. X`20*`20the`20-myaddr`20argument`20when`20you`20reconstruct`20it.
  789. X`20*----------------------------------------------------------------------
  790. X`20*/
  791. X
  792. Xrecons(file)
  793. Xchar`20*file;
  794. X`7B
  795. XFILE`20*fp;
  796. Xchar`20c;
  797. Xint`20i,`20j;
  798. Xstruct`20mv`20m;
  799. Xstruct`20game`20*g;
  800. Xstruct`20people`20*p;
  801. Xchar`20*s;
  802. Xchar`20buf`5B80`5D;
  803. X
  804. Xif`20(`20(fp`20=`20fopen(file,"r"))`20==`20NULL)`20`7B
  805. X`09fprintf(stderr,"ERROR:`20cannot`20open`20%s`20for`20reconstruct`5Cn",file);
  806. V
  807. X`09ldbexit(STAT_ABORT);
  808. X`09`7D
  809. Xg`20=`20addgame();`09`09`09/*`20get`20a`20game`20structure`20*/
  810. Xwhile`20(`20(c`20=`20getc(fp))`20!=`20EOF)`20`7B
  811. X`09ungetc(c,fp);`09`09`09/*`20put`20char`20back`20*/
  812. X`09nvscan(fp,nv_gfile,g);
  813. X`09if`20(strcmp(g->opaddr,rc.myaddr))`09/*`20this`20game`20wasn't`20with`20me
  814. V`20*/
  815. X`09`09continue;
  816. X`09if`20(`20(g->state`20==`20ST_OPSTART)`20`7C`7C`20(g->state`20==`20ST_GAMEOV
  817. VER)`20)
  818. X`09`09continue;`09`09/*`20can't`20handle`20these`20*/
  819. X`09printf("`5Cn---`20Reconstruct`20found`20game`20%s`20---`5Cn",g->gameid);
  820. X`09s`20=`20g->gameid;`09`09`09/*`20copy`20out`20gameid`20*/
  821. X`09g->gameid`20=`20"";`09`09`09/*`20temporarily`20delete`20gameid`20field`20*/
  822. V
  823. X`09if`20(findgame(s)`20!=`20NULL)`20`7B
  824. X`09`09printf("ERROR:`20This`20game`20already`20exists`20--`20ignoring.`5Cn");
  825. X`09`09continue;
  826. X`09`09`7D
  827. X`09g->gameid`20=`20s;`09`09`09/*`20restore`20gameid`20field`20*/
  828. X`09printf("Enter`20opponent`20address`20or`20alias:`20");
  829. X`09if`20(fgets(buf,sizeof(buf),stdin)`20==`20NULL)`20`7B
  830. X`09`09printf("`5Cn---`20Reconstruct`20deleting`20game`20%s`20---`5Cn",g->gamei
  831. Vd);
  832. X`09`09continue;
  833. X`09`09`7D
  834. X`09buf`5Bstrlen(buf)-1`5D`20=`20'`5C0';`09`09/*`20clobber`20newline`20*/
  835. X`09if`20(`20(p`20=`20findppl(buf,P_ADDR`7CP_ALIAS))`20==`20NULL)`20`7B/*`20not
  836. V`20in`20ppl`20file`20*/
  837. X`09`09g->opaddr`20=`20save(buf);`09`09/*`20save`20address`20in`20game`20*/
  838. X`09`09printf("Enter`20opponent`20name:`20");
  839. X`09`09if`20(fgets(buf,sizeof(buf),stdin)`20==`20NULL)`20`7B
  840. X`09`09`09printf("`5Cn---`20Reconstruct`20deleting`20game`20%s`20---`5Cn",
  841. X`09`09`09`09g->gameid);
  842. X`09`09`09continue;
  843. X`09`09`09`7D
  844. X`09`09buf`5Bstrlen(buf)-1`5D`20=`20'`5C0';`09/*`20clobber`20newline`20*/
  845. X`09`09g->opname`20=`20save(buf);`09`09/*`20save`20opponent's`20name`20*/
  846. X`09`09newppl(g);`09`09/*`20generate`20a`20new`20people`20rec`20*/
  847. X`09`09`7D
  848. X`09else`20`7B`09`09`09`09/*`20it`20was`20an`20alias`20*/
  849. X`09`09g->opname`20=`20save(p->name);`09/*`20copy`20name`20from`20people`20rec
  850. V`20*/
  851. X`09`09g->opaddr`20=`20save(p->addr);`09/*`20address`20too`20*/
  852. X`09`09g->ppl`20=`20p;`09`09`09/*`20store`20people`20pointer`20*/
  853. X`09`09`7D
  854. X`09g->dispmsg`20=`20NULL;
  855. X`09g->myaddr`20=`20save(rc.myaddr);
  856. X`09for`20(i`20=`200;`20i`20<`204;`20i++)`20`7B
  857. X`09`09g->blot`5Bi`5D`20=`200;`09`09/*`20clear`20blot`20array`20*/
  858. X`09`09m`20=`20g->mvs`5Bi`5D;`09`09/*`20switch`20mvs`20and`20opmvs`20fields`20*
  859. V/
  860. X`09`09g->mvs`5Bi`5D`20=`20g->opmvs`5Bi`5D;
  861. X`09`09g->opmvs`5Bi`5D`20=`20m;
  862. X`09`09`7D
  863. X`09for`20(i`20=`200;`20i`20<`206;`20i++)`20`7B
  864. X`09`09j`20=`20g->rolls`5Bi`5D;`09/*`20switch`20rolls`20and`20oprolls`20*/
  865. X`09`09g->rolls`5Bi`5D`20=`20g->oprolls`5Bi`5D;
  866. X`09`09g->oprolls`5Bi`5D`20=`20j;
  867. X`09`09j`20=`20g->doubles`5Bi`5D;`09/*`20switch`20doubles`20and`20opdoubles`20*
  868. V/
  869. X`09`09g->doubles`5Bi`5D`20=`20g->opdoubles`5Bi`5D;
  870. X`09`09g->opdoubles`5Bi`5D`20=`20j;
  871. X`09`09`7D
  872. X`09i`20=`20g->mydir;`09`09`09/*`20switch`20mydir`20and`20opdir`20*/
  873. X`09g->mydir`20=`20g->opdir;
  874. X`09g->opdir`20=`20i;
  875. X`09i`20=`20g->mycolor;`09`09`09/*`20switch`20mycolor`20and`20opcolor`20*/
  876. X`09g->mycolor`20=`20g->opcolor;
  877. X`09g->opcolor`20=`20i;
  878. X`09s`20=`20g->mycmt;
  879. X`09g->mycmt`20=`20g->opcmt;
  880. X`09g->opcmt`20=`20s;
  881. X`09s`20=`20g->mycmt2;
  882. X`09g->mycmt2`20=`20g->opcmt2;
  883. X`09g->opcmt2`20=`20s;
  884. X`09i`20=`20g->mcurrent`5BWHO_ME`5D;`09`09/*`20switch`20match`20scores`20*/
  885. X`09g->mcurrent`5BWHO_ME`5D`20=`20g->mcurrent`5BWHO_OPP`5D;
  886. X`09g->mcurrent`5BWHO_OPP`5D`20=`20i;
  887. X`09copyboard(g->mybd,g->opbd);`09/*`20my`20before`20bd`20==`20op's`20after`20b
  888. Vd`20*/
  889. X`09if`20(g->state`20<`20OPSTATES)`20`7B`09/*`20I'm`20sending`20next`20*/
  890. X`09`09g->seq++;`09/*`20set`20seq#`20to`20what`20opp`20expects`20in`20next`20pk
  891. Vt`20*/
  892. X`09`09copyboard(g->board,g->mybd);`09/*`20my`20after`20bd`20==`20cur`20board
  893. V`20*/
  894. X`09`09`7D
  895. X`09else`20`7B`09`09`09`09/*`20he's`20sending`20next`20*/
  896. X`09`09g->seq--;`09/*`20set`20seq#`20to`20what`20we're`20expecting`20*/
  897. X`09`09copyboard(g->mybd,g->board);`09/*`20erase`20his`20moves`20*/
  898. X`09`09`7D
  899. X`09g->lastop`20=`20START;`09`09/*`20has`20to`20be`20set`20to`20something`20*/
  900. X`09switch`20(g->state)`20`7B`09`09/*`20invert`20state`20*/
  901. X`09case`20ST_OPTURN:
  902. X`09`09g->state`20=`20ST_MYTURN;`09/*`20it's`20my`20turn`20*/
  903. X`09`09break;
  904. X`09case`20ST_OPACCEPT:
  905. X`09`09g->state`20=`20ST_MYACCEPT;`09/*`20waiting`20for`20me`20to`20accept`20do
  906. Vuble`20*/
  907. X`09`09break;
  908. X`09case`20ST_MYTURN:
  909. X`09case`20ST_MYMOVE:
  910. X`09`09g->state`20=`20ST_OPTURN;`09/*`20waiting`20for`20op`20to`20move`20*/
  911. X`09`09break;
  912. X`09case`20ST_MYACCEPT:
  913. X`09`09g->state`20=`20ST_OPACCEPT;`09/*`20waiting`20for`20op`20to`20accept`20do
  914. Vuble`20*/
  915. X`09`09break;
  916. X`09`09`7D
  917. X`09printf("---`20Reconstructed`20game`20%s`20---`5Cn",g->gameid);
  918. X`09g`20=`20addgame();`09`09/*`20get`20new`20buffer`20to`20read`20into`20*/
  919. X`09`7D
  920. Xdeletegame(g);`09`09`09/*`20get`20rid`20of`20buffer`20*/
  921. Xwritegames(rc.gfile,rc.gbackup,rc.pfile);`09/*`20save`20new`20games`20*/
  922. X`7D
  923. $ call unpack CONTROL.C;1 155352402 ""
  924. $!
  925. $ create 'f'
  926. X/*`20dohelp.c`09`093/27/92
  927. X`20*
  928. X`20*`20Copyright`201992`20`20Earle`20F.`20Ake
  929. X`20*
  930. X`20*`20Permission`20to`20use,`20copy,`20modify,`20and`20distribute`20this`20so
  931. Vftware`20and`20its
  932. X`20*`20documentation`20without`20fee`20is`20hereby`20granted,`20subject`20to
  933. V`20the`20restrictions
  934. X`20*`20detailed`20in`20the`20README`20file,`20which`20is`20included`20here`20b
  935. Vy`20reference.
  936. X`20*`20Any`20other`20use`20requires`20written`20permission`20from`20the`20auth
  937. Vor.`20`20This`20software
  938. X`20*`20is`20distributed`20"as`20is"`20without`20any`20warranty,`20including
  939. V`20any`20implied
  940. X`20*`20warranties`20of`20merchantability`20or`20fitness`20for`20a`20particular
  941. V`20purpose.
  942. X`20*`20The`20author`20shall`20not`20be`20liable`20for`20any`20damages`20result
  943. Ving`20from`20the
  944. X`20*`20use`20of`20this`20software.`20`20By`20using`20this`20software,`20the
  945. V`20user`20agrees
  946. X`20*`20to`20these`20terms.
  947. X`20*
  948. X`20*`20Original`20coding`20by`20Earle`20F.`20Ake`20<ake@dayton.saic.com>`20-
  949. V`2027`20March`201992.
  950. X`20*
  951. X`20*/
  952. X
  953. X#include`20"ldb.h"
  954. X
  955. X/*----------------------------------------------------------------------
  956. X`20*`09dohelp`20--`20display`20online`20help`20for`20the`20user
  957. X`20*
  958. X`20*`20This`20function`20creates`20a`20new`20curses`20window`20and`20displays
  959. V`20command`20help
  960. X`20*`20to`20the`20user.`20`20The`20user`20then`20presses`20any`20key`20to`20re
  961. Vturn`20to`20the`20game.
  962. X`20*----------------------------------------------------------------------
  963. X`20*/
  964. X
  965. Xdohelp()
  966. X`7B
  967. XWINDOW`20*helpwin;
  968. Xint`20row;
  969. X
  970. Xhelpwin`20=`20newwin(0,0,0,0);`09/*`20get`20a`20new`20window`20to`20post`20hel
  971. Vp`20to`20*/
  972. X
  973. Xmvwaddstr(helpwin,0,30,"ldb`20Command`20Summary");`09`09/*`20print`20title`20*
  974. V/
  975. Xmvwaddstr(helpwin,1,30,"-------------------");`09`09/*`20underline`20title`20*
  976. V/
  977. Xrow`20=`203;
  978. X
  979. Xif(GameState`20==`20STATE_MYACPT)`20`7B
  980. X`09mvwaddstr(helpwin,row,0,"Accept`20-");
  981. X`09mvwaddstr(helpwin,row++,15,"Accept`20the`20double`20and`20the`20game`20cont
  982. Vinues.");
  983. X`09row++;
  984. X`09mvwaddstr(helpwin,row,0,"Decline`20-");
  985. X`09mvwaddstr(helpwin,row++,15,"You`20decline`20the`20double`20and`20lose`20the
  986. V`20game`20for`20the`20current");
  987. X`09mvwaddstr(helpwin,row++,15,"game`20value.");
  988. X`09row++;
  989. X`09`7D
  990. X
  991. Xif(GameState`20==`20STATE_CONTROL)`20`7B
  992. X`09mvwaddstr(helpwin,row,0,"Invert`20-");
  993. X`09mvwaddstr(helpwin,row++,15,"Invert`20the`20board`20for`20this`20game.`20
  994. V`20Pressing`20Invert`20again`20will");
  995. X`09mvwaddstr(helpwin,row++,15,"put`20it`20back`20to`20normal.`20`20Inverting
  996. V`20the`20board`20does`20not`20affect");
  997. X`09mvwaddstr(helpwin,row++,15,"point`20numbering.");
  998. X`09row++;
  999. X`09mvwaddstr(helpwin,row,0,"Resend`20-");
  1000. X`09mvwaddstr(helpwin,row++,15,"Resend`20your`20last`20move`20command`20to`20yo
  1001. Vur`20opponent.");
  1002. X`09row++;
  1003. X`09mvwaddstr(helpwin,row,0,"Get`20Resend`20-");
  1004. X`09mvwaddstr(helpwin,row++,15,"Request`20a`20resend`20from`20your`20opponent."
  1005. V);
  1006. X`09row++;
  1007. X`09mvwaddstr(helpwin,row,0,"Screen`20Dump`20-");
  1008. X`09mvwaddstr(helpwin,row++,15,"Dump`20the`20screen`20to`20ldb_screen.dmp");
  1009. X`09row++;
  1010. X`09mvwaddstr(helpwin,row,0,"Delete`20Game`20-");
  1011. X`09mvwaddstr(helpwin,row++,15,"This`20marks`20a`20game`20for`20deletion.`20
  1012. V`20The`20game`20is`20not`20deleted");
  1013. X`09mvwaddstr(helpwin,row++,15,"until`20you`20quit`20and`20you`20can`20undelete
  1014. V`20it`20by`20pressing`20D`20again.");
  1015. X`09row++;
  1016. X`09`7D
  1017. X
  1018. Xif(GameState`20==`20STATE_MYTURN)`20`7B
  1019. X`09mvwaddstr(helpwin,row,0,"Roll`20-");
  1020. X`09mvwaddstr(helpwin,row++,15,"Roll`20the`20dice.`20`20Your`20roll`20will`20ap
  1021. Vpear`20in`20your`20move`20block.");
  1022. X`09mvwaddstr(helpwin,row++,15,"You`20will`20see`20two`20numbers`20appear`20or
  1023. V`20four`20if`20you`20have");
  1024. X`09mvwaddstr(helpwin,row++,15,"rolled`20doubles.");
  1025. X`09row++;
  1026. X`09mvwaddstr(helpwin,row,0,"Double`20-");
  1027. X`09mvwaddstr(helpwin,row++,15,"Choose`20to`20double`20the`20current`20game`20v
  1028. Value.`20`20A`20message`20will");
  1029. X`09mvwaddstr(helpwin,row++,15,"be`20sent`20to`20your`20opponent`20and`20ldb
  1030. V`20then`20will`20automatically");
  1031. X`09mvwaddstr(helpwin,row++,15,"select`20roll.");
  1032. X`09row++;
  1033. X`09`7D
  1034. X
  1035. Xif(GameState`20==`20STATE_MYMOVE)`20`7B
  1036. X`09mvwaddstr(helpwin,row,0,"Point`20-");
  1037. X`09mvwaddstr(helpwin,row++,15,"Attempt`20to`20make`20the`20point`20your`20last
  1038. V`20move`20ended`20on.");
  1039. X`09row++;
  1040. X`09mvwaddstr(helpwin,row,0,"Off`20-");
  1041. X`09mvwaddstr(helpwin,row++,15,"Bear`20off`20a`20piece`20by`20using`20the`20nex
  1042. Vt`20UNUSED`20roll.");
  1043. X`09row++;
  1044. X`09mvwaddstr(helpwin,row,0,"Reset`20-");
  1045. X`09mvwaddstr(helpwin,row++,15,"Reset`20your`20rolls`20to`20UNUSED`20and`20put
  1046. V`20the`20board`20back`20how`20it`20was");
  1047. X`09mvwaddstr(helpwin,row++,15,"before`20you`20moved.`20`20You`20can`20then`20e
  1048. Vnter`20some`20different`20moves.");
  1049. X`09row++;
  1050. X`09mvwaddstr(helpwin,row,0,"Send`20-");
  1051. X`09mvwaddstr(helpwin,row++,15,"Send`20your`20move`20to`20your`20opponent.`20
  1052. V`20You`20will`20be`20able`20to");
  1053. X`09mvwaddstr(helpwin,row++,15,"enter`202`20lines`20of`2056`20characters`20to
  1054. V`20send`20with`20your`20move.");
  1055. X`09row++;
  1056. X`09`7D
  1057. X
  1058. Xif(GameState`20!=`20STATE_CONTROL)`20`7B
  1059. X`09mvwaddstr(helpwin,row,0,"Board`20-");
  1060. X`09mvwaddstr(helpwin,row++,15,"Cycle`20between`20the`20current`20board,`20the
  1061. V`20board`20before`20your");
  1062. X`09mvwaddstr(helpwin,row++,15,"opponent's`20last`20move,`20and`20the`20board
  1063. V`20after`20your`20opponent's");
  1064. X`09mvwaddstr(helpwin,row++,15,"last`20move.");
  1065. X`09row++;
  1066. X`09`7D
  1067. X
  1068. Xif((GameState`20==`20STATE_MYTURN)`20`7C`7C`20(GameState`20==`20STATE_MYMOVE))
  1069. V`20`7B
  1070. X`09mvwaddstr(helpwin,row,0,"Concede`20-");
  1071. X`09mvwaddstr(helpwin,row++,15,"Concede`20the`20current`20game.");
  1072. X`09row++;
  1073. X`09`7D
  1074. X
  1075. Xmvwaddstr(helpwin,row,0,"Next`20Game`20-");
  1076. Xmvwaddstr(helpwin,row++,15,"The`20next`20game`20is`20displayed.`20`20If`20ther
  1077. Ve`20is`20no`20next`20game,`20quit.");
  1078. Xrow++;
  1079. Xmvwaddstr(helpwin,row,0,"Quit`20-");
  1080. Xmvwaddstr(helpwin,row++,15,"Quit`20the`20current`20ldb`20session.");
  1081. X
  1082. Xmvwaddstr(helpwin,23,25,"Press`20<return>`20to`20continue:`20");
  1083. X
  1084. Xtouchwin(helpwin);`09`09/*`20Make`20sure`20the`20screen`20is`20updated`20*/
  1085. Xwrefresh(helpwin);`09`09/*`20update`20the`20help`20window`20clearing`20screen
  1086. V`20*/
  1087. Xwgetch(helpwin);`09`09/*`20Wait`20for`20user`20response`20*/
  1088. Xwclear(helpwin);`09`09/*`20clear`20the`20help`20window`20*/
  1089. Xwrefresh(helpwin);`09`09/*`20update`20the`20help`20window`20clearing`20screen
  1090. V`20*/
  1091. Xdelwin(helpwin);`09`09/*`20delete`20the`20help`20window`20*/
  1092. X`7D
  1093. $ call unpack DOHELP.C;1 1229486700 ""
  1094. $!
  1095. $ create 'f'
  1096. X/*`20dostats.c`09`094/20/92
  1097. X`20*
  1098. X`20*`20Copyright`201992`20`20Earle`20F.`20Ake
  1099. X`20*
  1100. X`20*`20Permission`20to`20use,`20copy,`20modify,`20and`20distribute`20this`20so
  1101. Vftware`20and`20its
  1102. X`20*`20documentation`20without`20fee`20is`20hereby`20granted,`20subject`20to
  1103. V`20the`20restrictions
  1104. X`20*`20detailed`20in`20the`20README`20file,`20which`20is`20included`20here`20b
  1105. Vy`20reference.
  1106. X`20*`20Any`20other`20use`20requires`20written`20permission`20from`20the`20auth
  1107. Vor.`20`20This`20software
  1108. X`20*`20is`20distributed`20"as`20is"`20without`20any`20warranty,`20including
  1109. V`20any`20implied
  1110. X`20*`20warranties`20of`20merchantability`20or`20fitness`20for`20a`20particular
  1111. V`20purpose.
  1112. X`20*`20The`20author`20shall`20not`20be`20liable`20for`20any`20damages`20result
  1113. Ving`20from`20the
  1114. X`20*`20use`20of`20this`20software.`20`20By`20using`20this`20software,`20the
  1115. V`20user`20agrees
  1116. X`20*`20to`20these`20terms.
  1117. X`20*
  1118. X`20*`20Original`20coding`20by`20Earle`20F.`20Ake`20<ake@dayton.saic.com>`20-
  1119. V`2020`20April`201992.
  1120. X`20*
  1121. X`20*/
  1122. X
  1123. X#include`20"ldb.h"
  1124. X
  1125. X/*----------------------------------------------------------------------
  1126. X`20*`09dostats`20--`20display`20online`20statistics`20of`20dice`20rolls
  1127. X`20*
  1128. X`20*`20This`20function`20creates`20a`20new`20curses`20window`20and`20displays
  1129. V`20dice`20statistics
  1130. X`20*`20to`20the`20user.`20`20The`20user`20then`20presses`20any`20key`20to`20re
  1131. Vturn`20to`20the`20game.
  1132. X`20*----------------------------------------------------------------------
  1133. X`20*/
  1134. X
  1135. Xdostats(g)
  1136. Xstruct`20game`20*g;
  1137. X`7B
  1138. XWINDOW`20*statwin;
  1139. Xint`20row,`20i,`20col,`20rolls,`20dice;
  1140. Xint`20mypip,`20oppip;
  1141. Xchar`20temp`5B80`5D;
  1142. Xchar`20c;
  1143. Xint`20Total`20=`200,`20OpTotal`20=`200;
  1144. X
  1145. Xstatwin`20=`20newwin(0,0,0,0);`09/*`20get`20a`20new`20window`20to`20post`20hel
  1146. Vp`20to`20*/
  1147. X
  1148. Xmvwaddstr(statwin,0,30,"ldb`20Dice`20Statistics");`09`09/*`20print`20title`20*
  1149. V/
  1150. Xmvwaddstr(statwin,1,30,"-------------------");`09`09/*`20underline`20title`20*
  1151. V/
  1152. Xrow`20=`203;
  1153. X
  1154. Xmvwaddstr(statwin,row++,0,"You:");
  1155. Xmvwaddstr(statwin,row++,0,"----");
  1156. X
  1157. Xrow++;
  1158. Xmvwaddstr(statwin,row++,0,"Singles`20`20`201`20`202`20`203`20`204`20`205`20
  1159. V`206`20`20Doubles`20`20`201`20`202`20`203`20`204`20`205`20`206");
  1160. Xtemp`5B0`5D`20=`20'`5C0';
  1161. Xfor`20(i`20=`200;`20i`20<`206;`20i++)`20`7B
  1162. X`09sprintf(temp,`20"%s%3d",`20temp,`20g->rolls`5Bi`5D);
  1163. X`09Total`20+=`20(g->rolls`5Bi`5D`20*`20(i+1));
  1164. X`09`7D
  1165. Xsprintf(temp,`20"%s`20`20`20`20`20`20`20`20`20`20",temp);
  1166. Xfor`20(i`20=`200;`20i`20<`206;`20i++)`20`7B
  1167. X`09sprintf(temp,`20"%s%3d",`20temp,`20g->doubles`5Bi`5D);
  1168. X`09Total`20+=`20(g->doubles`5Bi`5D`20*`20(i+1)`20*`204);
  1169. X`09`7D
  1170. X
  1171. Xmvwaddstr(statwin,row++,8,temp);
  1172. Xrow++;
  1173. Xpipcount(g->board,g,`26mypip,`26oppip);
  1174. Xsprintf(temp,"Total`20of`20your`20dice`20rolls`20=`20%-3d`20`20`20`20`20`20
  1175. V`20`20Pips`20remaining`20=`20%-3d",
  1176. X`09Total,mypip);
  1177. Xmvwaddstr(statwin,row++,0,temp);
  1178. Xrow++;
  1179. Xrow++;
  1180. X
  1181. Xmvwaddstr(statwin,row++,0,"Opponent:");
  1182. Xmvwaddstr(statwin,row++,0,"---------");
  1183. X
  1184. Xrow++;
  1185. Xmvwaddstr(statwin,row++,0,"Singles`20`20`201`20`202`20`203`20`204`20`205`20
  1186. V`206`20`20Doubles`20`20`201`20`202`20`203`20`204`20`205`20`206");
  1187. Xtemp`5B0`5D`20=`20'`5C0';
  1188. Xfor`20(i`20=`200;`20i`20<`206;`20i++)`20`7B
  1189. X`09sprintf(temp,`20"%s%3d",`20temp,`20g->oprolls`5Bi`5D);
  1190. X`09OpTotal`20+=`20(g->oprolls`5Bi`5D`20*`20(i+1));
  1191. X`09`7D
  1192. Xsprintf(temp,`20"%s`20`20`20`20`20`20`20`20`20`20",temp);
  1193. Xfor`20(i`20=`200;`20i`20<`206;`20i++)`20`7B
  1194. X`09sprintf(temp,`20"%s%3d",`20temp,`20g->opdoubles`5Bi`5D);
  1195. X`09OpTotal`20+=`20(g->opdoubles`5Bi`5D`20*`20(i+1)`20*`204);
  1196. X`09`7D
  1197. X
  1198. Xmvwaddstr(statwin,row++,8,temp);
  1199. Xrow++;
  1200. Xsprintf(temp,"Total`20of`20opponent`20dice`20rolls`20=`20%-3d`20`20`20`20Pips
  1201. V`20remaining`20=`20%-3d",
  1202. X`09OpTotal,oppip);
  1203. Xmvwaddstr(statwin,row++,0,temp);
  1204. X
  1205. X
  1206. Xmvwaddstr(statwin,23,16,"Press`20H`20for`20histogram`20or`20<return>`20to`20co
  1207. Vntinue:`20");
  1208. X
  1209. Xtouchwin(statwin);`09`09/*`20Make`20sure`20the`20screen`20is`20updated`20*/
  1210. Xwrefresh(statwin);`09`09/*`20update`20the`20window`20clearing`20screen`20*/
  1211. Xc`20=`20wgetch(statwin)`20`26`200x7f;`09/*`20Wait`20for`20user`20response`20*/
  1212. V
  1213. X
  1214. Xif`20(c`20==`20'h'`20`7C`7C`20c`20==`20'H')`20`7B`09/*`20Histogram`20wanted
  1215. V`20*/
  1216. X`09wclear(statwin);`09`09/*`20clear`20the`20window`20*/
  1217. X
  1218. X/*
  1219. X`20*`20Draw`20the`20axis`20themselves
  1220. X`20*
  1221. X`20*/
  1222. X
  1223. X
  1224. X`09for`20(i`20=`202;`20i`20<`2018;`20i++)`20`7B`09`09/*`20Vertical`20axis`20*/
  1225. V
  1226. X`09`09mvwaddstr(statwin,i,11,"`7C");
  1227. X`09`09mvwaddstr(statwin,i,44,"`7C");
  1228. X`09`09`7D
  1229. X
  1230. X`09for`20(i`20=`2012;`20i`20<`2041;`20i++)`20`7B`09`09/*`20Horizontal`20axis
  1231. V`20*/
  1232. X`09`09mvwaddstr(statwin,17,i,"-");
  1233. X`09`09mvwaddstr(statwin,17,i+33,"-");
  1234. X`09`09`7D
  1235. X
  1236. X/*
  1237. X`20*`20Number`20the`20vertical`20axis
  1238. X`20*
  1239. X`20*/
  1240. X
  1241. X`09mvwaddstr(statwin,2,8,"15");
  1242. X`09mvwaddstr(statwin,2,41,"15");
  1243. X
  1244. X`09mvwaddstr(statwin,7,8,"10");
  1245. X`09mvwaddstr(statwin,7,41,"10");
  1246. X
  1247. X`09mvwaddstr(statwin,12,9,"5");
  1248. X`09mvwaddstr(statwin,12,42,"5");
  1249. X
  1250. X/*
  1251. X`20*`20Put`20the`20numbers`20across`20the`20bottom`20of`20the`20axis
  1252. X`20*
  1253. X`20*/
  1254. X
  1255. X`09col`20=`2013;
  1256. X`09for`20(i`20=`201;`20i`20<`207;`20i++)`20`7B
  1257. X`09`09sprintf(temp,"%d",`20i);
  1258. X`09`09mvwaddch(statwin,18,col,temp`5B0`5D);
  1259. X`09`09mvwaddch(statwin,18,col+33,temp`5B0`5D);
  1260. X`09`09col`20+=`205;
  1261. X`09`09`7D
  1262. X
  1263. X/*
  1264. X`20*`20Label`20the`20top`20and`20bottom`20of`20the`20graph
  1265. X`20*
  1266. X`20*/
  1267. X
  1268. X`09mvwaddstr(statwin,0,17,"H`20i`20s`20t`20o`20g`20r`20a`20m`20`20`20o`20f`20
  1269. V`20`20D`20I`20C`20E`20`20`20R`20o`20l`20l`20s");
  1270. X`09mvwaddstr(statwin,19,20,"S`20I`20N`20G`20L`20E`20S");
  1271. X`09mvwaddstr(statwin,19,53,"D`20O`20U`20B`20L`20E`20S");
  1272. X`09mvwaddstr(statwin,21,4,"Legend:");
  1273. X`09sprintf(temp,"X`20=`20You,`20dice`20total`20=`20%3d",`20Total);
  1274. X`09sprintf(temp,"%s`20`20`20`20`20O`20=`20Opponent,`20dice`20total`20=`20%3d",
  1275. V`20temp,`20OpTotal);
  1276. X`09mvwaddstr(statwin,21,14,temp);
  1277. X`09wmove(statwin,22,23);
  1278. X`09wprintw(statwin,"pips`20`20`20`20`20`20`20=`20%3d",mypip);
  1279. X`09wmove(statwin,22,58);
  1280. X`09wprintw(statwin,"pips`20`20`20`20`20`20`20=`20%3d",oppip);
  1281. X
  1282. X/*
  1283. X`20*`20Label`20the`20left`20side`20of`20the`20graph
  1284. X`20*
  1285. X`20*/
  1286. X
  1287. X`09sprintf(temp,"Number");
  1288. X`09for`20(i`20=`200;`20i`20<`20strlen(temp);`20i++)
  1289. X`09`09mvwaddch(statwin,7+i,0,temp`5Bi`5D);
  1290. X
  1291. X`09sprintf(temp,"of");
  1292. X`09for`20(i`20=`200;`20i`20<`20strlen(temp);`20i++)
  1293. X`09`09mvwaddch(statwin,9+i,3,temp`5Bi`5D);
  1294. X
  1295. X`09sprintf(temp,"Occurrences");
  1296. X`09for`20(i`20=`200;`20i`20<`20strlen(temp);`20i++)
  1297. X`09`09mvwaddch(statwin,5+i,6,temp`5Bi`5D);
  1298. X
  1299. X/*
  1300. X`20*`20Now`20that`20we`20have`20the`20axis`20drawn`20and`20labeled,`20fill`20i
  1301. Vn`20the`20data
  1302. X`20*
  1303. X`20*/
  1304. X
  1305. X`09for`20(dice`20=`200;`20dice`20<`206;`20dice++)`20`7B
  1306. X`09`09for`20(i`20=`200;`20i`20<`204;`20i++)`20`7B
  1307. X`09`09`09switch`20(i)`20`7B
  1308. X`09`09`09case`200:
  1309. X`09`09`09`09rolls`20=`20g->rolls`5Bdice`5D;
  1310. X`09`09`09`09col`20=`2012`20+`20dice`20*`205;
  1311. X`09`09`09`09c`20=`20'X';
  1312. X`09`09`09`09break;
  1313. X`09`09`09case`201:
  1314. X`09`09`09`09rolls`20=`20g->oprolls`5Bdice`5D;
  1315. X`09`09`09`09col`20=`2014`20+`20dice`20*`205;
  1316. X`09`09`09`09c`20=`20'O';
  1317. X`09`09`09`09break;
  1318. X`09`09`09case`202:
  1319. X`09`09`09`09rolls`20=`20g->doubles`5Bdice`5D;
  1320. X`09`09`09`09col`20=`2045`20+`20dice`20*`205;
  1321. X`09`09`09`09c`20=`20'X';
  1322. X`09`09`09`09break;
  1323. X`09`09`09case`203:
  1324. X`09`09`09`09rolls`20=`20g->opdoubles`5Bdice`5D;
  1325. X`09`09`09`09col`20=`2047`20+`20dice`20*`205;
  1326. X`09`09`09`09c`20=`20'O';
  1327. X`09`09`09`09break;
  1328. X`09`09`09`09`7D
  1329. X`09
  1330. X/*
  1331. X`20*`20Special`20case.`20`20If`20we`20have`20more`20than`2030`20of`20one`20rol
  1332. Vl,`20put`20a`20*`20at`20the
  1333. X`20*`20top`20of`20the`20second`20column`20and`20show`2029`20X's`20or`20O's.
  1334. X`20*
  1335. X`20*/
  1336. X
  1337. X`09`09`09row`20=`2016;
  1338. X`09`09`09if`20(rolls`20>`2030)`20`7B
  1339. X`09`09`09`09rolls`20=`2029;
  1340. X`09`09`09`09mvwaddch(statwin,2,col+1,'*');
  1341. X`09`09`09`09`7D
  1342. X
  1343. X/*
  1344. X`20*`20While`20the`20roll`20counter`20is`20greater`20than`20zero,`20put`20out
  1345. V`20X's`20or`20O's.
  1346. X`20*
  1347. X`20*/
  1348. X
  1349. X`09`09`09while`20(rolls`20>`200)`20`7B
  1350. X`09`09`09`09mvwaddch(statwin,row--,col,c);
  1351. X`09`09`09`09rolls--;
  1352. X`09`09`09`09if`20(row`20<`202)`20`7B`09/*`20move`20to`202nd`20column`20*/
  1353. X`09`09`09`09`09row`20=`2016;
  1354. X`09`09`09`09`09col++;
  1355. X`09`09`09`09`09`7D
  1356. X`09`09`09`09`7D
  1357. X`09`09`09`7D
  1358. X`09`09`7D
  1359. X
  1360. X/*
  1361. X`20*`20We`20are`20done`20with`20the`20graph.`20`20Refresh`20and`20wait`20for
  1362. V`20a`20keypress
  1363. X`20*
  1364. X`20*/
  1365. X
  1366. X`09mvwaddstr(statwin,23,25,"Press`20<return>`20to`20continue:`20");
  1367. X`09touchwin(statwin);`09`09/*`20Make`20sure`20the`20screen`20is`20updated`20*/
  1368. V
  1369. X`09wrefresh(statwin);`09`09/*`20update`20the`20window`20clearing`20screen`20*/
  1370. V
  1371. X`09wgetch(statwin);`09`09/*`20Wait`20for`20user`20response`20*/
  1372. X`09`7D
  1373. X
  1374. Xwclear(statwin);`09`09/*`20clear`20the`20window`20*/
  1375. Xwrefresh(statwin);`09`09/*`20update`20the`20window`20clearing`20screen`20*/
  1376. +-+-+-+-+-+-+-+-  END  OF PART 7 +-+-+-+-+-+-+-+-
  1377.