home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1994 March / Source_Code_CD-ROM_Walnut_Creek_March_1994.iso / compsrcs / games / vmsnet / ldb / part12 < 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 [12/16]
  5. Date: 8 Apr 93 11:01:50 EST
  6. Organization: Science Applications Intl Corp - Dayton, OH
  7. Lines: 1319
  8. Message-ID: <1993Apr8.110150.1@dayvd.dayton.saic.com>
  9. NNTP-Posting-Host: dayvd.dayton.saic.com
  10. Xref: uunet vmsnet.sources.games:673
  11.  
  12. -+-+-+-+-+-+-+-+ START OF PART 12 -+-+-+-+-+-+-+-+
  13. X`09`09`09b`5Bnp`5D.qty`20=`200;`09`09/*`20bye`20bye`20*/
  14. X`09`09`09j`20=`20BARPT(REV(dir));`09/*`20send`20it`20to`20opponents`20bar`20*/
  15. V
  16. X`09`09`09b`5Bj`5D.color`20=`20b`5Bnp`5D.color;`20/*`20copy`20color`20to`20bar
  17. V`20pt`20*/
  18. X`09`09`09b`5Bj`5D.qty++;`09`09/*`20bump`20counter`20*/
  19. X`09`09`09if`20(flags`20`26`20A_REDRAW)`20`7B`09/*`20update`20screen`20*/
  20. X`09`09`09`09FeDrawPoint(b,j,0,g->flags`20`26`20F_INVERT);
  21. X`09`09`09`09FeDrawPip(b,g);
  22. X`09`09`09`09`7D
  23. X`09`09`09b`5Bnp`5D.color`20=`20b`5Bop`5D.color;`09/*`20my`20point`20now`20*/
  24. X`09`09`09`7D
  25. X`09`09`7D
  26. X`09else
  27. X`09`09return(RJ_OCC);`09`09/*`20point`20is`20occupied`20*/
  28. X`09`7D
  29. Xif`20(`20(flags`20`26`20A_CHKONLY)`20==`200)`20`7B
  30. X`09b`5Bop`5D.qty--;`09`09`09`09/*`20take`20piece`20from`20old`20pt`20*/
  31. X`09b`5Bnp`5D.qty++;`09`09`09`09/*`20and`20put`20in`20on`20new`20pt`20*/
  32. X`09if`20(flags`20`26`20A_REDRAW)`20`7B
  33. X`09`09FeDrawPip(b,g);
  34. X`09`09FeDrawPoint(b,op,0,g->flags`20`26`20F_INVERT);/*`20update`20the`20screen
  35. V`20*/
  36. X`09`09FeDrawPoint(b,np,0,g->flags`20`26`20F_INVERT);
  37. X`09`09`7D
  38. X`09`7D
  39. Xif`20(dest`20!=`20NULL)`09`09`09/*`20return`20new`20position`20*/
  40. X`09*dest`20=`20np;
  41. Xreturn(blot);`09`09`09`09/*`20succeeded,`20return`20MVOK`20or`20blot`20*/
  42. X`7D
  43. X
  44. X
  45. X/*----------------------------------------------------------------------
  46. X`20*`09addpcs`20--`20add`20the`20number`20of`20pieces`20in`20a`20range`20of
  47. V`20points
  48. X`20*
  49. X`20*`20This`20function`20returns`20the`20number`20of`20pieces`20of`20a`20certa
  50. Vin`20color
  51. X`20*`20that`20reside`20within`20a`20range`20of`20points.
  52. X`20*----------------------------------------------------------------------
  53. X`20*/
  54. X
  55. Xaddpcs(b,clr,f,t)
  56. Xboard`20b;
  57. Xchar`20clr;
  58. Xint`20f,`20t;
  59. X`7B
  60. Xint`20i,`20q;
  61. X
  62. Xq`20=`200;`09`09`09`09/*`20quantity`20we`20have`20found`20so`20far`20*/
  63. Xfor`20(i`20=`20f;`20i`20<=`20t;`20i++)
  64. X`09if`20(b`5Bi`5D.color`20==`20clr)`09/*`20found`20some`20*/
  65. X`09`09q`20+=`20b`5Bi`5D.qty;`09/*`20count`20them`20*/
  66. Xreturn(q);`09`09`09/*`20return`20quantity`20found`20*/
  67. X`7D
  68. $ call unpack MOVE.C;1 268841531 ""
  69. $!
  70. $ create 'f'
  71. X/*`09process.c`09`098/8/91
  72. X`20*
  73. X`20*`20Copyright`201991`20`20Perry`20R.`20Ross
  74. X`20*
  75. X`20*`20Permission`20to`20use,`20copy,`20modify,`20and`20distribute`20this`20so
  76. Vftware`20and`20its
  77. X`20*`20documentation`20without`20fee`20is`20hereby`20granted,`20subject`20to
  78. V`20the`20restrictions
  79. X`20*`20detailed`20in`20the`20README`20file,`20which`20is`20included`20here`20b
  80. Vy`20reference.
  81. X`20*`20Any`20other`20use`20requires`20written`20permission`20from`20the`20auth
  82. Vor.`20`20This`20software
  83. X`20*`20is`20distributed`20"as`20is"`20without`20any`20warranty,`20including
  84. V`20any`20implied
  85. X`20*`20warranties`20of`20merchantability`20or`20fitness`20for`20a`20particular
  86. V`20purpose.
  87. X`20*`20The`20author`20shall`20not`20be`20liable`20for`20any`20damages`20result
  88. Ving`20from`20the
  89. X`20*`20use`20of`20this`20software.`20`20By`20using`20this`20software,`20the
  90. V`20user`20agrees
  91. X`20*`20to`20these`20terms.
  92. X`20*/
  93. X
  94. X#include`20"ldb.h"
  95. X
  96. X/*===========================================================================
  97. X`20*`20This`20file`20contains`20the`20code`20to`20process`20user`20input.
  98. X`20*==========================================================================
  99. V=
  100. X`20*/
  101. X
  102. X
  103. X
  104. X/*----------------------------------------------------------------------
  105. X`20*`09process`20--`20process`20a`20game`20while`20it`20needs`20local`20input
  106. X`20*
  107. X`20*`20This`20function`20calls`20the`20appropriate`20handler,`20according`20to
  108. V`20what
  109. X`20*`20state`20the`20game`20is`20in,`20to`20prompt`20the`20user`20for`20input.
  110. V`20`20If`20a`20game
  111. X`20*`20does`20not`20need`20local`20input,`20it`20is`20skipped.`20`20Process()
  112. V`20returns`201
  113. X`20*`20if`20the`20game`20still`20needs`20local`20input,`20in`20which`20case
  114. V`20the`20main`20program
  115. X`20*`20will`20re-call`20process`20with`20the`20same`20game.`20`20When`20the
  116. V`20game`20no`20longer
  117. X`20*`20needs`20local`20input,`20process`20will`20return`200,`20telling`20the
  118. V`20main`20program
  119. X`20*`20to`20proceed`20to`20the`20next`20game.
  120. X`20*----------------------------------------------------------------------
  121. X`20*/
  122. X
  123. Xprocess(g)
  124. Xstruct`20game`20*g;
  125. X`7B
  126. Xint`20i;
  127. X
  128. Xif`20(g->state`20<`20OPSTATES)`09/*`20this`20game`20is`20waiting`20for`20the
  129. V`20opponent`20*/
  130. X`09return(0);`09`09/*`20skip`20it`20for`20now`20*/
  131. Xif`20(`20(g->state`20==`20ST_GAMEOVER)`20`26`26`20(g->flags`20`26`20F_DISPLAYE
  132. VD)`20)
  133. X`09return(0);`09/*`20game`20is`20in`20"keepold"`20wait,`20no`20need`20to`20dis
  134. Vplay`20*/
  135. XFeDrawGame(g);`09`09`09/*`20draw`20the`20game`20*/
  136. Xswitch`20(g->state)`20`7B
  137. Xcase`20ST_MYTURN:`09`09`09/*`20my`20turn,`20I`20haven't`20rolled`20yet`20*/
  138. X`09if`20(`20((g->flags`20`26`20F_IDOUBLED)`20==`200)`20`7C`7C`20(*rc.autoroll
  139. V`20==`20'n')`20)`20`7B
  140. X`09`09i`20=`20myturn(g);`09/*`20I`20didn't`20double`20last`20*/
  141. X`09`09break;
  142. X`09`09`7D
  143. X`09rolldice(g);`09`09/*`20if`20I`20doubled`20last,`20go`20ahead`20and`20roll
  144. V`20*/
  145. X`09g->state`20=`20ST_MYMOVE;`09/*`20skip`20this`20state`20completely`20*/
  146. X`09if`20(*rc.chkpt`20==`20'y')`20`7B`09/*`20checkpoint`20games`20*/
  147. X`09`09writegames(rc.gfile,rc.gbackup,rc.pfile);
  148. X`09`09rc.gbackup`20=`20NULL;`09/*`20only`20backup`20old`20file`20once`20*/
  149. X`09`09`7D
  150. X`09for`20(i`20=`200;`20i`20<`204;`20i++)`09`09/*`20draw`20my`20new`20roll`20*/
  151. V
  152. X`09`09FeDrawMove(g,WHO_ME,i);
  153. X`09/****`20fall`20through`20****/
  154. Xcase`20ST_MYMOVE:`09`09`09/*`20my`20turn,`20I`20have`20rolled`20*/
  155. X`09i`20=`20mymove(g);`09`09/*`20user`20has`20rolled,`20must`20move`20*/
  156. X`09break;
  157. Xcase`20ST_MYACCEPT:
  158. X`09i`20=`20myacpt(g);`09/*`20user`20must`20accept`20or`20decline`20double`20*/
  159. V
  160. X`09break;
  161. Xcase`20ST_GAMEOVER:
  162. X`09i`20=`20gameover(g);`09`09/*`20tell`20him`20the`20game`20is`20over`20*/
  163. X`09break;
  164. X`09`7D
  165. Xreturn(i);
  166. X`7D
  167. X
  168. X
  169. X/*----------------------------------------------------------------------
  170. X`20*`09myturn`20--`20allow`20user`20to`20roll`20or`20double
  171. X`20*
  172. X`20*`20This`20function`20is`20called`20to`20allow`20the`20user`20to`20choose
  173. V`20between
  174. X`20*`20rolling`20the`20dice`20and`20doubling.`20`20It`20also`20allows`20the
  175. V`20user`20to`20cycle
  176. X`20*`20through`20the`20three`20board`20displays,`20to`20concede,`20and`20to
  177. V`20go`20to`20the`20next`20game.
  178. X`20*----------------------------------------------------------------------
  179. X`20*/
  180. X
  181. Xmyturn(g)
  182. Xstruct`20game`20*g;
  183. X`7B
  184. Xchar`20c;
  185. Xchar`20pm`20=`20'`5C0';
  186. Xint`20gv;
  187. Xstatic`20char`20*m`5B`5D=`7B"Roll","Double","Board","Next`20Game","Concede","Q
  188. Vuit",NULL`7D;
  189. X
  190. XFeDrawMenu(m);`09`09`09/*`20display`20the`20menu`20*/
  191. XGameState`20=`20STATE_MYTURN;
  192. Xwhile`20(1)`20`7B
  193. X`09c`20=`20FeMenu(m,0,0,"`5Cn`5Cr`20",pm);`09/*`20get`20a`20menu`20choice`20*/
  194. V
  195. X`09pm`20=`20c;
  196. X`09switch`20(c)`20`7B
  197. X`09case`20'`5Cn':
  198. X`09case`20'`5Cr':
  199. X`09case`20'`20':
  200. X`09`09FeOnMenuItem(m,'R');`09/*`20highlight`20Roll`20item`20*/
  201. X`09`09pm`20=`20'R';`09`09/*`20remember`20to`20unhighlight`20it`20later`20*/
  202. X`09`09/*`20fall`20through`20*/
  203. X`09case`20'R':`09`09`09/*`20roll`20them`20dice`20*/
  204. X`09`09g->curbd`20=`20BD_CUR;`09/*`20bring`20up`20current`20board`20*/
  205. X`09`09rolldice(g);
  206. X`09`09g->state`20=`20ST_MYMOVE;`09/*`20I`20just`20entered`20a`20new`20state
  207. V`20*/
  208. X`09`09if`20(*rc.chkpt`20==`20'y')`20`7B`09/*`20checkpoint`20games`20*/
  209. X`09`09`09writegames(rc.gfile,rc.gbackup,rc.pfile);
  210. X`09`09`09rc.gbackup`20=`20NULL;`09/*`20only`20backup`20old`20file`20once`20*/
  211. X`09`09`09`7D
  212. X`09`09return(1);`09`09/*`20make`20sure`20process`20gets`20re-called`20*/
  213. X`09case`20'D':`09`09`09/*`20I`20want`20to`20double`20*/
  214. X`09`09if`20(g->flags`20`26`20F_IDOUBLED)`20`7B`09/*`20I`20doubled`20last`20*/
  215. X`09`09`09FeMessage("You`20doubled`20last.");
  216. X`09`09`09break;`09`09/*`20so`20I`20can't`20double`20now`20*/
  217. X`09`09`09`7D
  218. X`09`09if`20(g->flags`20`26`20F_CRGAME)`20`7B
  219. X`09`09`09FeMessage("Double`20not`20allowed`20(Crawford`20rule)");
  220. X`09`09`09break;
  221. X`09`09`09`7D
  222. X`09`09if`20(FeGetComment(g)`20<`200)`20`7B`09/*`20get`20message`20*/
  223. X`09`09`09FeMessage("Double`20aborted.");
  224. X`09`09`09break;`09`09/*`20changed`20his`20mind`20*/
  225. X`09`09`09`7D
  226. X`09`09g->state`20=`20ST_OPACCEPT;`09/*`20we`20are`20waiting`20for`20accept/dec
  227. Vline`20*/
  228. X`09`09sendpkt(g,OFRDBL);`09/*`20send`20the`20double`20packet`20*/
  229. X`09`09return(0);`09`09/*`20this`20game`20is`20done`20for`20now`20*/
  230. X`09case`20'C':`09`09`09/*`20I'm`20wimping`20out`20*/
  231. X`09`09if`20(`20(check_concede(g)`20==`200)`20`7C`7C`20(FeGetComment(g)`20<`200
  232. V)`20)`20`7B
  233. X`09`09`09FeMessage("Concede`20aborted.");
  234. X`09`09`09break;
  235. X`09`09`09`7D
  236. X`09`09ilose(g,T_ICONCEDE,0);`09/*`20this`20game`20is`20over`20*/
  237. X`09`09sendpkt(g,CONCEDE);`09/*`20send`20the`20packet`20*/
  238. X`09`09return(1);`09`09/*`20display`20the`20gameover`20screen`20*/
  239. X`09case`20'B':`09`09`09/*`20display`20different`20board`20*/
  240. X`09`09if`20(g->curbd++`20>=`20BD_CUR)`09/*`20go`20to`20next`20board`20*/
  241. X`09`09`09g->curbd`20=`20BD_BEFOP;`09/*`20wrap`20around`20*/
  242. X`09`09return(1);`09`09/*`20redraw`20`26`20call`20us`20again`20*/
  243. X`09case`20'N':`09`09`09/*`20I`20don't`20want`20to`20decide`20right`20now`20*/
  244. X`09`09return(0);
  245. X`09case`20'Q':`09`09`09/*`20I`20want`20to`20quit`20ldb`20*/
  246. X`09`09return(-1);
  247. X`09`09`7D
  248. X`09`7D
  249. X`7D
  250. X
  251. X
  252. X/*----------------------------------------------------------------------
  253. X`20*`09mymove`20--`20allow`20user`20to`20move
  254. X`20*
  255. X`20*`20This`20function`20is`20called`20to`20allow`20the`20user`20to`20use`20hi
  256. Vs`20roll.
  257. X`20*`20It`20also`20allows`20the`20user`20to`20cycle`20through`20the`20three
  258. V`20board`20displays,
  259. X`20*`20to`20concede,`20and`20to`20go`20to`20the`20next`20game.
  260. X`20*`20Since`20the`20user`20has`20already`20rolled,`20doubling`20is`20not`20al
  261. Vlowed`20here.
  262. X`20*----------------------------------------------------------------------
  263. X`20*/
  264. X
  265. Xmymove(g)
  266. Xstruct`20game`20*g;
  267. X`7B
  268. Xchar`20c;
  269. Xint`20i,`20n;
  270. Xstatic`20char`20used`5B`5D`20=`20"That`20move`20is`20already`20used`20--`20use
  271. V`20Reset`20to`20start`20over";
  272. Xstruct`20mv`20tmp;
  273. Xstatic`20char`20*m`5B`5D`20=`20`7B"Reset","Send","Board","Next`20Game","Conced
  274. Ve",
  275. X`09`09`09"Point","Off","Quit",NULL`7D;
  276. Xchar`20pm`20=`20'`5C0';
  277. Xint`20lastpt`20=`2099;`09`09/*`20point`20last`20move`20started`20from`20*/
  278. Xint`20lastd`20=`2099;`09`09`09/*`20point`20last`20move`20ended`20at`20*/
  279. X
  280. XFeDrawMenu(m);
  281. XGameState`20=`20STATE_MYMOVE;
  282. Xwhile`20(1)`20`7B
  283. X`09c`20=`20FeMenu(m,g->mvs`5B0`5D.roll,g->mvs`5B1`5D.roll,"`5Cn`5Cr`20",pm);
  284. X`09pm`20=`20c;
  285. X`09switch`20(c)`20`7B
  286. X`09case`20'S':`09`09`09/*`20send`20moves`20*/
  287. X`09`09if`20(checkused(g))`09/*`20didn't`20use`20all`20our`20moves`20*/
  288. X`09`09`09break;
  289. X`09`09if`20(FeGetComment(g)`20<`200)`20`7B`09/*`20get`20our`20comment`20*/
  290. X`09`09`09FeMessage("Send`20aborted.");
  291. X`09`09`09break;
  292. X`09`09`09`7D
  293. X`09`09if`20(g->board`5BOFFPT(g->mydir)`5D.qty`20==`2015)`09/*`20I`20win`20*/
  294. X`09`09`09iwin(g,T_IWIN,0);
  295. X`09`09else
  296. X`09`09`09g->state`20=`20ST_OPTURN;
  297. X`09`09sendpkt(g,MOVE);`09`09/*`20send`20our`20move`20*/
  298. X`09`09return(g->state`20==`20ST_GAMEOVER);/*`20need`20to`20call`20gameover()
  299. V`20*/
  300. X`09case`20'R':`09`09`09/*`20reset`20--`20erase`20moves`20`26`20start`20over
  301. V`20*/
  302. X`09`09if`20(g->curbd`20!=`20BD_CUR)`09`09/*`20if`20we`20are`20not`20looking
  303. V`20at`20*/
  304. X`09`09`09g->curbd`20=`20BD_CUR;`09/*`20current`20board,`20switch`20*/
  305. X`09`09for`20(i`20=`200;`20i`20<`204;`20i++)`20`7B
  306. X`09`09`09g->mvs`5Bi`5D.pt`20=`20-1;
  307. X`09`09`09FeDrawMove(g,WHO_ME,i);
  308. X`09`09`09`7D
  309. X`09`09copyboard(g->mybd,g->board);
  310. X`09`09FeDrawBoard(g->board,NULL,g->mydir,0,g->flags`20`26`20F_INVERT);
  311. X`09`09FeLabelBoard(g);
  312. X`09`09FeDrawPip(g->board,g);
  313. X`09`09break;
  314. X`09case`20'B':`09`09`09`09/*`20display`20different`20board`20*/
  315. X`09`09if`20(g->curbd++`20>=`20BD_CUR)`09/*`20go`20to`20next`20board`20*/
  316. X`09`09`09g->curbd`20=`20BD_BEFOP;`09/*`20wrap`20around`20*/
  317. X`09`09return(1);`09`09/*`20redraw`20`26`20call`20us`20again`20*/
  318. X`09case`20'C':`09`09`09/*`20I'm`20wimping`20out`20*/
  319. X`09`09if`20(`20(check_concede(g)`20==`200)`20`7C`7C`20(FeGetComment(g)`20<`200
  320. V)`20)`20`7B
  321. X`09`09`09FeMessage("Concede`20aborted.");
  322. X`09`09`09break;
  323. X`09`09`09`7D
  324. X`09`09ilose(g,T_ICONCEDE,0);
  325. X`09`09sendpkt(g,CONCEDE);`09/*`20send`20the`20packet`20*/
  326. X`09`09return(1);`09`09/*`20display`20the`20gameover`20screen`20*/
  327. X`09case`20'N':`09`09`09/*`20I`20don't`20want`20to`20decide`20right`20now`20*/
  328. X`09`09return(0);
  329. X`09case`20'Q':`09`09`09/*`20I`20want`20to`20quit`20ldb`20*/
  330. X`09`09return(-1);
  331. X`09case`20'`20':`09`09`09/*`20continue`20last`20move`20*/
  332. X`09`09if`20(g->curbd`20!=`20BD_CUR)`20`7B
  333. X`09`09`09g->curbd`20=`20BD_CUR;
  334. X`09`09`09FeDrawBoard(g->board,NULL,g->mydir,0,
  335. X`09`09`09`09g->flags`20`26`20F_INVERT);
  336. X`09`09`09FeLabelBoard(g);
  337. X`09`09`09`7D
  338. X`09`09n`20=`20(g->mvs`5B0`5D.roll`20==`20g->mvs`5B1`5D.roll)`20?`204`20:`202;
  339. X`09`09for`20(i`20=`200;`20i`20<`20n;`20i++)`09`09/*`20search`20for`20an`20unus
  340. Ved`20move`20*/
  341. X`09`09`09if`20(g->mvs`5Bi`5D.pt`20<`200)
  342. X`09`09`09`09break;
  343. X`09`09if`20(i`20>=`20n)`20`7B
  344. X`09`09`09FeMessage("You`20don't`20have`20any`20moves`20left.");
  345. X`09`09`09break;
  346. X`09`09`09`7D
  347. X`09`09if`20(`20(lastd`20<`201)`20`7C`7C`20(lastd`20>`2024)`20)`20`7B
  348. X`09`09`09FeMessage(
  349. X`09`09`09`20`20`20"No`20move`20to`20continue`20--`20please`20select`20a`20roll
  350. V.");
  351. X`09`09`09break;
  352. X`09`09`09`7D
  353. X`09`09g->mvs`5Bi`5D.pt`20=`20lastd;
  354. X`09`09n`20=`20apply(g,WHO_ME,i,A_REDRAW,`26lastd);
  355. X`09`09if`20(n`20<`200)`20`7B`09/*`20move`20rejected`20*/
  356. X`09`09`09g->mvs`5Bi`5D.pt`20=`20-1;
  357. X`09`09`09FeMessage(rejlcl`5B-n`5D);
  358. X`09`09`09lastd`20=`2099;
  359. X`09`09`09`7D
  360. X`09`09else
  361. X`09`09`09lastpt`20=`20g->mvs`5Bi`5D.pt;
  362. X`09`09FeDrawMove(g,WHO_ME,i);
  363. X`09`09FeCheckContact(g);
  364. X`09`09break;
  365. X`09case`20'`5Cn':`09`09`09/*`20repeat`20last`20move`20*/
  366. X`09case`20'`5Cr':
  367. X`09`09if`20(g->curbd`20!=`20BD_CUR)`20`7B
  368. X`09`09`09g->curbd`20=`20BD_CUR;
  369. X`09`09`09FeDrawBoard(g->board,NULL,g->mydir,0,
  370. X`09`09`09`09g->flags`20`26`20F_INVERT);
  371. X`09`09`09FeLabelBoard(g);
  372. X`09`09`09`7D
  373. X`09`09n`20=`20(g->mvs`5B0`5D.roll`20==`20g->mvs`5B1`5D.roll)`20?`204`20:`202;
  374. X`09`09for`20(i`20=`200;`20i`20<`20n;`20i++)`09`09/*`20search`20for`20an`20unus
  375. Ved`20move`20*/
  376. X`09`09`09if`20(g->mvs`5Bi`5D.pt`20<`200)
  377. X`09`09`09`09break;
  378. X`09`09if`20(i`20>=`20n)`20`7B
  379. X`09`09`09FeMessage("You`20don't`20have`20any`20moves`20left.");
  380. X`09`09`09break;
  381. X`09`09`09`7D
  382. X`09`09if`20(`20(lastpt`20<`200)`20`7C`7C`20(lastpt`20>`2025)`20)`20`7B
  383. X`09`09`09FeMessage("No`20move`20to`20repeat`20--`20please`20select`20a`20roll.
  384. V");
  385. X`09`09`09break;
  386. X`09`09`09`7D
  387. X`09`09g->mvs`5Bi`5D.pt`20=`20lastpt;
  388. X`09`09n`20=`20apply(g,WHO_ME,i,A_REDRAW,`26lastd);
  389. X`09`09if`20(n`20<`200)`20`7B`09/*`20move`20rejected`20*/
  390. X`09`09`09g->mvs`5Bi`5D.pt`20=`20-1;
  391. X`09`09`09FeMessage(rejlcl`5B-n`5D);
  392. X`09`09`09lastpt`20=`2099;
  393. X`09`09`09`7D
  394. X`09`09FeDrawMove(g,WHO_ME,i);
  395. X`09`09FeCheckContact(g);
  396. X`09`09break;
  397. X`09case`20'P':`09`09`09`09/*`20make`20point`20from`20last`20move`20*/
  398. X`09`09if`20(g->curbd`20!=`20BD_CUR)`20`7B
  399. X`09`09`09g->curbd`20=`20BD_CUR;
  400. X`09`09`09FeDrawBoard(g->board,NULL,g->mydir,0,
  401. X`09`09`09`09g->flags`20`26`20F_INVERT);
  402. X`09`09`09FeLabelBoard(g);
  403. X`09`09`09`7D
  404. X`09`09n`20=`20(g->mvs`5B0`5D.roll`20==`20g->mvs`5B1`5D.roll)`20?`204`20:`202;
  405. X`09`09for`20(i`20=`200;`20i`20<`20n;`20i++)`09`09/*`20search`20for`20an`20unus
  406. Ved`20move`20*/
  407. X`09`09`09if`20(g->mvs`5Bi`5D.pt`20<`200)
  408. X`09`09`09`09break;
  409. X`09`09if`20(i`20>=`20n)`20`7B
  410. X`09`09`09FeMessage("You`20don't`20have`20any`20moves`20left.");
  411. X`09`09`09break;
  412. X`09`09`09`7D
  413. X`09`09if`20(`20(lastpt`20<`200)`20`7C`7C`20(lastpt`20>`2025)`20)`20`7B
  414. X`09`09`09FeMessage("No`20point`20to`20make`20--`20please`20select`20a`20roll."
  415. V);
  416. X`09`09`09break;
  417. X`09`09`09`7D
  418. X`09`09g->mvs`5Bi`5D.pt`20=`20lastd`20-`20g->mydir*g->mvs`5Bi`5D.roll;
  419. X`09`09n`20=`20apply(g,WHO_ME,i,A_REDRAW,`26lastd);
  420. X`09`09if`20(n`20<`200)`20`7B`09/*`20move`20rejected`20*/
  421. X`09`09`09g->mvs`5Bi`5D.pt`20=`20-1;
  422. X`09`09`09FeMessage(rejlcl`5B-n`5D);
  423. X`09`09`09`7D
  424. X`09`09FeDrawMove(g,WHO_ME,i);
  425. X`09`09FeCheckContact(g);
  426. X`09`09break;
  427. X`09case`20'O':`09`09`09`09/*`20bear`20off`20with`20next`20roll`20*/
  428. X`09`09if`20(g->curbd`20!=`20BD_CUR)`20`7B
  429. X`09`09`09g->curbd`20=`20BD_CUR;
  430. X`09`09`09FeDrawBoard(g->board,NULL,g->mydir,0,
  431. X`09`09`09`09g->flags`20`26`20F_INVERT);
  432. X`09`09`09FeLabelBoard(g);
  433. X`09`09`09`7D
  434. X`09`09n`20=`20(g->mvs`5B0`5D.roll`20==`20g->mvs`5B1`5D.roll)`20?`204`20:`202;
  435. X`09`09for`20(i`20=`200;`20i`20<`20n;`20i++)`09`09/*`20search`20for`20an`20unus
  436. Ved`20move`20*/
  437. X`09`09`09if`20(g->mvs`5Bi`5D.pt`20<`200)
  438. X`09`09`09`09break;
  439. X`09`09if`20(i`20>=`20n)`20`7B
  440. X`09`09`09FeMessage("You`20don't`20have`20any`20moves`20left.");
  441. X`09`09`09break;
  442. X`09`09`09`7D
  443. X`09`09n`20=`20(`20(g->mydir`20>`200)`20?`2025`20:`200`20)`20-`20g->mydir*g->mv
  444. Vs`5Bi`5D.roll;
  445. X`09`09while`20(`20(n`20>`200)`20`26`26`20(n`20<`2025)`20`26`26`20(`20(g->board
  446. V`5Bn`5D.qty`20<=`200)`20`7C`7C
  447. X`09`09`20`20`20(g->board`5Bn`5D.color`20!=`20g->mycolor)`20)`20`20)
  448. X`09`09`09n`20+=`20g->mydir;`09`09/*`20search`20for`20occupied`20point`20*/
  449. X`09`09if`20(`20(n`20<`201)`20`7C`7C`20(n`20>`2024)`20)`20`7B
  450. X`09`09`09FeMessage("You`20cannot`20bear`20off`20with`20that`20roll.");
  451. X`09`09`09break;
  452. X`09`09`09`7D
  453. X`09`09g->mvs`5Bi`5D.pt`20=`20n;
  454. X`09`09n`20=`20apply(g,WHO_ME,i,A_REDRAW,`26lastd);
  455. X`09`09if`20(n`20<`200)`20`7B`09/*`20move`20rejected`20*/
  456. X`09`09`09g->mvs`5Bi`5D.pt`20=`20-1;
  457. X`09`09`09FeMessage(rejlcl`5B-n`5D);
  458. X`09`09`09`7D
  459. X`09`09FeDrawMove(g,WHO_ME,i);
  460. X`09`09FeCheckContact(g);
  461. X`09`09break;
  462. X`09case`20'1':
  463. X`09case`20'2':
  464. X`09case`20'3':
  465. X`09case`20'4':
  466. X`09case`20'5':
  467. X`09case`20'6':
  468. X`09`09if`20(g->curbd`20!=`20BD_CUR)`20`7B
  469. X`09`09`09g->curbd`20=`20BD_CUR;
  470. X`09`09`09FeDrawBoard(g->board,NULL,g->mydir,0,
  471. X`09`09`09`09g->flags`20`26`20F_INVERT);
  472. X`09`09`09FeLabelBoard(g);
  473. X`09`09`09`7D
  474. X`09`09c`20-=`20'0';
  475. X`09`09if`20(`20(c`20==`20g->mvs`5B0`5D.roll)`20`26`26`20(c`20==`20g->mvs`5B1
  476. V`5D.roll)`20)`20`7B
  477. X`09`09`09for`20(i`20=`200;`20i`20<`204;`20i++)`09`09/*`20doubles`20*/
  478. X`09`09`09`09if`20(g->mvs`5Bi`5D.pt`20<`200)
  479. X`09`09`09`09`09break;
  480. X`09`09`09if`20(i`20==`204)`20`7B
  481. X`09`09`09`09FeMessage(used);
  482. X`09`09`09`09break;
  483. X`09`09`09`09`7D
  484. X`09`09`09`7D
  485. X`09`09else`20if`20(c`20==`20g->mvs`5B0`5D.roll)`20`7B`09`09/*`20used`201st`20m
  486. Vove`20*/
  487. X`09`09`09if`20(g->mvs`5B0`5D.pt`20>=`200)`20`7B
  488. X`09`09`09`09FeMessage(used);
  489. X`09`09`09`09break;
  490. X`09`09`09`09`7D
  491. X`09`09`09i`20=`200;
  492. X`09`09`09`7D
  493. X`09`09else`20`7B
  494. X`09`09`09if`20(g->mvs`5B0`5D.pt`20<`200)`20`7B`09/*`20used`202nd`20move`201st
  495. V`20*/
  496. X`09`09`09`09tmp`20=`20g->mvs`5B0`5D;`09/*`20swap`20moves`20*/
  497. X`09`09`09`09g->mvs`5B0`5D`20=`20g->mvs`5B1`5D;
  498. X`09`09`09`09g->mvs`5B1`5D`20=`20tmp;
  499. X`09`09`09`09FeDrawMove(g,WHO_ME,0);
  500. X`09`09`09`09FeDrawMove(g,WHO_ME,1);
  501. X`09`09`09`09i`20=`200;
  502. X`09`09`09`09`7D
  503. X`09`09`09else`20if`20(g->mvs`5B1`5D.pt`20>=`200)`20`7B`09/*`20this`20move`20us
  504. Ved?`20*/
  505. X`09`09`09`09FeMessage(used);
  506. X`09`09`09`09break;
  507. X`09`09`09`09`7D
  508. X`09`09`09else
  509. X`09`09`09`09i`20=`201;
  510. X`09`09`09`7D
  511. X`09`09n`20=`20FeGetPoint(g,i,lastpt,lastd);
  512. X`09`09if`20(n`20>=`200)`20`7B
  513. X`09`09`09if`20(n`20>`2025)`20`7B
  514. X`09`09`09`09FeMessage("Invalid`20point`20number");
  515. X`09`09`09`09FeDrawMove(g,WHO_ME,i);
  516. X`09`09`09`09break;
  517. X`09`09`09`09`7D
  518. X`09`09`09g->mvs`5Bi`5D.pt`20=`20n;
  519. X`09`09`09n`20=`20apply(g,WHO_ME,i,A_REDRAW,`26lastd);
  520. X`09`09`09if`20(n`20<`200)`20`7B`09/*`20move`20rejected`20*/
  521. X`09`09`09`09g->mvs`5Bi`5D.pt`20=`20-1;
  522. X`09`09`09`09FeMessage(rejlcl`5B-n`5D);
  523. X`09`09`09`09`7D
  524. X`09`09`09else
  525. X`09`09`09`09lastpt`20=`20g->mvs`5Bi`5D.pt;
  526. X`09`09`09`7D
  527. X`09`09FeDrawMove(g,WHO_ME,i);
  528. X`09`09FeCheckContact(g);
  529. X`09`09break;
  530. X`09default:
  531. X`09`09FeMessage("Invalid`20command.");
  532. X`09`09break;
  533. X`09`09`7D
  534. X`09`7D
  535. X`7D
  536. X
  537. X
  538. X/*----------------------------------------------------------------------
  539. X`20*`09myacpt`20--`20allow`20user`20to`20accept`20or`20decline`20double.
  540. X`20*
  541. X`20*`20This`20function`20allows`20the`20user`20to`20decide`20whether`20he
  542. X`20*`20wants`20to`20accept`20or`20decline`20his`20opponent's`20double.
  543. X`20*`20It`20also`20allows`20the`20user`20to`20cycle`20through`20the`20three
  544. V`20board`20displays,
  545. X`20*`20to`20concede,`20and`20to`20go`20to`20the`20next`20game.
  546. X`20*`20Rolling`20and`20doubling`20are`20not`20allowed`20here.
  547. X`20*----------------------------------------------------------------------
  548. X`20*/
  549. X
  550. Xmyacpt(g)
  551. Xstruct`20game`20*g;
  552. X`7B
  553. Xchar`20c;
  554. Xchar`20pm`20=`20'`5C0';
  555. Xint`20gv;
  556. Xstatic`20char`20*m`5B`5D`20=`20`7B"Accept","Decline","Board","Next`20Game","Qu
  557. Vit",NULL`7D;
  558. X
  559. XFeDrawMenu(m);
  560. XGameState`20=`20STATE_MYACPT;
  561. Xwhile`20(1)`20`7B
  562. X`09c`20=`20FeMenu(m,0,0,"",pm);
  563. X`09pm`20=`20c;
  564. X`09switch`20(c)`20`7B
  565. X`09case`20'A':`09`09`09`09/*`20I`20accepted`20*/
  566. X`09`09if`20(FeGetComment(g)`20<`200)`20`7B`09`09/*`20get`20message`20*/
  567. X`09`09`09FeMessage("Accept`20aborted.");
  568. X`09`09`09break;
  569. X`09`09`09`7D
  570. X`09`09g->gameval`20*=`202;`09`09/*`20the`20game`20value`20is`20doubled`20*/
  571. X`09`09g->state`20=`20ST_OPTURN;`09`09/*`20it's`20opponent's`20turn`20*/
  572. X`09`09sendpkt(g,ACPTDBL);`09`09/*`20send`20accept`20packet`20*/
  573. X`09`09return(0);`09`09`09/*`20done`20w/`20this`20game`20for`20now`20*/
  574. X`09case`20'D':`09`09`09`09/*`20I`20declined`20*/
  575. X`09`09if`20(FeGetComment(g)`20<`200)`20`7B`09`09/*`20get`20message`20*/
  576. X`09`09`09FeMessage("Decline`20aborted.");
  577. X`09`09`09break;
  578. X`09`09`09`7D
  579. X`09`09ilose(g,T_IDECLINE,0);
  580. X`09`09sendpkt(g,DECDBL);`09`09/*`20tell`20the`20opponent`20*/
  581. X`09`09return(1);`09`09`09/*`20call`20gameover()`20*/
  582. X`09case`20'B':`09`09`09`09/*`20display`20different`20board`20*/
  583. X`09`09if`20(g->curbd++`20>=`20BD_CUR)`09/*`20go`20to`20next`20board`20*/
  584. X`09`09`09g->curbd`20=`20BD_BEFOP;`09/*`20wrap`20around`20*/
  585. X`09`09return(1);`09`09/*`20redraw`20`26`20call`20us`20again`20*/
  586. X`09case`20'N':
  587. X`09`09return(0);`09`09/*`20I'm`20done`20with`20this`20game`20for`20now`20*/
  588. X`09case`20'Q':`09`09`09/*`20I`20want`20to`20quit`20ldb`20*/
  589. X`09`09return(-1);
  590. X`09default:
  591. X`09`09FeMessage("Invalid`20command.");
  592. X`09`09break;
  593. X`09`09`7D
  594. X`09`7D
  595. X`7D
  596. X
  597. X
  598. X/*----------------------------------------------------------------------
  599. X`20*`09gameover`20--`20show`20game`20to`20user`20before`20it`20is`20deleted.
  600. X`20*
  601. X`20*`20This`20function`20displays`20a`20game`20that`20has`20just`20terminated.
  602. V
  603. X`20*`20It`20displays`20the`20final`20board,`20the`20reason`20the`20game`20ende
  604. Vd,`20and`20the
  605. X`20*`20number`20of`20points`20won`20or`20lost.`20`20The`20game`20will`20be`20d
  606. Veleted`20by
  607. X`20*`20writegames()`20when`20ldb`20exits.
  608. X`20*----------------------------------------------------------------------
  609. X`20*/
  610. X
  611. Xgameover(g)
  612. Xstruct`20game`20*g;
  613. X`7B
  614. Xchar`20c,`20c1,`20c2;
  615. Xchar`20pm`20=`20'`5C0';
  616. Xint`20i;
  617. Xstatic`20char`20*m`5B`5D`20=`20`7B"Board","Next`20Game","Quit",NULL`7D;
  618. X
  619. Xif`20(g->flags`20`26`20F_DISPLAYED)`09`09/*`20this`20game`20already`20displaye
  620. Vd`20*/
  621. X`09return(0);
  622. XFeDrawMenu(m);
  623. XGameState`20=`20STATE_GAMEOVER;
  624. Xwhile`20(1)`20`7B
  625. X`09c`20=`20FeMenu(m,0,0,"`5Cn`5Cr`20",pm);
  626. X`09pm`20=`20c;
  627. X`09switch`20(c)`20`7B
  628. X`09case`20'B':`09`09`09`09/*`20display`20different`20board`20*/
  629. X`09`09if`20(g->curbd++`20>=`20BD_CUR)`09/*`20go`20to`20next`20board`20*/
  630. X`09`09`09g->curbd`20=`20BD_BEFOP;`09/*`20wrap`20around`20*/
  631. X`09`09return(1);`09`09/*`20redraw`20`26`20call`20us`20again`20*/
  632. X`09case`20'`20':
  633. X`09case`20'`5Cr':
  634. X`09case`20'`5Cn':
  635. X`09`09FeOnMenuItem(m,'N');`09/*`20highlight`20Next`20Game`20item`20*/
  636. X`09`09pm`20=`20'N';`09`09/*`20remember`20to`20unhighlight`20*/
  637. X`09`09/*`20fall`20through`20*/
  638. X`09case`20'N':`09`09`09/*`20delete`20game`20`26`20go`20to`20next`20*/
  639. X`09`09if`20(`20(g->mcurrent`5BWHO_ME`5D`20<`20g->mtotal)`20`26`26
  640. X`09`09`20`20`20`20`20(g->mcurrent`5BWHO_OPP`5D`20<`20g->mtotal)`20)`20`7B
  641. X`09`09`09g->state`20=`20ST_OPSTART;
  642. X`09`09`09if`20(`20(g->term`20==`20T_ILOSE)`20`7C`7C`20(g->term`20==`20T_OPCONC
  643. VEDE)
  644. X`09`09`09`20`20`20`20`20`7C`7C`20(g->term`20==`20T_OPDECLINE)`20)`20`7B
  645. X`09`09`09`09g->gameval`20=`201;`09/*`20reset`20for`20next`20game`20*/
  646. X`09`09`09`09g->adcnt`20=`200;
  647. X`09`09`09`09g->flags`20`26=`20`7EF_IDOUBLED;
  648. X`09`09`09`09g->term`20=`200;
  649. X`09`09`09`09clearmvs(g->mvs);
  650. X`09`09`09`09clearmvs(g->opmvs);
  651. X`09`09`09`09if`20(g->mydir`20>`200)`20`7B
  652. X`09`09`09`09`09c1`20=`20g->mycolor;
  653. X`09`09`09`09`09c2`20=`20g->opcolor;
  654. X`09`09`09`09`09`7D
  655. X`09`09`09`09else`20`7B
  656. X`09`09`09`09`09c1`20=`20g->opcolor;
  657. X`09`09`09`09`09c2`20=`20g->mycolor;
  658. X`09`09`09`09`09`7D
  659. X`09`09`09`09newboard(g->opbd,c1,c2);
  660. X`09`09`09`09newboard(g->mybd,c1,c2);
  661. X`09`09`09`09newboard(g->board,c1,c2);
  662. X`09`09`09`09for`20(i`20=`200;`20i`20<`206;`20i++)`20`7B
  663. X`09`09`09`09`09g->rolls`5Bi`5D`20=`200;
  664. X`09`09`09`09`09g->doubles`5Bi`5D`20=`200;
  665. X`09`09`09`09`09g->oprolls`5Bi`5D`20=`200;
  666. X`09`09`09`09`09g->opdoubles`5Bi`5D`20=`200;
  667. X`09`09`09`09`09`7D
  668. X`09`09`09`09crawford_check(g);
  669. X`09`09`09`09g->mvs`5B0`5D.roll`20=`20Rolldie();
  670. X`09`09`09`09sendpkt(g,MSTART);
  671. X`09`09`09`09`7D
  672. X`09`09`09`7D
  673. X`09`09else`20`7B
  674. X`09`09`09g->flags`20`7C=`20F_DISPLAYED;/*`20done`20looking`20at`20this`20game
  675. V`20*/
  676. X`09`09`09if`20(g->mtotal`20>`200)`20`7B`09/*`20finished`20match`20*/
  677. X`09`09`09`09if`20(g->term`20<=`20T_ILOSE)
  678. X`09`09`09`09`09g->ppl->score`5BSC_MLOST`5D++;
  679. X`09`09`09`09else
  680. X`09`09`09`09`09g->ppl->score`5BSC_MWON`5D++;
  681. X`09`09`09`09`7D
  682. X`09`09`09`7D
  683. X`09`09return(0);`09`09/*`20I'm`20done`20looking`20at`20this`20game`20*/
  684. X`09case`20'Q':`09`09`09/*`20delete`20game`20`26`20quit`20*/
  685. X`09`09return(-1);
  686. X`09default:
  687. X`09`09FeMessage("Invalid`20command.");
  688. X`09`09break;
  689. X`09`09`7D
  690. X`09`7D
  691. X`7D
  692. X
  693. X
  694. Xcheck_concede(g)
  695. Xstruct`20game`20*g;
  696. X`7B
  697. Xint`20gv,`20bg;
  698. Xchar`20*msg;
  699. X
  700. Xg->term`20=`20T_ICONCEDE;
  701. Xbg`20=`20gvalue(g,`26gv);
  702. Xswitch`20(bg)`20`7B
  703. Xcase`201:
  704. X`09msg`20=`20"This`20will`20score`20as`20a`20gammon.`20`20Are`20you`20sure?
  705. V`20`5Byn`5D";
  706. X`09break;
  707. Xcase`202:
  708. X`09msg`20=`20"This`20will`20score`20as`20a`20backgammon.`20`20Are`20you`20sure
  709. V?`20`5Byn`5D";
  710. X`09break;
  711. Xdefault:
  712. X`09msg`20=`20"Are`20you`20sure?`20`5Byn`5D";
  713. X`09break;
  714. X`09`7D
  715. Xreturn(FeYesNo(msg));
  716. X`7D
  717. $ call unpack PROCESS.C;1 796178223 ""
  718. $!
  719. $ create 'f'
  720. X/*`09rcvop.c`09`098/6/91
  721. X`20*
  722. X`20*`20Copyright`201991`20`20Perry`20R.`20Ross
  723. X`20*
  724. X`20*`20Permission`20to`20use,`20copy,`20modify,`20and`20distribute`20this`20so
  725. Vftware`20and`20its
  726. X`20*`20documentation`20without`20fee`20is`20hereby`20granted,`20subject`20to
  727. V`20the`20restrictions
  728. X`20*`20detailed`20in`20the`20README`20file,`20which`20is`20included`20here`20b
  729. Vy`20reference.
  730. X`20*`20Any`20other`20use`20requires`20written`20permission`20from`20the`20auth
  731. Vor.`20`20This`20software
  732. X`20*`20is`20distributed`20"as`20is"`20without`20any`20warranty,`20including
  733. V`20any`20implied
  734. X`20*`20warranties`20of`20merchantability`20or`20fitness`20for`20a`20particular
  735. V`20purpose.
  736. X`20*`20The`20author`20shall`20not`20be`20liable`20for`20any`20damages`20result
  737. Ving`20from`20the
  738. X`20*`20use`20of`20this`20software.`20`20By`20using`20this`20software,`20the
  739. V`20user`20agrees
  740. X`20*`20to`20these`20terms.
  741. X`20*/
  742. X
  743. X#include`20"ldb.h"
  744. X
  745. X/*===========================================================================
  746. X`20*`20This`20file`20contains`20the`20functions`20which`20make`20up`20the`20re
  747. Vceive`20state
  748. X`20*`20machine.`20`20These`20are`20called`20through`20the`20func`5B`5D`5B`5D
  749. V`20matrix,`20which`20takes
  750. X`20*`20the`20current`20state`20and`20a`20received`20operation`20and`20calls
  751. V`20the`20appropriate
  752. X`20*`20handler`20function.`20`20These`20functions`20will`20typically`20change
  753. V`20the`20game
  754. X`20*`20state`20into`20one`20requiring`20user`20input`20at`20this`20host`20(ST_
  755. VMY*),`20and`20return.
  756. X`20*==========================================================================
  757. V=
  758. X`20*/
  759. X
  760. X
  761. X/*---------------------------------------------------------------------------
  762. X`20*`09start`20--`20initiate`20a`20game
  763. X`20*
  764. X`20*`20This`20function`20is`20called`20when`20a`20remote`20user`20starts`20a
  765. V`20game`20with`20us.
  766. X`20*`20We`20store`20his`20personal`20information`20(opaddr`20`26`20opname),
  767. V`20roll`201`20die,
  768. X`20*`20and`20compare`20it`20to`20the`20one`20he`20sent.`20`20If`20we`20won`20t
  769. Vhe`20roll,`20the`20roll
  770. X`20*`20is`20stored`20in`20mvs`5B`5D`20and`20state`20is`20set`20to`20MYMOVE.
  771. V`20`20If`20we`20lost`20the`20roll,
  772. X`20*`20both`20dice`20are`20sent`20back`20in`20a`20USTART`20line.`20`20If`20the
  773. V`20roll`20was`20a`20tie,
  774. X`20*`20a`20TIE`20packet`20is`20sent`20back`20.`20`20The`20originator`20will
  775. V`20re-roll`20and`20send
  776. X`20*`20us`20a`20RESTART`20packet,`20which`20will`20repeat`20the`20opening`20ro
  777. Vll.
  778. X`20*--------------------------------------------------------------------------
  779. V-
  780. X`20*/
  781. X
  782. Xstart(g)
  783. Xstruct`20game`20*g;
  784. X`7B
  785. Xint`20mydie;
  786. Xchar`20c1,`20c2;
  787. X
  788. Xg->opaddr`20=`20P.addr;`09/*`20save`20mail`20address`20of`20opponent`20*/
  789. Xg->gameid`20=`20P.gameid;`09`09/*`20copy`20game`20id`20*/
  790. Xg->opver`20=`20P.version;`09`09/*`20save`20opponent's`20ldb`20version`20*/
  791. Xg->mycolor`20=`20P.colors`5B1`5D;`09/*`20copy`20out`20colors`20*/
  792. Xg->opcolor`20=`20P.colors`5B0`5D;
  793. Xif`20(isupper(*P.dir))
  794. X`09*P.dir`20=`20tolower(*P.dir);
  795. Xg->mydir`20=`20(*P.dir`20==`20'u')`20?`201`20:`20-1;`09/*`20copy`20out`20direc
  796. Vtions`20*/
  797. Xg->opdir`20=`20REV(g->mydir);
  798. Xg->gameval`20=`201;`09`09`09/*`20no`20doubles`20yet`20*/
  799. Xg->flags`20=`200;
  800. Xg->seq`20=`202;`09`09`09/*`20we`20rcvd`201`20pkt`20already,`20init`20to`202
  801. V`20*/
  802. Xif`20(`20(g->ppl`20=`20findppl(g->opaddr,P_ADDR))`20==`20NULL)`20`7B`20/*`20kn
  803. Vow`20this`20guy?`20*/
  804. X`09g->myaddr`20=`20save(rc.myaddr);`09/*`20nope,`20create`20a`20new`20ppl`20re
  805. Vcord`20*/
  806. X`09newppl(g);
  807. X`09`7D
  808. Xelse
  809. X`09g->myaddr`20=`20save(g->ppl->myaddr);
  810. Xg->starttime`20=`20P.timestamp;`09/*`20store`20timestamp`20from`20start`20pack
  811. Vet`20*/
  812. Xg->lastacc`20=`20P.timestamp;`09/*`20set`20last`20access`20time`20to`20start
  813. V`20time`20*/
  814. Xif`20(P.autodbl`20==`20NULL)`09`09/*`20set`20admax`20to`20MIN(my`20count,`20op
  815. V's`20count)`20*/
  816. X`09g->admax`20=`200;
  817. Xelse
  818. X`09g->admax`20=`20atoi(P.autodbl);
  819. Xif`20(rc.autodouble`20<`20g->admax)
  820. X`09g->admax`20=`20rc.autodouble;
  821. Xg->adcnt`20=`200;`09`09`09/*`20no`20autodoubles`20yet`20*/
  822. Xclearmvs(g->mvs);
  823. Xclearmvs(g->opmvs);
  824. Xif`20(g->mydir`20>`200)`20`7B
  825. X`09c1`20=`20g->mycolor;`09/*`20upbound`20color`20is`20mine`20*/
  826. X`09c2`20=`20g->opcolor;`09/*`20downbound`20color`20is`20opponent's`20*/
  827. X`09`7D
  828. Xelse`20`7B
  829. X`09c1`20=`20g->opcolor;`09/*`20upbound`20color`20is`20opponent's`20*/
  830. X`09c2`20=`20g->mycolor;`09/*`20downbound`20color`20is`20mine`20*/
  831. X`09`7D
  832. Xnewboard(g->opbd,c1,c2);`09`09/*`20set`20up`20boards`20for`20new`20game`20*/
  833. Xnewboard(g->mybd,c1,c2);
  834. Xnewboard(g->board,c1,c2);
  835. Xif`20(P.jacoby`20!=`20NULL)
  836. X`09g->flags`20`7C=`20F_JACOBY;
  837. Xif`20(P.crawford`20!=`20NULL)
  838. X`09g->flags`20`7C=`20F_CRAWFORD;
  839. Xif`20(P.european`20!=`20NULL)
  840. X`09g->flags`20`7C=`20F_EUROPE;
  841. Xif`20(P.perm`20!=`20NULL)
  842. X`09g->flags`20`7C=`20F_PERM;
  843. Xif`20(P.match`20!=`20NULL)
  844. X`09g->mtotal`20=`20atoi(P.match);
  845. Xg->curbd`20=`20boardnums`5B*rc.initboard`20-`20'a'`5D;`09/*`20display`20initia
  846. Vl`20board`20*/
  847. Xmydie`20=`20Rolldie();
  848. Xif`20(P.mvs`5B0`5D.roll`20==`20mydie)`20`7B`09`09/*`20a`20!#$%`26@`20tie`20*/
  849. X`09if`20(g->adcnt`20<`20g->admax)`09/*`20do`20an`20autodouble`20*/
  850. X`09`09g->gameval`20=`201`20<<`20++(g->adcnt);
  851. X`09sendpkt(g,TIE);
  852. X`09message("Tie`20on`20initial`20roll`20with`20%s`20(%s).`5Cn",g->opname,g->op
  853. Vaddr);
  854. X`09return;`09`09`09/*`20opponent`20will`20send`20RESTART`20*/
  855. X`09`7D
  856. Xif`20(mydie`20>`20(int)`20P.mvs`5B0`5D.roll)`20`7B`09`09/*`20we`20won`20the
  857. V`20initial`20roll`20*/
  858. X`09g->mvs`5B0`5D.roll`20=`20P.mvs`5B0`5D.roll;`09/*`20copy`20initial`20roll
  859. V`20*/
  860. X`09g->mvs`5B1`5D.roll`20=`20mydie;
  861. X`09g->mvs`5B0`5D.pt`20=`20-1;`09/*`20mark`20both`20rolls`20unused`20*/
  862. X`09g->mvs`5B1`5D.pt`20=`20-1;
  863. X`09g->state`20=`20ST_MYMOVE;`09/*`20set`20state`20so`20we`20make`20a`20move
  864. V`20*/
  865. X`09legalmoves(g);`09`09/*`20calculate`20legal`20moves`20for`20these`20rolls
  866. V`20*/
  867. X`09g->rolls`5Bg->mvs`5B0`5D.roll`20-`201`5D++;`09/*`20count`20the`20rolls`20we
  868. V`20got`20*/
  869. X`09g->rolls`5Bg->mvs`5B1`5D.roll`20-`201`5D++;
  870. X`09`7D
  871. Xelse`20`7B`09`09`09`09/*`20we`20lost,`20tell`20the`20opponent`20to`20start`20*
  872. V/
  873. X`09g->mvs`5B0`5D.roll`20=`20P.mvs`5B0`5D.roll;`09/*`20copy`20initial`20roll
  874. V`20*/
  875. X`09g->mvs`5B1`5D.roll`20=`20mydie;`09/*`20store`20so`20sendpkt`20can`20find
  876. V`20it`20*/
  877. X`09g->state`20=`20ST_OPTURN;
  878. X`09sendpkt(g,USTART);
  879. X`09message("Started`20game`20with`20%s`20(%s).`5Cn",g->opname,g->opaddr);
  880. X`09`7D
  881. X`7D
  882. X
  883. X
  884. X/*---------------------------------------------------------------------------
  885. X`20*`09istart`20--`20I`20won`20the`20opening`20toss
  886. X`20*
  887. X`20*`20This`20function`20is`20called`20when`20a`20USTART`20packet`20is`20recei
  888. Vved.`20`20Both`20rolls
  889. X`20*`20are`20copied`20into`20the`20game`20structure`20and`20the`20state`20is
  890. V`20set`20to`20MYMOVE,
  891. X`20*`20allowing`20us`20to`20use`20the`20roll`20but`20not`20to`20double.
  892. X`20*--------------------------------------------------------------------------
  893. V-
  894. X`20*/
  895. X
  896. Xistart(g)
  897. Xstruct`20game`20*g;
  898. X`7B
  899. X
  900. Xg->mvs`5B0`5D.roll`20=`20P.mvs`5B0`5D.roll;`09/*`20copy`20rolls`20from`20packe
  901. Vt`20*/
  902. Xg->mvs`5B1`5D.roll`20=`20P.mvs`5B1`5D.roll;
  903. Xg->mvs`5B0`5D.pt`20=`20-1;`09/*`20mark`20both`20rolls`20unused`20*/
  904. Xg->mvs`5B1`5D.pt`20=`20-1;
  905. Xg->state`20=`20ST_MYMOVE;`09/*`20set`20state`20so`20we`20make`20a`20move`20*/
  906. Xlegalmoves(g);`09`09/*`20calculate`20legal`20moves`20*/
  907. Xg->rolls`5Bg->mvs`5B0`5D.roll`20-`201`5D++;`09/*`20count`20the`20rolls`20we
  908. V`20got`20*/
  909. Xg->rolls`5Bg->mvs`5B1`5D.roll`20-`201`5D++;
  910. X`7D
  911. X
  912. X
  913. X/*---------------------------------------------------------------------------
  914. X`20*`09tie`20--`20The`20opening`20toss`20was`20a`20tie,`20try`20again
  915. X`20*
  916. X`20*`20This`20function`20is`20called`20when`20we`20receive`20a`20TIE`20packet.
  917. V`20`20We`20reroll
  918. X`20*`20one`20die`20and`20send`20a`20RESTART`20packet.`20`20If`20the`20autodbl
  919. V`20field`20in
  920. X`20*`20the`20received`20packet`20is`20>`200,`20the`20game`20value`20is`20set
  921. V`20to`202`20**`20autodbl.
  922. X`20*--------------------------------------------------------------------------
  923. V-
  924. X`20*/
  925. X
  926. Xtie(g)
  927. Xstruct`20game`20*g;
  928. X`7B
  929. X
  930. Xclearmvs(g->mvs);
  931. Xg->mvs`5B0`5D.roll`20=`20Rolldie();
  932. Xif`20(P.autodbl`20!=`20NULL)
  933. X`09g->gameval`20=`201`20<<`20(g->adcnt`20=`20atoi(P.autodbl));
  934. Xsendpkt(g,RESTART);
  935. Xmessage("Tie`20on`20initial`20roll`20with`20%s`20(%s).`5Cn",g->opname,g->opadd
  936. Vr);
  937. X`7D
  938. X
  939. X
  940. X/*---------------------------------------------------------------------------
  941. X`20*`09restart`20--`20restart`20after`20opening`20tie
  942. X`20*
  943. X`20*`20This`20function`20is`20called`20when`20we`20receive`20a`20RESTART`20pac
  944. Vket.`20`20It`20is
  945. X`20*`20mostly`20the`20same`20as`20start().
  946. X`20*--------------------------------------------------------------------------
  947. V-
  948. X`20*/
  949. X
  950. Xrestart(g)
  951. Xstruct`20game`20*g;
  952. X`7B
  953. Xint`20mydie;
  954. X
  955. Xclearmvs(g->mvs);
  956. Xclearmvs(g->opmvs);
  957. Xmydie`20=`20Rolldie();
  958. Xif`20(P.mvs`5B0`5D.roll`20==`20mydie)`20`7B`09`09/*`20a`20!#$%`26@`20tie`20*/
  959. X`09if`20(g->adcnt`20<`20g->admax)`09/*`20do`20an`20autodouble`20*/
  960. X`09`09g->gameval`20=`201`20<<`20++(g->adcnt);
  961. X`09sendpkt(g,TIE);
  962. X`09message("Tie`20on`20initial`20roll`20with`20%s`20(%s).`5Cn",g->opname,g->op
  963. Vaddr);
  964. X`09return;`09`09`09/*`20opponent`20will`20send`20RESTART`20*/
  965. X`09`7D
  966. Xg->mvs`5B0`5D.roll`20=`20P.mvs`5B0`5D.roll;`09/*`20copy`20initial`20roll`20*/
  967. Xg->mvs`5B1`5D.roll`20=`20mydie;`09/*`20store`20so`20sendpkt`20can`20find`20it
  968. V`20*/
  969. Xif`20(mydie`20>`20(int)`20P.mvs`5B0`5D.roll)`20`7B`09`09/*`20we`20won`20the
  970. V`20initial`20roll`20*/
  971. X`09g->state`20=`20ST_MYMOVE;`09/*`20set`20state`20so`20we`20make`20a`20move
  972. V`20*/
  973. X`09legalmoves(g);`09`09/*`20calculate`20legal`20moves`20for`20these`20rolls
  974. V`20*/
  975. X`09g->rolls`5Bg->mvs`5B0`5D.roll`20-`201`5D++;`09/*`20count`20the`20rolls`20we
  976. V`20got`20*/
  977. X`09g->rolls`5Bg->mvs`5B1`5D.roll`20-`201`5D++;
  978. X`09`7D
  979. Xelse`20`7B`09`09`09`09/*`20we`20lost,`20tell`20the`20opponent`20to`20start`20*
  980. V/
  981. X`09g->state`20=`20ST_OPTURN;
  982. X`09sendpkt(g,USTART);
  983. X`09message("Started`20game`20with`20%s`20(%s).`5Cn",g->opname,g->opaddr);
  984. X`09`7D
  985. X`7D
  986. X
  987. X
  988. X/*---------------------------------------------------------------------------
  989. X`20*`09mstart`20--`20start`20next`20game`20of`20match
  990. X`20*
  991. X`20*`20This`20function`20is`20called`20when`20we`20receive`20an`20MSTART`20pac
  992. Vket.`20`20It`20is
  993. X`20*`20similar`20to`20restart,`20except`20that`20it`20also`20reinitializes`20t
  994. Vhe`20game
  995. X`20*`20structure`20for`20the`20next`20game`20of`20the`20match.`20`20All`20game
  996. Vs`20of`20a`20match
  997. X`20*`20use`20the`20same`20gameid`20and`20game`20structure.`20`20Mstart`20also
  998. V`20checks`20to
  999. X`20*`20see`20if`20this`20is`20a`20Crawford`20rule`20game,`20and`20if`20so,`20s
  1000. Vets`20F_CRGAME`20in`20g->flags.
  1001. X`20*--------------------------------------------------------------------------
  1002. V-
  1003. X`20*/
  1004. X
  1005. Xmstart(g)
  1006. Xstruct`20game`20*g;
  1007. X`7B
  1008. Xint`20mydie;
  1009. Xint`20i;
  1010. Xchar`20c1,`20c2;
  1011. X
  1012. Xg->state`20=`20ST_OPSTART;
  1013. Xg->gameval`20=`201;`09`09/*`20reset`20for`20next`20game`20*/
  1014. Xg->adcnt`20=`200;
  1015. Xg->flags`20`26=`20`7EF_IDOUBLED;
  1016. Xg->term`20=`200;
  1017. Xif`20(g->mydir`20>`200)`20`7B
  1018. X`09c1`20=`20g->mycolor;`09/*`20upbound`20color`20is`20mine`20*/
  1019. X`09c2`20=`20g->opcolor;`09/*`20downbound`20color`20is`20opponent's`20*/
  1020. X`09`7D
  1021. Xelse`20`7B
  1022. X`09c1`20=`20g->opcolor;`09/*`20upbound`20color`20is`20opponent's`20*/
  1023. X`09c2`20=`20g->mycolor;`09/*`20downbound`20color`20is`20mine`20*/
  1024. X`09`7D
  1025. Xnewboard(g->opbd,c1,c2);
  1026. Xnewboard(g->mybd,c1,c2);
  1027. Xnewboard(g->board,c1,c2);
  1028. Xfor`20(i`20=`200;`20i`20<`206;`20i++)`20`7B
  1029. X`09g->rolls`5Bi`5D`20=`200;
  1030. X`09g->doubles`5Bi`5D`20=`200;
  1031. X`09g->oprolls`5Bi`5D`20=`200;
  1032. X`09g->opdoubles`5Bi`5D`20=`200;
  1033. X`09`7D
  1034. Xclearmvs(g->mvs);
  1035. Xclearmvs(g->opmvs);
  1036. Xcrawford_check(g);`09`09`09/*`20is`20this`20the`20Crawford`20rule`20game?`20*/
  1037. V
  1038. Xmydie`20=`20Rolldie();
  1039. Xif`20(P.mvs`5B0`5D.roll`20==`20mydie)`20`7B`09`09/*`20a`20!#$%`26@`20tie`20*/
  1040. X`09if`20(g->adcnt`20<`20g->admax)`09/*`20do`20an`20autodouble`20*/
  1041. X`09`09g->gameval`20=`201`20<<`20++(g->adcnt);
  1042. X`09sendpkt(g,TIE);
  1043. X`09message("Tie`20on`20initial`20roll`20with`20%s`20(%s).`5Cn",g->opname,g->op
  1044. Vaddr);
  1045. X`09return;`09`09`09/*`20opponent`20will`20send`20RESTART`20*/
  1046. X`09`7D
  1047. Xg->mvs`5B0`5D.roll`20=`20P.mvs`5B0`5D.roll;`09/*`20copy`20initial`20roll`20*/
  1048. Xg->mvs`5B1`5D.roll`20=`20mydie;`09/*`20store`20so`20sendpkt`20can`20find`20it
  1049. V`20*/
  1050. Xif`20(mydie`20>`20(int)`20P.mvs`5B0`5D.roll)`20`7B`09`09/*`20we`20won`20the
  1051. V`20initial`20roll`20*/
  1052. X`09g->state`20=`20ST_MYMOVE;`09/*`20set`20state`20so`20we`20make`20a`20move
  1053. V`20*/
  1054. X`09legalmoves(g);`09`09/*`20calculate`20legal`20moves`20for`20these`20rolls
  1055. V`20*/
  1056. X`09g->rolls`5Bg->mvs`5B0`5D.roll`20-`201`5D++;`09/*`20count`20the`20rolls`20we
  1057. V`20got`20*/
  1058. X`09g->rolls`5Bg->mvs`5B1`5D.roll`20-`201`5D++;
  1059. X`09`7D
  1060. Xelse`20`7B`09`09`09`09/*`20we`20lost,`20tell`20the`20opponent`20to`20start`20*
  1061. V/
  1062. X`09g->state`20=`20ST_OPTURN;
  1063. X`09sendpkt(g,USTART);
  1064. X`09message("Started`20game`20with`20%s`20(%s).`5Cn",g->opname,g->opaddr);
  1065. X`09`7D
  1066. X`7D
  1067. X
  1068. X
  1069. X/*---------------------------------------------------------------------------
  1070. X`20*`09opmove`20--`20opponent`20moved
  1071. X`20*
  1072. X`20*`20This`20function`20is`20called`20when`20we`20receive`20a`20MOVE`20packet
  1073. V.`20`20The`20move`20is
  1074. X`20*`20copied`20into`20the`20opmvs`20field`20of`20the`20game`20structure`20and
  1075. V`20applied`20to`20the
  1076. X`20*`20board.`20`20A`20copy`20of`20the`20board`20before`20the`20moves`20are
  1077. V`20applied`20is`20stored
  1078. X`20*`20in`20the`20opbd`20field,`20and`20a`20copy`20of`20the`20board`20after
  1079. V`20the`20moves`20are`20applied
  1080. X`20*`20is`20stored`20in`20the`20mybd`20field.`20`20These`20two`20boards,`20alo
  1081. Vng`20with`20the
  1082. X`20*`20current`20board`20in`20the`20board`20field,`20make`20up`20the`20three
  1083. V`20boards`20that`20can
  1084. X`20*`20be`20displayed`20with`20the`20"Board"`20command`20in`20the`20user`20men
  1085. Vus`20in`20process.c
  1086. X`20*--------------------------------------------------------------------------
  1087. V-
  1088. X`20*/
  1089. X
  1090. Xopmove(g)
  1091. Xstruct`20game`20*g;
  1092. X`7B
  1093. Xint`20i,`20n,`20r;
  1094. Xstatic`20char`20buf`5B`5D`20=`20"Opponent`20move`20dated`20DDD`20MMM`20NN`20HH
  1095. V:MM:SS`20YYYY";
  1096. Xstruct`20game`20*pg;
  1097. X
  1098. Xcopyboard(g->board,g->opbd);`09/*`20save`20board`20before`20opponent`20moved
  1099. V`20*/
  1100. Xg->curbd`20=`20boardnums`5B*rc.initboard`20-`20'a'`5D;`09/*`20display`20initia
  1101. Vl`20board`20*/
  1102. Xclearmvs(g->opmvs);`09`09/*`20clear`20old`20moves`20*/
  1103. Xg->opmvs`5B0`5D`20=`20P.mvs`5B0`5D;`09/*`20extract`20opponent's`20moves`20*/
  1104. Xg->opmvs`5B1`5D`20=`20P.mvs`5B1`5D;
  1105. Xg->oprolls`5Bg->opmvs`5B0`5D.roll`20-`201`5D++;`09`09/*`20count`20rolls`20oppo
  1106. Vnent`20got`20*/
  1107. Xg->oprolls`5Bg->opmvs`5B1`5D.roll`20-`201`5D++;
  1108. Xif`20(g->opmvs`5B0`5D.roll`20==`20g->opmvs`5B1`5D.roll)`20`7B
  1109. X`09g->opmvs`5B2`5D`20=`20P.mvs`5B2`5D;`09/*`20he`20got`20doubles`20*/
  1110. X`09g->opmvs`5B3`5D`20=`20P.mvs`5B3`5D;`09/*`20extract`202`20more`20moves`20*/
  1111. X`09g->opdoubles`5Bg->opmvs`5B0`5D.roll`20-`201`5D++;
  1112. X`09n`20=`204;
  1113. X`09`7D
  1114. Xelse
  1115. X`09n`20=`202;
  1116. Xfor`20(i`20=`200;`20i`20<`204;`20i++)
  1117. X`09g->blot`5Bi`5D`20=`200;`09`09/*`20clear`20all`20blot`20locations`20*/
  1118. Xfor`20(i`20=`200;`20i`20<`20n;`20i++)`20`7B
  1119. X`09if`20(`20(r`20=`20apply(g,WHO_OPP,i,0,NULL))`20<`200)`20`7B`09/*`20err`20w/
  1120. V`20op`20move`20*/
  1121. X`09`09copyboard(g->opbd,g->board);`09/*`20restore`20board`20*/
  1122. X`09`09message("ERROR:`20Opponent`20move`20rejected,`20id=%s`5Cn",
  1123. X`09`09`09P.gameid);
  1124. X`09`09message("`20`20`20`20`20`20`20%s`5Cn",rejmsg`5B-r`5D);
  1125. X`09`09return;
  1126. X`09`09`7D
  1127. X`09else`09`09/*`20if`20opponent`20hit`20our`20blot`20*/
  1128. X`09`09g->blot`5Bi`5D`20=`20r;`09`09/*`20save`20location`20*/
  1129. X`09`7D
  1130. Xcopyboard(g->board,g->mybd);`09`09/*`20save`20board`20after`20op`20move`20*/
  1131. Xif`20(g->board`5BOFFPT(g->opdir)`5D.qty`20==`2015)`09/*`20opponent`20won`20*/
  1132. X`09ilose(g,T_ILOSE,1);
  1133. Xelse
  1134. X`09g->state`20=`20ST_MYTURN;`09`09/*`20opponent`20has`20moved,`20it's`20our
  1135. V`20turn`20*/
  1136. Xclearmvs(g->mvs);`09`09/*`20erase`20our`20previous`20move`20*/
  1137. Xif`20(P.timestamp`20>`200)`20`7B`09`09/*`20if`20we`20got`20a`20timestamp`20*/
  1138. X`09strncpy(`26buf`5B20`5D,ctime(`26P.timestamp),24);`09/*`20gen`20message`20*/
  1139. V
  1140. X`09g->dispmsg`20=`20save(buf);`09`09/*`20save`20copy`20in`20game`20*/
  1141. X`09`7D
  1142. X`7D
  1143. X
  1144. X
  1145. X/*---------------------------------------------------------------------------
  1146. X`20*`09opofr`20--`20opponent`20offered`20to`20double
  1147. X`20*
  1148. X`20*`20This`20function`20is`20called`20when`20we`20receive`20an`20OFRDBL`20pac
  1149. Vket,`20indicating
  1150. X`20*`20the`20opponent`20wishes`20to`20double.`20`20The`20game`20moves`20to`20s
  1151. Vtate`20MYACCEPT,
  1152. X`20*`20where`20the`20user`20will`20decide`20to`20accept`20or`20decline`20the
  1153. V`20double.
  1154. X`20*--------------------------------------------------------------------------
  1155. V-
  1156. X`20*/
  1157. X
  1158. Xopofr(g)
  1159. Xstruct`20game`20*g;
  1160. X`7B
  1161. X
  1162. Xif`20(g->flags`20`26`20F_CRGAME)`20`7B
  1163. X`09message("ERROR:`20Opponent`20move`20rejected,`20id=%s`5Cn",P.gameid);
  1164. X`09message("`20`20`20`20`20`20`20Invalid`20double`20(Crawford`20rule)`5Cn");
  1165. X`09return;
  1166. X`09`7D
  1167. Xg->state`20=`20ST_MYACCEPT;`09`09`09/*`20send`20us`20to`20an`20accept`20screen
  1168. V`20*/
  1169. Xg->flags`20`26=`20`7EF_IDOUBLED;`09`09/*`20I`20didn't`20double`20last`20*/
  1170. Xcopyboard(g->board,g->opbd);
  1171. Xcopyboard(g->board,g->mybd);
  1172. Xg->curbd`20=`20BD_CUR;`09`09/*`20display`20current`20board`20*/
  1173. Xclearmvs(g->opmvs);`09`09/*`20clear`20old`20moves`20*/
  1174. Xclearmvs(g->mvs);`09`09/*`20erase`20our`20previous`20move`20*/
  1175. X`7D
  1176. X
  1177. X
  1178. X/*---------------------------------------------------------------------------
  1179. X`20*`09opconc`20--`20opponent`20conceded
  1180. X`20*
  1181. X`20*`20This`20function`20is`20called`20when`20we`20receive`20a`20CONCEDE`20pac
  1182. Vket,`20indicating
  1183. X`20*`20the`20opponent`20has`20given`20up.
  1184. X`20*--------------------------------------------------------------------------
  1185. V-
  1186. X`20*/
  1187. X
  1188. Xopconc(g)
  1189. Xstruct`20game`20*g;
  1190. X`7B
  1191. Xint`20gv;
  1192. X
  1193. Xiwin(g,T_OPCONCEDE,1);`09`09`09/*`20wimp`20*/
  1194. X`7D
  1195. X
  1196. X
  1197. X/*---------------------------------------------------------------------------
  1198. X`20*`09opacpt`20--`20opponent`20accepted`20double
  1199. X`20*
  1200. X`20*`20This`20function`20is`20called`20when`20we`20receive`20an`20ACPTDBL`20pa
  1201. Vcket,`20indicating
  1202. X`20*`20the`20opponent`20has`20accepted`20our`20double.`20`20The`20IDOUBLED`20f
  1203. Vlag`20is`20set`20to
  1204. X`20*`20prevent`20us`20from`20doubling`20again`20until`20the`20opponent`20doubl
  1205. Ves.`20`20Since`20it
  1206. X`20*`20is`20now`20our`20turn,`20we`20go`20ahead`20and`20roll`20the`20dice`20an
  1207. Vd`20proceed`20to`20the
  1208. X`20*`20MYMOVE`20state.
  1209. X`20*--------------------------------------------------------------------------
  1210. V-
  1211. X`20*/
  1212. X
  1213. Xopacpt(g)
  1214. Xstruct`20game`20*g;
  1215. X`7B
  1216. X
  1217. Xg->gameval`20*=`202;`09`09/*`20double`20game`20value`20*/
  1218. Xg->flags`20`7C=`20F_IDOUBLED;`09`09/*`20I`20doubled`20last`20*/
  1219. Xg->state`20=`20ST_MYMOVE;`09`09/*`20It`20is`20my`20move`20*/
  1220. Xcopyboard(g->board,g->opbd);
  1221. Xcopyboard(g->board,g->mybd);
  1222. Xg->curbd`20=`20BD_CUR;`09`09/*`20display`20current`20board`20*/
  1223. Xclearmvs(g->opmvs);`09`09/*`20clear`20old`20moves`20*/
  1224. Xclearmvs(g->mvs);`09`09/*`20erase`20our`20previous`20move`20*/
  1225. Xrolldice(g);`09`09`09/*`20go`20ahead`20and`20roll,`20I`20can't`20double`20*/
  1226. Xg->dispmsg`20=`20save("Opponent`20has`20accepted`20your`20double.");/*`20notif
  1227. Vy`20user`20*/
  1228. X`7D
  1229. X
  1230. X
  1231. X/*---------------------------------------------------------------------------
  1232. X`20*`09opdec`20--`20opponent`20declined`20double
  1233. X`20*
  1234. X`20*`20This`20function`20is`20called`20when`20a`20DECDBL`20packet`20is`20recei
  1235. Vved.`20`20This
  1236. X`20*`20indicates`20that`20the`20opponent`20has`20declined`20our`20double,`20an
  1237. Vd`20the`20game`20is`20over.
  1238. X`20*--------------------------------------------------------------------------
  1239. V-
  1240. X`20*/
  1241. X
  1242. Xopdec(g)
  1243. Xstruct`20game`20*g;
  1244. X`7B
  1245. Xint`20gv;
  1246. X
  1247. Xiwin(g,T_OPDECLINE,1);
  1248. Xcopyboard(g->board,g->opbd);
  1249. Xcopyboard(g->board,g->mybd);
  1250. Xg->curbd`20=`20BD_CUR;`09`09/*`20display`20current`20board`20*/
  1251. Xclearmvs(g->opmvs);`09`09/*`20clear`20old`20moves`20*/
  1252. Xclearmvs(g->mvs);`09`09/*`20erase`20our`20previous`20move`20*/
  1253. X`7D
  1254. X
  1255. X
  1256. X/*---------------------------------------------------------------------------
  1257. X`20*`09smerr`20--`20an`20illegal`20operation`20was`20received`20for`20this`20s
  1258. Vtate
  1259. X`20*
  1260. X`20*`20This`20function`20is`20called`20when`20a`20packet`20is`20received`20tha
  1261. Vt`20is`20invalid
  1262. X`20*`20for`20the`20game`20state.`20`20An`20example`20of`20this`20would`20be
  1263. V`20receiving`20an
  1264. X`20*`20ACPTDBL`20packet`20when`20we`20did`20not`20send`20an`20OFRDBL.
  1265. X`20*--------------------------------------------------------------------------
  1266. V-
  1267. X`20*/
  1268. X
  1269. Xsmerr(g)
  1270. Xstruct`20game`20*g;
  1271. X`7B
  1272. X
  1273. Xmessage("ERROR:`20invalid`20operation`20(%d)`20for`20state`20(%d),`20id=%s`5Cn
  1274. V",
  1275. X`09P.opcode,`20g->state,`20g->gameid);
  1276. X`7D
  1277. $ call unpack RCVOP.C;1 861626388 ""
  1278. $!
  1279. $ create 'f'
  1280. X/*`09readmail.c`09`098/7/91
  1281. X`20*
  1282. X`20*`20Copyright`201991`20`20Perry`20R.`20Ross
  1283. X`20*
  1284. X`20*`20Permission`20to`20use,`20copy,`20modify,`20and`20distribute`20this`20so
  1285. Vftware`20and`20its
  1286. X`20*`20documentation`20without`20fee`20is`20hereby`20granted,`20subject`20to
  1287. V`20the`20restrictions
  1288. X`20*`20detailed`20in`20the`20README`20file,`20which`20is`20included`20here`20b
  1289. Vy`20reference.
  1290. X`20*`20Any`20other`20use`20requires`20written`20permission`20from`20the`20auth
  1291. Vor.`20`20This`20software
  1292. X`20*`20is`20distributed`20"as`20is"`20without`20any`20warranty,`20including
  1293. V`20any`20implied
  1294. X`20*`20warranties`20of`20merchantability`20or`20fitness`20for`20a`20particular
  1295. V`20purpose.
  1296. X`20*`20The`20author`20shall`20not`20be`20liable`20for`20any`20damages`20result
  1297. Ving`20from`20the
  1298. X`20*`20use`20of`20this`20software.`20`20By`20using`20this`20software,`20the
  1299. V`20user`20agrees
  1300. X`20*`20to`20these`20terms.
  1301. X`20*/
  1302. X
  1303. X#include`20"ldb.h"
  1304. X
  1305. X/*----------------------------------------------------------------------
  1306. X`20*`09readmail`20--`20read`20the`20incoming`20mail`20and`20process`20it
  1307. X`20*
  1308. X`20*`20This`20function`20extracts`20each`20packet`20from`20the`20mail`20file
  1309. V`20and`20applies`20it
  1310. X`20*`20to`20the`20appropriate`20game`20structure.`20`20Most`20packets`20are
  1311. V`20processed`20by
  1312. X`20*`20calling`20the`20handler`20found`20in`20the`20func`20array,`20which`20is
  1313. V`20a`202-dimensional
  1314. X`20*`20array`20indexed`20by`20the`20current`20game`20state`20and`20the`20recei
  1315. Vved`20opcode.
  1316. X`20*`20The`20handlers`20are`20responsible`20for`20transforming`20the`20game
  1317. V`20state`20as
  1318. X`20*`20necessary.`20`20The`20START`20and`20RSTART`20opcodes`20receive`20specia
  1319. Vl`20processing,
  1320. X`20*`20since`20they`20apply`20to`20games`20that`20do`20not`20exist`20and`20thu
  1321. Vs`20have`20no`20state.
  1322. X`20*`20START`20packets`20result`20in`20the`20creation`20of`20a`20game,`20whose
  1323. V`20state`20is`20set
  1324. X`20*`20such`20that`20the`20correct`20handler`20will`20be`20called.`20`20The
  1325. V`20RSTART`20opcode
  1326. X`20*`20is`20processed`20in`20the`20same`20way`20as`20the`20-start`20command
  1327. V`20line`20argument;
  1328. X`20*`20the`20packet`20is`20then`20discarded.
  1329. X`20*
  1330. +-+-+-+-+-+-+-+-  END  OF PART 12 +-+-+-+-+-+-+-+-
  1331.