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 >
Wrap
Internet Message Format
|
1993-04-07
|
49KB
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
From: ake@dayvd.dayton.saic.com (Earle Ake)
Newsgroups: vmsnet.sources.games
Subject: ldb - Long Distance Backgammon [07/16]
Date: 8 Apr 93 10:56:49 EST
Organization: Science Applications Intl Corp - Dayton, OH
Lines: 1365
Message-ID: <1993Apr8.105649.1@dayvd.dayton.saic.com>
NNTP-Posting-Host: dayvd.dayton.saic.com
Xref: uunet vmsnet.sources.games:668
-+-+-+-+-+-+-+-+ START OF PART 7 -+-+-+-+-+-+-+-+
V`20purpose.
X`20*`20The`20author`20shall`20not`20be`20liable`20for`20any`20damages`20result
Ving`20from`20the
X`20*`20use`20of`20this`20software.`20`20By`20using`20this`20software,`20the
V`20user`20agrees
X`20*`20to`20these`20terms.
X`20*/
X
X#include`20"ldb.h"
X
X/*----------------------------------------------------------------------
X`20*`09newboard`20--`20set`20up`20a`20board`20array`20for`20a`20new`20game
X`20*
X`20*`20This`20function`20initializes`20a`20board`20array`20so`20that`20it`20is
V`20set`20up
X`20*`20properly`20for`20a`20new`20game.`20`20It`20is`20passed`20two`20characte
Vrs`20that`20are
X`20*`20used`20to`20draw`20the`20pieces`20for`20the`20board.`20`20C1`20is`20the
V`20color`20for`20the
X`20*`20upbound`20player,`20and`20c2`20is`20the`20color`20for`20the`20downbound
V`20player.
X`20*----------------------------------------------------------------------
X`20*/
X
Xnewboard(b,c1,c2)
Xboard`20b;
Xchar`20c1,`20c2;
X`7B
Xint`20i;
X
Xfor`20(i`20=`200;`20i`20<`20BOARDSIZE;`20i++)`20`7B
X`09b`5Bi`5D.qty`20=`200;`09`09`09/*`20init`20to`20empty`20*/
X`09b`5Bi`5D.color`20=`20'-';`09`09/*`20init`20to`20invalid`20color`20*/
X`09`7D
Xb`5B1`5D.qty`20=`202;`09`09`09`09/*`202`20c1's`20on`201`20point`20*/
Xb`5B1`5D.color`20=`20c1;
Xb`5B6`5D.qty`20=`205;`09`09`09`09/*`205`20c2's`20on`206`20point`20*/
Xb`5B6`5D.color`20=`20c2;
Xb`5B8`5D.qty`20=`203;`09`09`09`09/*`203`20c2's`20on`208`20point`20*/
Xb`5B8`5D.color`20=`20c2;
Xb`5B12`5D.qty`20=`205;`09`09`09`09/*`205`20c1's`20on`2012`20point`20*/
Xb`5B12`5D.color`20=`20c1;
Xb`5B13`5D.qty`20=`205;`09`09`09`09/*`205`20c2's`20on`2013`20point`20*/
Xb`5B13`5D.color`20=`20c2;
Xb`5B17`5D.qty`20=`203;`09`09`09`09/*`203`20c1's`20on`2017`20point`20*/
Xb`5B17`5D.color`20=`20c1;
Xb`5B19`5D.qty`20=`205;`09`09`09`09/*`205`20c1's`20on`2019`20point`20*/
Xb`5B19`5D.color`20=`20c1;
Xb`5B24`5D.qty`20=`202;`09`09`09`09/*`202`20c2's`20on`2024`20point`20*/
Xb`5B24`5D.color`20=`20c2;
X`7D
X
X
X/*----------------------------------------------------------------------
X`20*`09copyboard`20--`20make`20a`20copy`20a`20board`20array
X`20*
X`20*`20This`20is`20a`20convenience`20function`20that`20copies`20an`20entire
V`20board.`20The
X`20*`20source`20is`20given`20as`20"f",`20and`20the`20destination`20as`20"t".
X`20*----------------------------------------------------------------------
X`20*/
X
Xcopyboard(f,t)
Xboard`20f,`20t;
X`7B
Xint`20i;
X
Xfor`20(i`20=`200;`20i`20<`20BOARDSIZE;`20i++)
X`09t`5Bi`5D`20=`20f`5Bi`5D;
X`7D
$ call unpack BOARD.C;1 560470732 ""
$!
$ create 'f'
X/*`09check.c`09`0910/29/91
X`20*
X`20*`20Copyright`201991`20`20Perry`20R.`20Ross
X`20*
X`20*`20Permission`20to`20use,`20copy,`20modify,`20and`20distribute`20this`20so
Vftware`20and`20its
X`20*`20documentation`20without`20fee`20is`20hereby`20granted,`20subject`20to
V`20the`20restrictions
X`20*`20detailed`20in`20the`20README`20file,`20which`20is`20included`20here`20b
Vy`20reference.
X`20*`20Any`20other`20use`20requires`20written`20permission`20from`20the`20auth
Vor.`20`20This`20software
X`20*`20is`20distributed`20"as`20is"`20without`20any`20warranty,`20including
V`20any`20implied
X`20*`20warranties`20of`20merchantability`20or`20fitness`20for`20a`20particular
V`20purpose.
X`20*`20The`20author`20shall`20not`20be`20liable`20for`20any`20damages`20result
Ving`20from`20the
X`20*`20use`20of`20this`20software.`20`20By`20using`20this`20software,`20the
V`20user`20agrees
X`20*`20to`20these`20terms.
X`20*/
X
X#include`20"ldb.h"
X
X/*======================================================================
X`20*`20This`20file`20contains`20the`20functions`20that`20check`20for`20unused
V`20moves.
X`20*======================================================================
X`20*/
X
X
XPRIVATE`20int`20maxused,`20hiused,`20nlegal;
X
Xstruct`20legal`20*rmlegal();
X
X/*----------------------------------------------------------------------
X`20*`09legalmoves`20--`20calculate`20all`20legal`20moves`20for`20a`20game
X`20*
X`20*`20This`20function`20is`20called`20after`20the`20dice`20have`20been`20roll
Ved`20to`20search
X`20*`20all`20possible`20combinations`20of`20moves`20to`20see`20which`20ones
V`20are`20legal.
X`20*`20While`20this`20function`20is`20working,`20it`20keeps`20a`20list`20of
V`20legal`20moves,
X`20*`20but`20this`20list`20is`20deleted`20before`20returning.`20`20For`20the
V`20purposes
X`20*`20of`20checking`20a`20move,`20it`20suffices`20to`20only`20keep`20the`20nu
Vmber`20of`20usable
X`20*`20dice`20and`20the`20highest`20numbered`20usable`20dice.`20`20Any`20move
V`20that`20uses`20as
X`20*`20many`20dice`20as`20can`20be`20used,`20and`20uses`20the`20highest`20usab
Vle`20dice,`20is
X`20*`20legal.`20`20These`20values`20are`20stored`20in`20the`20maxused`20and
V`20hiused`20fields
X`20*`20of`20the`20game`20structure.
X`20*
X`20*`20legalmoves`20performs`20an`20exhaustive`20search`20of`20all`20possible
V`20move
X`20*`20combinations,`20storing`20the`20combinations`20that`20are`20not`20rejec
Vted
X`20*`20by`20apply()`20in`20an`20instance`20of`20struct`20legal,`20which`20is
V`20linked`20into
X`20*`20the`20doubly-linked`20list`20headed`20by`20lhead.`20`20Note`20that,`20a
Vt`20this`20point,
X`20*`20this`20list`20may`20contain`20many`20combinations`20that`20are`20not
V`20legal`20because
X`20*`20they`20do`20not`20use`20all`20possible`20dice,`20or`20they`20use`20a
V`20smaller`20dice`20when
X`20*`20a`20larger`20one`20is`20usable.`20`20These`20illegal`20combinations`20a
Vre`20trimmed`20from
X`20*`20the`20list`20by`20trimunused()`20and`20trimlowused().`20`20Finally,`20d
Vuplicate`20combinations
X`20*`20are`20removed`20from`20the`20list`20by`20trimequal().`20`20Duplicate
V`20moves`20are`20those`20that
X`20*`20use`20the`20same`20rolls`20to`20move`20from`20the`20same`20points,`20bu
Vt`20possibly`20in`20a
X`20*`20different`20order,`20for`20example`20(3/8`201/6)`20and`20(1/6`203/8).
V`20`20This`20allows
X`20*`20detection`20of`20the`20case`20where`20there`20is`20only`20one`20legal
V`20move,`20in`20which
X`20*`20case`20this`20move`20is`20automatically`20applied`20(if`20rc.automove
V`20is`20set).
X`20*`20If`20the`20list`20is`20empty,`20there`20are`20no`20legal`20moves.`20
V`20Otherwise,`20the
X`20*`20highest`20roll`20used`20in`20the`20list`20is`20stored`20in`20g->hiused,
V`20and`20the`20largest
X`20*`20number`20of`20rolls`20used`20in`20the`20list`20is`20stored`20in`20g->ma
Vxused.`20`20This`20information
X`20*`20is`20used`20by`20check().
X`20*----------------------------------------------------------------------
X`20*/
X
Xlegalmoves(g)
Xstruct`20game`20*g;
X`7B
Xstruct`20game`20tmp;
Xint`20i;
Xstruct`20legal`20*l;
X
Xtmp`20=`20*g;`09`09`09/*`20we`20don't`20want`20to`20change`20actual`20game`20*
V/
Xfor`20(i`20=`200;`20i`20<`204;`20tmp.mvs`5Bi++`5D.pt`20=`20-1);`09/*`20mark
V`20all`20unused`20*/
Xmaxused`20=`20-1;`09`09`09/*`20init`20to`20not`20all`20used`20*/
Xhiused`20=`200;`09`09`09/*`20init`20to`200`20*/
Xnlegal`20=`200;`09`09`09/*`20init`20to`20no`20legal`20moves*/
Xlhead`20=`20NULL;
Xltail`20=`20NULL;
Xif`20(tmp.mvs`5B0`5D.roll`20==`20tmp.mvs`5B1`5D.roll)
X`09scanmvs(`26tmp,0,3);`09/*`20there`20is`20only`20one`20ordering`20*/
Xelse`20`7B
X`09scanmvs(`26tmp,0,1);`09`09/*`20scan`20for`20one`20ordering`20*/
X`09i`20=`20tmp.mvs`5B0`5D.roll;`09/*`20reverse`20rolls`20*/
X`09tmp.mvs`5B0`5D.roll`20=`20tmp.mvs`5B1`5D.roll;
X`09tmp.mvs`5B1`5D.roll`20=`20i;
X`09for`20(i`20=`200;`20i`20<`204;`20tmp.mvs`5Bi++`5D.pt`20=`20-1);`09/*`20mark
V`20all`20unused`20*/
X`09scanmvs(`26tmp,0,1);`09`09/*`20scan`20for`20other`20ordering`20*/
X`09`7D
Xtrimunused();`09`09/*`20zap`20combinations`20that`20leave`20usable`20rolls`20u
Vnused`20*/
Xtrimlowused();`09`09/*`20zap`20combinations`20that`20use`20the`20wrong`20die
V`20*/
Xtrimequal();`09`09/*`20zap`20duplicates`20*/
Xg->maxused`20=`20maxused;`09/*`20store`20maxused`20and`20hiused`20into`20the
V`20game`20structure`20*/
Xg->hiused`20=`20hiused;
Xif`20(nlegal`20==`200)`20`7B`09/*`20check`20for`20no`20legal`20moves`20*/
X`09if`20(g->dispmsg`20!=`20NULL)
X`09`09free(g->dispmsg);
X`09g->dispmsg`20=`20save("You`20don't`20have`20any`20legal`20moves.");
X`09`7D
Xelse`20if`20(nlegal`20==`201)`20`7B`09/*`20check`20for`20only`20one`20legal
V`20move`20*/
X`09if`20(g->dispmsg`20!=`20NULL)
X`09`09free(g->dispmsg);
X`09g->dispmsg`20=`20save("You`20only`20have`20one`20legal`20move.");
X`09if`20(*rc.automove`20==`20'y')`20`7B`09/*`20you`20want`20the`20move`20appli
Ved?`20*/
X`09`09if`20(`20(lhead->nmove==0)`20`26`26`20(lhead->mvs`5B0`5D.roll!=g->mvs
V`5B0`5D.roll))
X`09`09`09g->mvs`5B1`5D`20=`20g->mvs`5B0`5D;
X`09`09for`20(i`20=`200;`20i`20<=`20lhead->nmove;`20i++)`20`7B
X`09`09`09g->mvs`5Bi`5D`20=`20lhead->mvs`5Bi`5D;
X`09`09`09apply(g,WHO_ME,i,0,NULL);
X`09`09`09`7D
X`09`09`7D
X`09`7D
X
X`09/*`20we`20have`20no`20use`20for`20the`20legal`20moves`20list,`20so`20free
V`20it`20*/
X`09/*`20maybe`20in`20the`20future`20we`20will`20have`20a`20use`20for`20it`20*/
V
X
Xfor`20(l`20=`20lhead;`20l`20!=`20NULL;`20l`20=`20l->next)
X`09free(l);
Xlhead`20=`20NULL;
Xltail`20=`20NULL;
X`7D
X
X
X/*----------------------------------------------------------------------
X`20*`09scanmvs`20--`20search`20for`20all`20possible`20combinations`20of`20a
V`20move
X`20*
X`20*`20This`20function`20takes`20a`20single`20die`20and`20tries`20to`20use`20i
Vt`20on`20every`20point
X`20*`20of`20the`20board.`20`20For`20every`20point`20it`20is`20successful,`20it
V`20adds`20the
X`20*`20combination`20to`20the`20legal`20moves`20list`20and`20performs`20a`20re
Vcursive`20descent
X`20*`20searching`20for`20all`20legal`20combinations`20of`20the`20remaining`20d
Vice.
X`20*----------------------------------------------------------------------
X`20*/
Xscanmvs(g,mn,max)
Xstruct`20game`20*g;
Xint`20mn,`20max;
X`7B
Xint`20i;
Xboard`20sv;
X
Xcopyboard(g->board,sv);`09`09/*`20save`20the`20board`20*/
Xfor`20(i`20=`200;`20i`20<=`2024;`20i++)`20`7B
X`09if`20(i`20==`200)
X`09`09g->mvs`5Bmn`5D.pt`20=`20BARPT(g->mydir);`09/*`20use`20correct`20barpt
V`20*/
X`09else
X`09`09g->mvs`5Bmn`5D.pt`20=`20i;
X`09if`20(apply(g,WHO_ME,mn,0,NULL)`20<`200)`09/*`20can't`20move`20from`20this
V`20pt`20*/
X`09`09continue;
X`09addlegal(mn,g->mvs`5Bmn`5D.roll,g->mvs`5Bmn`5D.pt);`09/*`20add`20to`20list
V`20*/
X`09if`20(mn`20<`20max)
X`09`09scanmvs(g,mn+1,max);`09`09/*`20try`20all`20remaining`20comb's`20*/
X`09copyboard(sv,g->board);`09`09`09/*`20restore`20board`20*/
X`09`7D
X`7D
X
X
X/*----------------------------------------------------------------------
X`20*`09addlegal`20--`20add`20a`20move`20combination`20to`20the`20list
X`20*
X`20*`20This`20function`20adds`20an`20instance`20of`20struct`20legal`20to`20the
V`20legal`20moves`20list.
X`20*`20The`20arguments`20to`20addlegal`20only`20specify`20the`20usage`20of`20o
Vne`20particular
X`20*`20die,`20by`20specifying`20its`20"move`20number".`20`20For`20example,`20f
Vor`20a`20roll`20of
X`20*`205`202,`20the`205`20is`20move`20number`200`20and`20the`202`20is`20move
V`20number`201.`20`20The`20usage
X`20*`20of`20all`20lower`20numbered`20rolls`20is`20copied`20from`20the`20previo
Vus`20entry`20in`20the
X`20*`20moves`20list`20(since`20that`20entry`20was`20added`20by`20the`20higher
V`20level`20scanmvs
X`20*`20before`20the`20current`20scanmvs`20was`20called),`20and`20all`20higher-
Vnumbered`20rolls
X`20*`20are`20marked`20unused.
X`20*----------------------------------------------------------------------
X`20*/
X
Xaddlegal(mn,r,pt)
Xint`20mn,`20r,`20pt;
X`7B
Xint`20i;
Xstruct`20legal`20*n;
X
Xif`20(`20(n`20=`20(struct`20legal`20*)`20calloc(sizeof(struct`20legal),1))`20=
V=`20NULL)
X`09fatal("Out`20of`20memory!");
Xclearmvs(n->mvs);
Xif`20(ltail`20!=`20NULL)
X`09for`20(i`20=`200;`20i`20<`20mn;`20i++)`09`09/*`20copy`20prefix`20from`20pre
Vv`20move`20*/
X`09`09n->mvs`5Bi`5D`20=`20ltail->mvs`5Bi`5D;
Xn->mvs`5Bmn`5D.roll`20=`20r;`09`09/*`20copy`20in`20this`20move`20*/
Xn->mvs`5Bmn`5D.pt`20=`20pt;
Xn->next`20=`20NULL;`09`09`09/*`20this`20is`20end`20of`20list`20*/
Xif`20(lhead`20==`20NULL)`20`7B`09`09/*`20link`20into`20list`20*/
X`09n->prev`20=`20NULL;
X`09lhead`20=`20n;
X`09ltail`20=`20n;
X`09`7D
Xelse`20`7B
X`09n->prev`20=`20ltail;
X`09ltail->next`20=`20n;
X`09ltail`20=`20n;
X`09`7D
Xn->himove`20=`200;
Xfor`20(i`20=`200;`20i`20<=`20mn;`20i++)`09/*`20search`20for`20highest`20used
V`20move`20*/
X`09if`20(n->mvs`5Bi`5D.roll`20>`20n->himove)
X`09`09n->himove`20=`20n->mvs`5Bi`5D.roll;
Xif`20(mn`20>`20maxused)`09`09/*`20keep`20track`20of`20whether`20it`20is`20poss
Vible`20*/
X`09maxused`20=`20mn;`09/*`20to`20use`20all`20of`20the`20rolls`20*/
Xnlegal++;
Xn->nmove`20=`20mn;`09`09/*`20store`20number`20of`20moves`20used`20by`20this
V`20entry`20*/
X`7D
X
X
X/*----------------------------------------------------------------------
X`20*`09trimunused`20--`20remove`20moves`20that`20do`20not`20use`20all`20possib
Vle`20rolls
X`20*
X`20*`20This`20function`20scans`20the`20move`20list`20and`20deletes`20combinati
Vons`20that
X`20*`20leave`20usable`20rolls`20unused.
X`20*----------------------------------------------------------------------
X`20*/
X
Xtrimunused()
X`7B
Xstruct`20legal`20*l;
X
Xl`20=`20lhead;
Xwhile`20(l`20!=`20NULL)`20`7B
X`09if`20(l->nmove`20<`20maxused)
X`09`09l`20=`20rmlegal(l);
X`09else
X`09`09l`20=`20l->next;
X`09`7D
X`7D
X
X
X/*----------------------------------------------------------------------
X`20*`09trimlowused`20--`20remove`20moves`20that`20do`20not`20use`20the`20large
Vst`20possible`20roll
X`20*
X`20*`20This`20function`20scans`20the`20move`20list`20and`20deletes`20combinati
Vons`20that
X`20*`20do`20not`20use`20the`20highest`20usable`20roll.
X`20*----------------------------------------------------------------------
X`20*/
X
Xtrimlowused()
X`7B
Xstruct`20legal`20*l;
X
Xl`20=`20lhead;
Xwhile`20(l`20!=`20NULL)`20`7B
X`09if`20(l->himove`20<`20hiused)
X`09`09l`20=`20rmlegal(l);
X`09else
X`09`09l`20=`20l->next;
X`09`7D
X`7D
X
X
X/*----------------------------------------------------------------------
X`20*`09trimequal`20--`20remove`20duplicate`20moves
X`20*
X`20*`20This`20function`20scans`20the`20move`20list`20and`20deletes`20combinati
Vons`20that
X`20*`20are`20duplicates.
X`20*----------------------------------------------------------------------
X`20*/
X
Xtrimequal()
X`7B
Xstruct`20legal`20*l,`20*p;
Xstruct`20mv`20m1`5B4`5D,`20m2`5B4`5D;
Xint`20i,`20n;
X
Xfor`20(l`20=`20lhead;`20l`20!=`20NULL;`20l`20=`20l->next)`20`7B
X`09extractmvs(l,m1);
X`09n`20=`20l->nmove;
X`09p`20=`20l->next;
X`09while`20(p`20!=`20NULL)`20`7B
X`09`09if`20(p->nmove`20!=`20n)`20`7B
X`09`09`09p`20=`20p->next;
X`09`09`09continue;
X`09`09`09`7D
X`09`09extractmvs(p,m2);
X`09`09for`20(i`20=`200;`20i`20<=`20n;`20i++)
X`09`09`09if`20((m1`5Bi`5D.roll`20!=`20m2`5Bi`5D.roll)`7C`7C(m1`5Bi`5D.pt`20!=
V`20m2`5Bi`5D.pt))
X`09`09`09`09break;
X`09`09if`20(i`20<=`20n)
X`09`09`09p`20=`20p->next;
X`09`09else
X`09`09`09p`20=`20rmlegal(p);
X`09`09`7D
X`09`7D
X`7D
X
X
X/*----------------------------------------------------------------------
X`20*`09rmlegal`20--`20remove`20a`20struct`20legal`20from`20the`20move`20list
X`20*
X`20*`20This`20function`20unlinks`20an`20entry`20from`20the`20move`20list`20and
V`20free's`20it.
X`20*----------------------------------------------------------------------
X`20*/
X
Xstruct`20legal`20*rmlegal(l)
Xstruct`20legal`20*l;
X`7B
Xstruct`20legal`20*t;
X
Xt`20=`20l;
Xif`20(l`20==`20lhead)`20`7B
X`09lhead`20=`20l->next;
X`09l`20=`20lhead;
X`09`7D
Xelse`20`7B
X`09if`20(`20(l->prev->next`20=`20l->next)`20!=`20NULL)
X`09`09l->next->prev`20=`20l->prev;
X`09l`20=`20l->next;
X`09`7D
Xfree(t);
Xnlegal--;
Xreturn(l);
X`7D
X
X
X/*----------------------------------------------------------------------
X`20*`09extractmvs`20--`20extract`20a`20struct`20legal`20into`20a`20struct`20mv
V
X`20*
X`20*`20This`20function`20copies`20the`20information`20from`20a`20move`20list
V`20entry`20into
X`20*`20an`20instance`20of`20struct`20mv,`20and`20then`20sorts`20the`20rolls
V`20in`20the`20struct`20mv
X`20*`20by`20increasing`20dice`20value`20(and`20by`20increasing`20point`20numbe
Vr`20for`20equal
X`20*`20rolls).`20`20Sorting`20the`20rolls`20makes`20it`20easier`20for`20trimeq
Vual`20to`20check
X`20*`20for`20duplicate`20entries,`20it`20has`20no`20value`20as`20far`20as`20th
Ve`20game`20is`20concerned.
X`20*----------------------------------------------------------------------
X`20*/
X
Xextractmvs(l,m)
Xstruct`20legal`20*l;
Xstruct`20mv`20*m;
X`7B
Xint`20i,`20n,`20s;
Xstruct`20mv`20tmp;
X
Xclearmvs(m);
Xfor`20(i`20=`200;`20i`20<=`20l->nmove;`20i++)`09`09/*`20extract`20the`20moves
V`20*/
X`09m`5Bi`5D`20=`20l->mvs`5Bi`5D;
Xn`20=`20l->nmove;
Xdo`20`7B`09`09`09/*`20sort`20by`20increasing`20roll`20then`20increasing`20poin
Vt`20*/
X`09s`20=`200;
X`09for`20(i`20=`200;`20i`20<`20n;`20i++)`20`7B`09`09/*`20long`20live`20bubbles
Vort`20*/
X`09`09if`20(m`5Bi`5D.roll`20<`20m`5Bi+1`5D.roll)
X`09`09`09continue;
X`09`09else`20if`20(`20(m`5Bi`5D.roll`20==`20m`5Bi+1`5D.roll)`20`26`26`20(m`5Bi
V`5D.pt`20<`20m`5Bi+1`5D.pt)`20)
X`09`09`09continue;
X`09`09tmp`20=`20m`5Bi`5D;
X`09`09m`5Bi`5D`20=`20m`5Bi+1`5D;
X`09`09m`5Bi+1`5D`20=`20tmp;
X`09`09s`20=`201;
X`09`09`7D
X`09n--;
X`09`7D`20while`20(s);
X`7D
X
X
X/*----------------------------------------------------------------------
X`20*`09checkused`20--`20check`20that`20a`20move`20uses`20the`20correct`20rolls
V
X`20*
X`20*`20This`20function`20is`20called`20just`20before`20a`20move`20is`20sent
V`20to`20the
X`20*`20opponent.`20`20It`20uses`20the`20values`20stored`20in`20g->maxused`20an
Vd`20g->hiused
X`20*`20to`20make`20sure`20that`20the`20move`20uses`20all`20usable`20rolls,`20a
Vnd`20that`20it
X`20*`20uses`20the`20highest`20usable`20roll.`20`20As`20a`20special`20case,`20i
Vt`20considers
X`20*`20to`20be`20legal`20any`20move`20where`20all`20pieces`20are`20borne`20off
V.`20`20This
X`20*`20takes`20care`20of`20the`20special`20case`20where`20there`20is`20one`20p
Viece
X`20*`20left`20to`20bear`20off,`20and`20two`20rolls,`20one`20of`20which`20is
V`20too`20small
X`20*`20to`20bear`20off.`20`20Normally,`20ldb`20would`20insist`20that`20the`20s
Vmaller
X`20*`20roll`20be`20used,`20then`20the`20larger`20one,`20so`20that`20both`20rol
Vls
X`20*`20would`20be`20used.`20`20If`20one`20roll`20is`20large`20enough`20to`20be
Var`20the`20last
X`20*`20man`20off,`20though,`20there`20is`20no`20need`20to`20force`20the`20othe
Vr`20roll`20to`20be`20used.
X`20*----------------------------------------------------------------------
X`20*/
X
Xcheckused(g)
Xstruct`20game`20*g;
X`7B
Xint`20h,`20i;
X
Xif`20(g->board`5BOFFPT(g->mydir)`5D.qty`20==`2015)`09/*`20special`20case,`20if
V`20all`20pcs`20*/
X`09return(0);`09`09/*`20are`20off,`20then`20all`20rolls`20have`20been`20used
V`20*/
Xh`20=`200;
Xfor`20(i`20=`200;`20i`20<=`20g->maxused;`20i++)`20`7B
X`09if`20(g->mvs`5Bi`5D.pt`20<`200)`20`7B
X`09`09FeMessage("You`20left`20a`20roll`20unused.");
X`09`09return(1);
X`09`09`7D
X`09if`20(h`20<`20g->mvs`5Bi`5D.roll)
X`09`09h`20=`20g->mvs`5Bi`5D.roll;
X`09`7D
Xif`20(g->hiused`20>`20h)`20`7B
X`09FeMessage("You`20can`20use`20the`20higher`20roll.");
X`09return(1);
X`09`7D
Xreturn(0);
X`7D
$ call unpack CHECK.C;1 421838177 ""
$!
$ create 'f'
X/*`09control.c`09`099/12/91
X`20*
X`20*`20Copyright`201991`20`20Perry`20R.`20Ross
X`20*
X`20*`20Permission`20to`20use,`20copy,`20modify,`20and`20distribute`20this`20so
Vftware`20and`20its
X`20*`20documentation`20without`20fee`20is`20hereby`20granted,`20subject`20to
V`20the`20restrictions
X`20*`20detailed`20in`20the`20README`20file,`20which`20is`20included`20here`20b
Vy`20reference.
X`20*`20Any`20other`20use`20requires`20written`20permission`20from`20the`20auth
Vor.`20`20This`20software
X`20*`20is`20distributed`20"as`20is"`20without`20any`20warranty,`20including
V`20any`20implied
X`20*`20warranties`20of`20merchantability`20or`20fitness`20for`20a`20particular
V`20purpose.
X`20*`20The`20author`20shall`20not`20be`20liable`20for`20any`20damages`20result
Ving`20from`20the
X`20*`20use`20of`20this`20software.`20`20By`20using`20this`20software,`20the
V`20user`20agrees
X`20*`20to`20these`20terms.
X`20*/
X
X#include`20"ldb.h"
X
X/*----------------------------------------------------------------------
X`20*`09control`20--`20control`20a`20game
X`20*
X`20*`20This`20function`20is`20called`20to`20process`20the`20-control`20command
V`20line`20option.
X`20*`20It`20currently`20allows`20the`20following:
X`20*`20`20`20`20-`09The`20board`20may`20be`20inverted.`20`20The`20points`20are
V`20still`20numbered`20the
X`20*`09same,`20the`20board`20is`20merely`20drawn`20upside`20down.`20`20This
V`20can`20help`20users
X`20*`09who`20are`20playing`20a`20number`20of`20games`20simultaneously`20by`20a
Vllowing`20him
X`20*`09to`20make`20all`20of`20his`20games`20move`20in`20the`20same`20direction
V`20on`20the`20screen.
X`20*`20`20`20`20-`20The`20last`20packet`20sent`20may`20be`20resent.`20`20This
V`20is`20useful`20when`20moves
X`20*`09are`20lost`20in`20the`20mail,`20or`20if`20players`20forget`20whose`20tu
Vrn`20it`20is.
X`20*`09Ldb`20rejects`20packets`20that`20have`20already`20been`20received,`20so
V`20both
X`20*`09players`20may`20simply`20resend`20their`20last`20packet,`20and`20ldb
V`20will`20display
X`20*`09the`20board`20to`20the`20player`20who`20is`20supposed`20to`20move.
X`20*----------------------------------------------------------------------
X`20*/
X
Xcontrol()
X`7B
Xregister`20struct`20game`20*g;
Xstatic`20char`20*m`5B`5D`20=`20`7B"Invert","Resend","Get`20Resend","Screen`20D
Vump","Delete`20Game",
X`09`09`09"Next`20Game","Quit",NULL`7D;
Xchar`20buf`5B60`5D,`20c,`20done;
Xint`20mod;
Xchar`20pm`20=`20'`5C0';
Xstatic`20char`20oldmsg`5B`5D`20=`20"Your`20opponent's`20ldb`20does`20not`20sup
Vport`20resend`20requests.";
Xstatic`20char`20gmover`5B`5D`20=`20"This`20game`20is`20over`20--`20you`20canno
Vt`20request`20a`20resend.";
X
Xif`20(ghead`20==`20NULL)`20`7B
X`09printf("You`20don't`20have`20any`20games`20in`20progress.`5Cn");
X`09printf("Use`20the`20-start`20option`20to`20start`20one.`5Cn");
X`09usage(0);
X`09ldbexit(STAT_ABORT);
X`09`7D
Xmod`20=`200;`09`09`09`09/*`20init`20to`20no`20mods`20*/
Xrc.chkpt`20=`20"no";`09`09`09/*`20disable`20checkpoint`20in`20sendpkt`20*/
XFeInitialize();`09`09`09`09/*`20initialize`20front`20end`20*/
XFeDrawScreen();`09`09`09`09/*`20draw`20board`20outline`20*/
Xdone`20=`200;
Xfor`20(g`20=`20ghead;`20(done`20<`202)`20`26`26`20(g`20!=`20NULL);`20g`20=`20g
V->next)`20`7B/*`20for`20all`20games`20*/
X`09g->curbd`20=`20BD_CUR;`09`09/*`20make`20sure`20we`20draw`20the`20current
V`20bd`20*/
X`09FeDrawGame(g);
X`09FeDrawMenu(m);
X`09sprintf(buf,"Current`20state:`20%s",states`5Bg->state`5D);
X`09FeMessage(buf);
X`09done`20=`200;
X`09GameState`20=`20STATE_CONTROL;
X`09while`20(!`20done)`20`7B
X`09`09c`20=`20FeMenu(m,0,0,"`20`5Cn`5Cr",pm);
X`09`09pm`20=`20c;
X`09`09switch`20(c)`20`7B
X`09`09case`20'I':`09`09`09/*`20invert`20board`20*/
X`09`09`09g->flags`20`5E=`20F_INVERT;`09/*`20toggle`20invert`20bit`20*/
X`09`09`09FeDrawGame(g);`09`09/*`20redraw`20the`20screen`20*/
X`09`09`09mod++;`09`09`09/*`20games`20have`20been`20modified`20*/
X`09`09`09break;
X`09`09case`20'R':`09`09`09/*`20resend`20last`20packet`20*/
X`09`09`09if`20((g->state>=OPSTATES)`26`26(g->state!=ST_GAMEOVER))`20`7B
X`09`09`09`09FeMessage("Can't`20resend`20--`20it`20is`20your`20move.");
X`09`09`09`09break;
X`09`09`09`09`7D
X`09`09`09resendpkt(g);
X`09`09`09FeMessage("Last`20packet`20re-sent.");
X`09`09`09break;
X`09`09case`20'G':
X`09`09`09if`20(g->state`20==`20ST_GAMEOVER)`20`7B
X`09`09`09`09FeMessage(gmover);
X`09`09`09`09break;
X`09`09`09`09`7D
X`09`09`09if`20(g->opver`20<`20110)`20`7B
X`09`09`09`09FeMessage(oldmsg);
X`09`09`09`09break;
X`09`09`09`09`7D
X`09`09`09sendpkt(g,RESEND);
X`09`09`09FeMessage("Resend`20requested.");
X`09`09`09break;
X`09`09case`20'S':`09`09`09/*`20dump`20screen`20*/
X`09`09`09FeMessage(buf);`09`09/*`20restore`20state`20msg`20*/
X`09`09`09FeDumpScreen("ldb_screen.dmp");`09/*`20do`20the`20dump`20*/
X`09`09`09FeMessage("Screen`20dumped`20to`20ldb_screen.dmp");
X`09`09`09break;
X`09`09case`20'D':`09`09`09/*`20delete`20game`20*/
X`09`09`09mod++;`09`09`09/*`20games`20have`20been`20modified`20*/
X`09`09`09if`20(g->flags`20`26`20F_DELETE)`20`7B`09/*`20undelete`20*/
X`09`09`09`09g->flags`20`26=`20`7EF_DELETE;
X`09`09`09`09FeMessage("Game`20undeleted.");
X`09`09`09`09`7D
X`09`09`09else`20`7B
X`09`09`09`09g->flags`20`7C=`20F_DELETE;`09/*`20delete`20*/
X`09`09`09`09FeMessage(
X`09`09`09`09`20"Game`20deleted`20--`20press`20D`20again`20to`20undelete.");
X`09`09`09`09`7D
X`09`09`09break;
X`09`09case`20'Q':`09`09`09/*`20exit`20ldb`20*/
X`09`09`09done`20=`202;`09`09/*`202`20means`20Really`20done`20*/
X`09`09`09break;
X`09`09case`20'`20':
X`09`09case`20'`5Cn':
X`09`09case`20'`5Cr':
X`09`09`09FeOnMenuItem(m,'N');`09/*`20highlight`20Next`20Game`20item`20*/
X`09`09`09pm`20=`20'N';`09`09/*`20remember`20to`20unhighlight`20*/
X`09`09`09/*`20Fall`20through`20*/
X`09`09case`20'N':
X`09`09`09done`20=`201;`09/*`201`20means`20just`20done`20with`20this`20game`20*
V/
X`09`09`09break;`09`09/*`20go`20to`20next`20game`20*/
X`09`09`09`7D
X`09`09`7D
X`09`7D
XFeFinishSession();
Xwhile`20(mod)`20`7B
X`09printf("Save`20changes?`20`5Byn`5D:`20");
X`09fflush(stdout);
X`09if`20(`20(`20(c`20=`20getchar())`20==`20'y')`20`7C`7C`20(c`20==`20'Y')`20)
V`20`7B
X`09`09writegames(rc.gfile,rc.gbackup,rc.pfile);
X`09`09break;
X`09`09`7D
X`09if`20(`20(c`20==`20'n')`20`7C`7C`20(c`20==`20'N')`20)`20`7B
X`09`09printf("Changes`20discarded.`5Cn");
X`09`09break;
X`09`09`7D
X`09if`20(`20(c`20!=`20'`5Cn')`20`26`26`20(c`20!=`20EOF)`20)
X`09`09while`20(`20(`20(c`20=`20getchar())`20!=`20'`5Cn')`20`26`26`20(c`20!=
V`20EOF)`20);
X`09printf("Please`20respond`20with`20y`20or`20n.`5Cn");
X`09`7D
X`7D
X
X
X/*----------------------------------------------------------------------
X`20*`09recons`20--`20reconstruct`20games`20from`20opponent's`20.ldbdata
X`20*
X`20*`20This`20function`20allows`20a`20game`20to`20be`20reconstructed`20when
V`20the`20.ldbdata
X`20*`20file`20has`20been`20irretrievably`20lost.`20`20The`20opponent`20merely
V`20mails
X`20*`20his`20.ldbdata`20file,`20and`20we`20scan`20it`20for`20all`20the`20impor
Vtant`20information.
X`20*`20Games`20that`20are`20in`20the`20OPSTART`20or`20GAMEOVER`20states`20cann
Vot`20be`20reconstructed
X`20*`20due`20to`20the`20lack`20of`20adequate`20information,`20but`20these`20ga
Vmes`20either`20have
X`20*`20not`20started`20or`20are`20already`20over.`20`20If`20the`20game`20is
V`20in`20state`20OPSTART
X`20*`20because`20the`20next`20game`20of`20a`20match`20is`20being`20started,
V`20the`20match`20can
X`20*`20be`20rescued`20by`20starting`20a`20new`20match`20that`20plays`20up`20to
V`20the`20number`20of
X`20*`20points`20remaining`20in`20the`20old`20match.
X`20*
X`20*`20Before`20sending`20the`20.ldbdata`20file,`20your`20opponent`20should
V`20incorporate
X`20*`20any`20moves`20you`20sent`20before`20you`20lost`20your`20file.`20`20If
V`20your`20move`20is`20lost
X`20*`20as`20well,`20it`20may`20be`20necessary`20for`20you`20to`20replay`20your
V`20last`20move,`20with
X`20*`20a`20new`20roll.`20`20This`20should`20not`20be`20considered`20cheating,
V`20as`20it`20is`20unavoidable.
X`20*`20Alternatively,`20if`20you`20remember`20your`20last`20roll,`20you`20coul
Vd`20plug`20the`20rolls
X`20*`20into`20your`20.ldbdata`20after`20the`20reconstruct.
X`20*
X`20*`20You`20will`20have`20to`20edit`20the`20mail`20header`20off`20the`20file
V`20before`20feeding`20it
X`20*`20to`20-reconstruct.`20`20The`20first`20line`20of`20the`20file`20MUST`20b
Ve`20the`20first`20line
X`20*`20of`20the`20data`20file.
X`20*
X`20*`20Because`20data`20fields`20are`20frequently`20added`20to`20data`20files
V`20between
X`20*`20revisions,`20-reconstruct`20is`20only`20guaranteed`20to`20work`20when
V`20you
X`20*`20are`20using`20the`20same`20ldb`20revision`20as`20your`20opponent.
X`20*
X`20*`20If`20you`20started`20the`20game`20being`20reconstructed,`20and`20you
V`20used`20the
X`20*`20-myaddr`20argument`20when`20you`20started`20it,`20you`20will`20need`20t
Vo`20use
X`20*`20the`20-myaddr`20argument`20when`20you`20reconstruct`20it.
X`20*----------------------------------------------------------------------
X`20*/
X
Xrecons(file)
Xchar`20*file;
X`7B
XFILE`20*fp;
Xchar`20c;
Xint`20i,`20j;
Xstruct`20mv`20m;
Xstruct`20game`20*g;
Xstruct`20people`20*p;
Xchar`20*s;
Xchar`20buf`5B80`5D;
X
Xif`20(`20(fp`20=`20fopen(file,"r"))`20==`20NULL)`20`7B
X`09fprintf(stderr,"ERROR:`20cannot`20open`20%s`20for`20reconstruct`5Cn",file);
V
X`09ldbexit(STAT_ABORT);
X`09`7D
Xg`20=`20addgame();`09`09`09/*`20get`20a`20game`20structure`20*/
Xwhile`20(`20(c`20=`20getc(fp))`20!=`20EOF)`20`7B
X`09ungetc(c,fp);`09`09`09/*`20put`20char`20back`20*/
X`09nvscan(fp,nv_gfile,g);
X`09if`20(strcmp(g->opaddr,rc.myaddr))`09/*`20this`20game`20wasn't`20with`20me
V`20*/
X`09`09continue;
X`09if`20(`20(g->state`20==`20ST_OPSTART)`20`7C`7C`20(g->state`20==`20ST_GAMEOV
VER)`20)
X`09`09continue;`09`09/*`20can't`20handle`20these`20*/
X`09printf("`5Cn---`20Reconstruct`20found`20game`20%s`20---`5Cn",g->gameid);
X`09s`20=`20g->gameid;`09`09`09/*`20copy`20out`20gameid`20*/
X`09g->gameid`20=`20"";`09`09`09/*`20temporarily`20delete`20gameid`20field`20*/
V
X`09if`20(findgame(s)`20!=`20NULL)`20`7B
X`09`09printf("ERROR:`20This`20game`20already`20exists`20--`20ignoring.`5Cn");
X`09`09continue;
X`09`09`7D
X`09g->gameid`20=`20s;`09`09`09/*`20restore`20gameid`20field`20*/
X`09printf("Enter`20opponent`20address`20or`20alias:`20");
X`09if`20(fgets(buf,sizeof(buf),stdin)`20==`20NULL)`20`7B
X`09`09printf("`5Cn---`20Reconstruct`20deleting`20game`20%s`20---`5Cn",g->gamei
Vd);
X`09`09continue;
X`09`09`7D
X`09buf`5Bstrlen(buf)-1`5D`20=`20'`5C0';`09`09/*`20clobber`20newline`20*/
X`09if`20(`20(p`20=`20findppl(buf,P_ADDR`7CP_ALIAS))`20==`20NULL)`20`7B/*`20not
V`20in`20ppl`20file`20*/
X`09`09g->opaddr`20=`20save(buf);`09`09/*`20save`20address`20in`20game`20*/
X`09`09printf("Enter`20opponent`20name:`20");
X`09`09if`20(fgets(buf,sizeof(buf),stdin)`20==`20NULL)`20`7B
X`09`09`09printf("`5Cn---`20Reconstruct`20deleting`20game`20%s`20---`5Cn",
X`09`09`09`09g->gameid);
X`09`09`09continue;
X`09`09`09`7D
X`09`09buf`5Bstrlen(buf)-1`5D`20=`20'`5C0';`09/*`20clobber`20newline`20*/
X`09`09g->opname`20=`20save(buf);`09`09/*`20save`20opponent's`20name`20*/
X`09`09newppl(g);`09`09/*`20generate`20a`20new`20people`20rec`20*/
X`09`09`7D
X`09else`20`7B`09`09`09`09/*`20it`20was`20an`20alias`20*/
X`09`09g->opname`20=`20save(p->name);`09/*`20copy`20name`20from`20people`20rec
V`20*/
X`09`09g->opaddr`20=`20save(p->addr);`09/*`20address`20too`20*/
X`09`09g->ppl`20=`20p;`09`09`09/*`20store`20people`20pointer`20*/
X`09`09`7D
X`09g->dispmsg`20=`20NULL;
X`09g->myaddr`20=`20save(rc.myaddr);
X`09for`20(i`20=`200;`20i`20<`204;`20i++)`20`7B
X`09`09g->blot`5Bi`5D`20=`200;`09`09/*`20clear`20blot`20array`20*/
X`09`09m`20=`20g->mvs`5Bi`5D;`09`09/*`20switch`20mvs`20and`20opmvs`20fields`20*
V/
X`09`09g->mvs`5Bi`5D`20=`20g->opmvs`5Bi`5D;
X`09`09g->opmvs`5Bi`5D`20=`20m;
X`09`09`7D
X`09for`20(i`20=`200;`20i`20<`206;`20i++)`20`7B
X`09`09j`20=`20g->rolls`5Bi`5D;`09/*`20switch`20rolls`20and`20oprolls`20*/
X`09`09g->rolls`5Bi`5D`20=`20g->oprolls`5Bi`5D;
X`09`09g->oprolls`5Bi`5D`20=`20j;
X`09`09j`20=`20g->doubles`5Bi`5D;`09/*`20switch`20doubles`20and`20opdoubles`20*
V/
X`09`09g->doubles`5Bi`5D`20=`20g->opdoubles`5Bi`5D;
X`09`09g->opdoubles`5Bi`5D`20=`20j;
X`09`09`7D
X`09i`20=`20g->mydir;`09`09`09/*`20switch`20mydir`20and`20opdir`20*/
X`09g->mydir`20=`20g->opdir;
X`09g->opdir`20=`20i;
X`09i`20=`20g->mycolor;`09`09`09/*`20switch`20mycolor`20and`20opcolor`20*/
X`09g->mycolor`20=`20g->opcolor;
X`09g->opcolor`20=`20i;
X`09s`20=`20g->mycmt;
X`09g->mycmt`20=`20g->opcmt;
X`09g->opcmt`20=`20s;
X`09s`20=`20g->mycmt2;
X`09g->mycmt2`20=`20g->opcmt2;
X`09g->opcmt2`20=`20s;
X`09i`20=`20g->mcurrent`5BWHO_ME`5D;`09`09/*`20switch`20match`20scores`20*/
X`09g->mcurrent`5BWHO_ME`5D`20=`20g->mcurrent`5BWHO_OPP`5D;
X`09g->mcurrent`5BWHO_OPP`5D`20=`20i;
X`09copyboard(g->mybd,g->opbd);`09/*`20my`20before`20bd`20==`20op's`20after`20b
Vd`20*/
X`09if`20(g->state`20<`20OPSTATES)`20`7B`09/*`20I'm`20sending`20next`20*/
X`09`09g->seq++;`09/*`20set`20seq#`20to`20what`20opp`20expects`20in`20next`20pk
Vt`20*/
X`09`09copyboard(g->board,g->mybd);`09/*`20my`20after`20bd`20==`20cur`20board
V`20*/
X`09`09`7D
X`09else`20`7B`09`09`09`09/*`20he's`20sending`20next`20*/
X`09`09g->seq--;`09/*`20set`20seq#`20to`20what`20we're`20expecting`20*/
X`09`09copyboard(g->mybd,g->board);`09/*`20erase`20his`20moves`20*/
X`09`09`7D
X`09g->lastop`20=`20START;`09`09/*`20has`20to`20be`20set`20to`20something`20*/
X`09switch`20(g->state)`20`7B`09`09/*`20invert`20state`20*/
X`09case`20ST_OPTURN:
X`09`09g->state`20=`20ST_MYTURN;`09/*`20it's`20my`20turn`20*/
X`09`09break;
X`09case`20ST_OPACCEPT:
X`09`09g->state`20=`20ST_MYACCEPT;`09/*`20waiting`20for`20me`20to`20accept`20do
Vuble`20*/
X`09`09break;
X`09case`20ST_MYTURN:
X`09case`20ST_MYMOVE:
X`09`09g->state`20=`20ST_OPTURN;`09/*`20waiting`20for`20op`20to`20move`20*/
X`09`09break;
X`09case`20ST_MYACCEPT:
X`09`09g->state`20=`20ST_OPACCEPT;`09/*`20waiting`20for`20op`20to`20accept`20do
Vuble`20*/
X`09`09break;
X`09`09`7D
X`09printf("---`20Reconstructed`20game`20%s`20---`5Cn",g->gameid);
X`09g`20=`20addgame();`09`09/*`20get`20new`20buffer`20to`20read`20into`20*/
X`09`7D
Xdeletegame(g);`09`09`09/*`20get`20rid`20of`20buffer`20*/
Xwritegames(rc.gfile,rc.gbackup,rc.pfile);`09/*`20save`20new`20games`20*/
X`7D
$ call unpack CONTROL.C;1 155352402 ""
$!
$ create 'f'
X/*`20dohelp.c`09`093/27/92
X`20*
X`20*`20Copyright`201992`20`20Earle`20F.`20Ake
X`20*
X`20*`20Permission`20to`20use,`20copy,`20modify,`20and`20distribute`20this`20so
Vftware`20and`20its
X`20*`20documentation`20without`20fee`20is`20hereby`20granted,`20subject`20to
V`20the`20restrictions
X`20*`20detailed`20in`20the`20README`20file,`20which`20is`20included`20here`20b
Vy`20reference.
X`20*`20Any`20other`20use`20requires`20written`20permission`20from`20the`20auth
Vor.`20`20This`20software
X`20*`20is`20distributed`20"as`20is"`20without`20any`20warranty,`20including
V`20any`20implied
X`20*`20warranties`20of`20merchantability`20or`20fitness`20for`20a`20particular
V`20purpose.
X`20*`20The`20author`20shall`20not`20be`20liable`20for`20any`20damages`20result
Ving`20from`20the
X`20*`20use`20of`20this`20software.`20`20By`20using`20this`20software,`20the
V`20user`20agrees
X`20*`20to`20these`20terms.
X`20*
X`20*`20Original`20coding`20by`20Earle`20F.`20Ake`20<ake@dayton.saic.com>`20-
V`2027`20March`201992.
X`20*
X`20*/
X
X#include`20"ldb.h"
X
X/*----------------------------------------------------------------------
X`20*`09dohelp`20--`20display`20online`20help`20for`20the`20user
X`20*
X`20*`20This`20function`20creates`20a`20new`20curses`20window`20and`20displays
V`20command`20help
X`20*`20to`20the`20user.`20`20The`20user`20then`20presses`20any`20key`20to`20re
Vturn`20to`20the`20game.
X`20*----------------------------------------------------------------------
X`20*/
X
Xdohelp()
X`7B
XWINDOW`20*helpwin;
Xint`20row;
X
Xhelpwin`20=`20newwin(0,0,0,0);`09/*`20get`20a`20new`20window`20to`20post`20hel
Vp`20to`20*/
X
Xmvwaddstr(helpwin,0,30,"ldb`20Command`20Summary");`09`09/*`20print`20title`20*
V/
Xmvwaddstr(helpwin,1,30,"-------------------");`09`09/*`20underline`20title`20*
V/
Xrow`20=`203;
X
Xif(GameState`20==`20STATE_MYACPT)`20`7B
X`09mvwaddstr(helpwin,row,0,"Accept`20-");
X`09mvwaddstr(helpwin,row++,15,"Accept`20the`20double`20and`20the`20game`20cont
Vinues.");
X`09row++;
X`09mvwaddstr(helpwin,row,0,"Decline`20-");
X`09mvwaddstr(helpwin,row++,15,"You`20decline`20the`20double`20and`20lose`20the
V`20game`20for`20the`20current");
X`09mvwaddstr(helpwin,row++,15,"game`20value.");
X`09row++;
X`09`7D
X
Xif(GameState`20==`20STATE_CONTROL)`20`7B
X`09mvwaddstr(helpwin,row,0,"Invert`20-");
X`09mvwaddstr(helpwin,row++,15,"Invert`20the`20board`20for`20this`20game.`20
V`20Pressing`20Invert`20again`20will");
X`09mvwaddstr(helpwin,row++,15,"put`20it`20back`20to`20normal.`20`20Inverting
V`20the`20board`20does`20not`20affect");
X`09mvwaddstr(helpwin,row++,15,"point`20numbering.");
X`09row++;
X`09mvwaddstr(helpwin,row,0,"Resend`20-");
X`09mvwaddstr(helpwin,row++,15,"Resend`20your`20last`20move`20command`20to`20yo
Vur`20opponent.");
X`09row++;
X`09mvwaddstr(helpwin,row,0,"Get`20Resend`20-");
X`09mvwaddstr(helpwin,row++,15,"Request`20a`20resend`20from`20your`20opponent."
V);
X`09row++;
X`09mvwaddstr(helpwin,row,0,"Screen`20Dump`20-");
X`09mvwaddstr(helpwin,row++,15,"Dump`20the`20screen`20to`20ldb_screen.dmp");
X`09row++;
X`09mvwaddstr(helpwin,row,0,"Delete`20Game`20-");
X`09mvwaddstr(helpwin,row++,15,"This`20marks`20a`20game`20for`20deletion.`20
V`20The`20game`20is`20not`20deleted");
X`09mvwaddstr(helpwin,row++,15,"until`20you`20quit`20and`20you`20can`20undelete
V`20it`20by`20pressing`20D`20again.");
X`09row++;
X`09`7D
X
Xif(GameState`20==`20STATE_MYTURN)`20`7B
X`09mvwaddstr(helpwin,row,0,"Roll`20-");
X`09mvwaddstr(helpwin,row++,15,"Roll`20the`20dice.`20`20Your`20roll`20will`20ap
Vpear`20in`20your`20move`20block.");
X`09mvwaddstr(helpwin,row++,15,"You`20will`20see`20two`20numbers`20appear`20or
V`20four`20if`20you`20have");
X`09mvwaddstr(helpwin,row++,15,"rolled`20doubles.");
X`09row++;
X`09mvwaddstr(helpwin,row,0,"Double`20-");
X`09mvwaddstr(helpwin,row++,15,"Choose`20to`20double`20the`20current`20game`20v
Value.`20`20A`20message`20will");
X`09mvwaddstr(helpwin,row++,15,"be`20sent`20to`20your`20opponent`20and`20ldb
V`20then`20will`20automatically");
X`09mvwaddstr(helpwin,row++,15,"select`20roll.");
X`09row++;
X`09`7D
X
Xif(GameState`20==`20STATE_MYMOVE)`20`7B
X`09mvwaddstr(helpwin,row,0,"Point`20-");
X`09mvwaddstr(helpwin,row++,15,"Attempt`20to`20make`20the`20point`20your`20last
V`20move`20ended`20on.");
X`09row++;
X`09mvwaddstr(helpwin,row,0,"Off`20-");
X`09mvwaddstr(helpwin,row++,15,"Bear`20off`20a`20piece`20by`20using`20the`20nex
Vt`20UNUSED`20roll.");
X`09row++;
X`09mvwaddstr(helpwin,row,0,"Reset`20-");
X`09mvwaddstr(helpwin,row++,15,"Reset`20your`20rolls`20to`20UNUSED`20and`20put
V`20the`20board`20back`20how`20it`20was");
X`09mvwaddstr(helpwin,row++,15,"before`20you`20moved.`20`20You`20can`20then`20e
Vnter`20some`20different`20moves.");
X`09row++;
X`09mvwaddstr(helpwin,row,0,"Send`20-");
X`09mvwaddstr(helpwin,row++,15,"Send`20your`20move`20to`20your`20opponent.`20
V`20You`20will`20be`20able`20to");
X`09mvwaddstr(helpwin,row++,15,"enter`202`20lines`20of`2056`20characters`20to
V`20send`20with`20your`20move.");
X`09row++;
X`09`7D
X
Xif(GameState`20!=`20STATE_CONTROL)`20`7B
X`09mvwaddstr(helpwin,row,0,"Board`20-");
X`09mvwaddstr(helpwin,row++,15,"Cycle`20between`20the`20current`20board,`20the
V`20board`20before`20your");
X`09mvwaddstr(helpwin,row++,15,"opponent's`20last`20move,`20and`20the`20board
V`20after`20your`20opponent's");
X`09mvwaddstr(helpwin,row++,15,"last`20move.");
X`09row++;
X`09`7D
X
Xif((GameState`20==`20STATE_MYTURN)`20`7C`7C`20(GameState`20==`20STATE_MYMOVE))
V`20`7B
X`09mvwaddstr(helpwin,row,0,"Concede`20-");
X`09mvwaddstr(helpwin,row++,15,"Concede`20the`20current`20game.");
X`09row++;
X`09`7D
X
Xmvwaddstr(helpwin,row,0,"Next`20Game`20-");
Xmvwaddstr(helpwin,row++,15,"The`20next`20game`20is`20displayed.`20`20If`20ther
Ve`20is`20no`20next`20game,`20quit.");
Xrow++;
Xmvwaddstr(helpwin,row,0,"Quit`20-");
Xmvwaddstr(helpwin,row++,15,"Quit`20the`20current`20ldb`20session.");
X
Xmvwaddstr(helpwin,23,25,"Press`20<return>`20to`20continue:`20");
X
Xtouchwin(helpwin);`09`09/*`20Make`20sure`20the`20screen`20is`20updated`20*/
Xwrefresh(helpwin);`09`09/*`20update`20the`20help`20window`20clearing`20screen
V`20*/
Xwgetch(helpwin);`09`09/*`20Wait`20for`20user`20response`20*/
Xwclear(helpwin);`09`09/*`20clear`20the`20help`20window`20*/
Xwrefresh(helpwin);`09`09/*`20update`20the`20help`20window`20clearing`20screen
V`20*/
Xdelwin(helpwin);`09`09/*`20delete`20the`20help`20window`20*/
X`7D
$ call unpack DOHELP.C;1 1229486700 ""
$!
$ create 'f'
X/*`20dostats.c`09`094/20/92
X`20*
X`20*`20Copyright`201992`20`20Earle`20F.`20Ake
X`20*
X`20*`20Permission`20to`20use,`20copy,`20modify,`20and`20distribute`20this`20so
Vftware`20and`20its
X`20*`20documentation`20without`20fee`20is`20hereby`20granted,`20subject`20to
V`20the`20restrictions
X`20*`20detailed`20in`20the`20README`20file,`20which`20is`20included`20here`20b
Vy`20reference.
X`20*`20Any`20other`20use`20requires`20written`20permission`20from`20the`20auth
Vor.`20`20This`20software
X`20*`20is`20distributed`20"as`20is"`20without`20any`20warranty,`20including
V`20any`20implied
X`20*`20warranties`20of`20merchantability`20or`20fitness`20for`20a`20particular
V`20purpose.
X`20*`20The`20author`20shall`20not`20be`20liable`20for`20any`20damages`20result
Ving`20from`20the
X`20*`20use`20of`20this`20software.`20`20By`20using`20this`20software,`20the
V`20user`20agrees
X`20*`20to`20these`20terms.
X`20*
X`20*`20Original`20coding`20by`20Earle`20F.`20Ake`20<ake@dayton.saic.com>`20-
V`2020`20April`201992.
X`20*
X`20*/
X
X#include`20"ldb.h"
X
X/*----------------------------------------------------------------------
X`20*`09dostats`20--`20display`20online`20statistics`20of`20dice`20rolls
X`20*
X`20*`20This`20function`20creates`20a`20new`20curses`20window`20and`20displays
V`20dice`20statistics
X`20*`20to`20the`20user.`20`20The`20user`20then`20presses`20any`20key`20to`20re
Vturn`20to`20the`20game.
X`20*----------------------------------------------------------------------
X`20*/
X
Xdostats(g)
Xstruct`20game`20*g;
X`7B
XWINDOW`20*statwin;
Xint`20row,`20i,`20col,`20rolls,`20dice;
Xint`20mypip,`20oppip;
Xchar`20temp`5B80`5D;
Xchar`20c;
Xint`20Total`20=`200,`20OpTotal`20=`200;
X
Xstatwin`20=`20newwin(0,0,0,0);`09/*`20get`20a`20new`20window`20to`20post`20hel
Vp`20to`20*/
X
Xmvwaddstr(statwin,0,30,"ldb`20Dice`20Statistics");`09`09/*`20print`20title`20*
V/
Xmvwaddstr(statwin,1,30,"-------------------");`09`09/*`20underline`20title`20*
V/
Xrow`20=`203;
X
Xmvwaddstr(statwin,row++,0,"You:");
Xmvwaddstr(statwin,row++,0,"----");
X
Xrow++;
Xmvwaddstr(statwin,row++,0,"Singles`20`20`201`20`202`20`203`20`204`20`205`20
V`206`20`20Doubles`20`20`201`20`202`20`203`20`204`20`205`20`206");
Xtemp`5B0`5D`20=`20'`5C0';
Xfor`20(i`20=`200;`20i`20<`206;`20i++)`20`7B
X`09sprintf(temp,`20"%s%3d",`20temp,`20g->rolls`5Bi`5D);
X`09Total`20+=`20(g->rolls`5Bi`5D`20*`20(i+1));
X`09`7D
Xsprintf(temp,`20"%s`20`20`20`20`20`20`20`20`20`20",temp);
Xfor`20(i`20=`200;`20i`20<`206;`20i++)`20`7B
X`09sprintf(temp,`20"%s%3d",`20temp,`20g->doubles`5Bi`5D);
X`09Total`20+=`20(g->doubles`5Bi`5D`20*`20(i+1)`20*`204);
X`09`7D
X
Xmvwaddstr(statwin,row++,8,temp);
Xrow++;
Xpipcount(g->board,g,`26mypip,`26oppip);
Xsprintf(temp,"Total`20of`20your`20dice`20rolls`20=`20%-3d`20`20`20`20`20`20
V`20`20Pips`20remaining`20=`20%-3d",
X`09Total,mypip);
Xmvwaddstr(statwin,row++,0,temp);
Xrow++;
Xrow++;
X
Xmvwaddstr(statwin,row++,0,"Opponent:");
Xmvwaddstr(statwin,row++,0,"---------");
X
Xrow++;
Xmvwaddstr(statwin,row++,0,"Singles`20`20`201`20`202`20`203`20`204`20`205`20
V`206`20`20Doubles`20`20`201`20`202`20`203`20`204`20`205`20`206");
Xtemp`5B0`5D`20=`20'`5C0';
Xfor`20(i`20=`200;`20i`20<`206;`20i++)`20`7B
X`09sprintf(temp,`20"%s%3d",`20temp,`20g->oprolls`5Bi`5D);
X`09OpTotal`20+=`20(g->oprolls`5Bi`5D`20*`20(i+1));
X`09`7D
Xsprintf(temp,`20"%s`20`20`20`20`20`20`20`20`20`20",temp);
Xfor`20(i`20=`200;`20i`20<`206;`20i++)`20`7B
X`09sprintf(temp,`20"%s%3d",`20temp,`20g->opdoubles`5Bi`5D);
X`09OpTotal`20+=`20(g->opdoubles`5Bi`5D`20*`20(i+1)`20*`204);
X`09`7D
X
Xmvwaddstr(statwin,row++,8,temp);
Xrow++;
Xsprintf(temp,"Total`20of`20opponent`20dice`20rolls`20=`20%-3d`20`20`20`20Pips
V`20remaining`20=`20%-3d",
X`09OpTotal,oppip);
Xmvwaddstr(statwin,row++,0,temp);
X
X
Xmvwaddstr(statwin,23,16,"Press`20H`20for`20histogram`20or`20<return>`20to`20co
Vntinue:`20");
X
Xtouchwin(statwin);`09`09/*`20Make`20sure`20the`20screen`20is`20updated`20*/
Xwrefresh(statwin);`09`09/*`20update`20the`20window`20clearing`20screen`20*/
Xc`20=`20wgetch(statwin)`20`26`200x7f;`09/*`20Wait`20for`20user`20response`20*/
V
X
Xif`20(c`20==`20'h'`20`7C`7C`20c`20==`20'H')`20`7B`09/*`20Histogram`20wanted
V`20*/
X`09wclear(statwin);`09`09/*`20clear`20the`20window`20*/
X
X/*
X`20*`20Draw`20the`20axis`20themselves
X`20*
X`20*/
X
X
X`09for`20(i`20=`202;`20i`20<`2018;`20i++)`20`7B`09`09/*`20Vertical`20axis`20*/
V
X`09`09mvwaddstr(statwin,i,11,"`7C");
X`09`09mvwaddstr(statwin,i,44,"`7C");
X`09`09`7D
X
X`09for`20(i`20=`2012;`20i`20<`2041;`20i++)`20`7B`09`09/*`20Horizontal`20axis
V`20*/
X`09`09mvwaddstr(statwin,17,i,"-");
X`09`09mvwaddstr(statwin,17,i+33,"-");
X`09`09`7D
X
X/*
X`20*`20Number`20the`20vertical`20axis
X`20*
X`20*/
X
X`09mvwaddstr(statwin,2,8,"15");
X`09mvwaddstr(statwin,2,41,"15");
X
X`09mvwaddstr(statwin,7,8,"10");
X`09mvwaddstr(statwin,7,41,"10");
X
X`09mvwaddstr(statwin,12,9,"5");
X`09mvwaddstr(statwin,12,42,"5");
X
X/*
X`20*`20Put`20the`20numbers`20across`20the`20bottom`20of`20the`20axis
X`20*
X`20*/
X
X`09col`20=`2013;
X`09for`20(i`20=`201;`20i`20<`207;`20i++)`20`7B
X`09`09sprintf(temp,"%d",`20i);
X`09`09mvwaddch(statwin,18,col,temp`5B0`5D);
X`09`09mvwaddch(statwin,18,col+33,temp`5B0`5D);
X`09`09col`20+=`205;
X`09`09`7D
X
X/*
X`20*`20Label`20the`20top`20and`20bottom`20of`20the`20graph
X`20*
X`20*/
X
X`09mvwaddstr(statwin,0,17,"H`20i`20s`20t`20o`20g`20r`20a`20m`20`20`20o`20f`20
V`20`20D`20I`20C`20E`20`20`20R`20o`20l`20l`20s");
X`09mvwaddstr(statwin,19,20,"S`20I`20N`20G`20L`20E`20S");
X`09mvwaddstr(statwin,19,53,"D`20O`20U`20B`20L`20E`20S");
X`09mvwaddstr(statwin,21,4,"Legend:");
X`09sprintf(temp,"X`20=`20You,`20dice`20total`20=`20%3d",`20Total);
X`09sprintf(temp,"%s`20`20`20`20`20O`20=`20Opponent,`20dice`20total`20=`20%3d",
V`20temp,`20OpTotal);
X`09mvwaddstr(statwin,21,14,temp);
X`09wmove(statwin,22,23);
X`09wprintw(statwin,"pips`20`20`20`20`20`20`20=`20%3d",mypip);
X`09wmove(statwin,22,58);
X`09wprintw(statwin,"pips`20`20`20`20`20`20`20=`20%3d",oppip);
X
X/*
X`20*`20Label`20the`20left`20side`20of`20the`20graph
X`20*
X`20*/
X
X`09sprintf(temp,"Number");
X`09for`20(i`20=`200;`20i`20<`20strlen(temp);`20i++)
X`09`09mvwaddch(statwin,7+i,0,temp`5Bi`5D);
X
X`09sprintf(temp,"of");
X`09for`20(i`20=`200;`20i`20<`20strlen(temp);`20i++)
X`09`09mvwaddch(statwin,9+i,3,temp`5Bi`5D);
X
X`09sprintf(temp,"Occurrences");
X`09for`20(i`20=`200;`20i`20<`20strlen(temp);`20i++)
X`09`09mvwaddch(statwin,5+i,6,temp`5Bi`5D);
X
X/*
X`20*`20Now`20that`20we`20have`20the`20axis`20drawn`20and`20labeled,`20fill`20i
Vn`20the`20data
X`20*
X`20*/
X
X`09for`20(dice`20=`200;`20dice`20<`206;`20dice++)`20`7B
X`09`09for`20(i`20=`200;`20i`20<`204;`20i++)`20`7B
X`09`09`09switch`20(i)`20`7B
X`09`09`09case`200:
X`09`09`09`09rolls`20=`20g->rolls`5Bdice`5D;
X`09`09`09`09col`20=`2012`20+`20dice`20*`205;
X`09`09`09`09c`20=`20'X';
X`09`09`09`09break;
X`09`09`09case`201:
X`09`09`09`09rolls`20=`20g->oprolls`5Bdice`5D;
X`09`09`09`09col`20=`2014`20+`20dice`20*`205;
X`09`09`09`09c`20=`20'O';
X`09`09`09`09break;
X`09`09`09case`202:
X`09`09`09`09rolls`20=`20g->doubles`5Bdice`5D;
X`09`09`09`09col`20=`2045`20+`20dice`20*`205;
X`09`09`09`09c`20=`20'X';
X`09`09`09`09break;
X`09`09`09case`203:
X`09`09`09`09rolls`20=`20g->opdoubles`5Bdice`5D;
X`09`09`09`09col`20=`2047`20+`20dice`20*`205;
X`09`09`09`09c`20=`20'O';
X`09`09`09`09break;
X`09`09`09`09`7D
X`09
X/*
X`20*`20Special`20case.`20`20If`20we`20have`20more`20than`2030`20of`20one`20rol
Vl,`20put`20a`20*`20at`20the
X`20*`20top`20of`20the`20second`20column`20and`20show`2029`20X's`20or`20O's.
X`20*
X`20*/
X
X`09`09`09row`20=`2016;
X`09`09`09if`20(rolls`20>`2030)`20`7B
X`09`09`09`09rolls`20=`2029;
X`09`09`09`09mvwaddch(statwin,2,col+1,'*');
X`09`09`09`09`7D
X
X/*
X`20*`20While`20the`20roll`20counter`20is`20greater`20than`20zero,`20put`20out
V`20X's`20or`20O's.
X`20*
X`20*/
X
X`09`09`09while`20(rolls`20>`200)`20`7B
X`09`09`09`09mvwaddch(statwin,row--,col,c);
X`09`09`09`09rolls--;
X`09`09`09`09if`20(row`20<`202)`20`7B`09/*`20move`20to`202nd`20column`20*/
X`09`09`09`09`09row`20=`2016;
X`09`09`09`09`09col++;
X`09`09`09`09`09`7D
X`09`09`09`09`7D
X`09`09`09`7D
X`09`09`7D
X
X/*
X`20*`20We`20are`20done`20with`20the`20graph.`20`20Refresh`20and`20wait`20for
V`20a`20keypress
X`20*
X`20*/
X
X`09mvwaddstr(statwin,23,25,"Press`20<return>`20to`20continue:`20");
X`09touchwin(statwin);`09`09/*`20Make`20sure`20the`20screen`20is`20updated`20*/
V
X`09wrefresh(statwin);`09`09/*`20update`20the`20window`20clearing`20screen`20*/
V
X`09wgetch(statwin);`09`09/*`20Wait`20for`20user`20response`20*/
X`09`7D
X
Xwclear(statwin);`09`09/*`20clear`20the`20window`20*/
Xwrefresh(statwin);`09`09/*`20update`20the`20window`20clearing`20screen`20*/
+-+-+-+-+-+-+-+- END OF PART 7 +-+-+-+-+-+-+-+-