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 >
Wrap
Internet Message Format
|
1993-04-07
|
49KB
Path: uunet!zaphod.mps.ohio-state.edu!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 [12/16]
Date: 8 Apr 93 11:01:50 EST
Organization: Science Applications Intl Corp - Dayton, OH
Lines: 1319
Message-ID: <1993Apr8.110150.1@dayvd.dayton.saic.com>
NNTP-Posting-Host: dayvd.dayton.saic.com
Xref: uunet vmsnet.sources.games:673
-+-+-+-+-+-+-+-+ START OF PART 12 -+-+-+-+-+-+-+-+
X`09`09`09b`5Bnp`5D.qty`20=`200;`09`09/*`20bye`20bye`20*/
X`09`09`09j`20=`20BARPT(REV(dir));`09/*`20send`20it`20to`20opponents`20bar`20*/
V
X`09`09`09b`5Bj`5D.color`20=`20b`5Bnp`5D.color;`20/*`20copy`20color`20to`20bar
V`20pt`20*/
X`09`09`09b`5Bj`5D.qty++;`09`09/*`20bump`20counter`20*/
X`09`09`09if`20(flags`20`26`20A_REDRAW)`20`7B`09/*`20update`20screen`20*/
X`09`09`09`09FeDrawPoint(b,j,0,g->flags`20`26`20F_INVERT);
X`09`09`09`09FeDrawPip(b,g);
X`09`09`09`09`7D
X`09`09`09b`5Bnp`5D.color`20=`20b`5Bop`5D.color;`09/*`20my`20point`20now`20*/
X`09`09`09`7D
X`09`09`7D
X`09else
X`09`09return(RJ_OCC);`09`09/*`20point`20is`20occupied`20*/
X`09`7D
Xif`20(`20(flags`20`26`20A_CHKONLY)`20==`200)`20`7B
X`09b`5Bop`5D.qty--;`09`09`09`09/*`20take`20piece`20from`20old`20pt`20*/
X`09b`5Bnp`5D.qty++;`09`09`09`09/*`20and`20put`20in`20on`20new`20pt`20*/
X`09if`20(flags`20`26`20A_REDRAW)`20`7B
X`09`09FeDrawPip(b,g);
X`09`09FeDrawPoint(b,op,0,g->flags`20`26`20F_INVERT);/*`20update`20the`20screen
V`20*/
X`09`09FeDrawPoint(b,np,0,g->flags`20`26`20F_INVERT);
X`09`09`7D
X`09`7D
Xif`20(dest`20!=`20NULL)`09`09`09/*`20return`20new`20position`20*/
X`09*dest`20=`20np;
Xreturn(blot);`09`09`09`09/*`20succeeded,`20return`20MVOK`20or`20blot`20*/
X`7D
X
X
X/*----------------------------------------------------------------------
X`20*`09addpcs`20--`20add`20the`20number`20of`20pieces`20in`20a`20range`20of
V`20points
X`20*
X`20*`20This`20function`20returns`20the`20number`20of`20pieces`20of`20a`20certa
Vin`20color
X`20*`20that`20reside`20within`20a`20range`20of`20points.
X`20*----------------------------------------------------------------------
X`20*/
X
Xaddpcs(b,clr,f,t)
Xboard`20b;
Xchar`20clr;
Xint`20f,`20t;
X`7B
Xint`20i,`20q;
X
Xq`20=`200;`09`09`09`09/*`20quantity`20we`20have`20found`20so`20far`20*/
Xfor`20(i`20=`20f;`20i`20<=`20t;`20i++)
X`09if`20(b`5Bi`5D.color`20==`20clr)`09/*`20found`20some`20*/
X`09`09q`20+=`20b`5Bi`5D.qty;`09/*`20count`20them`20*/
Xreturn(q);`09`09`09/*`20return`20quantity`20found`20*/
X`7D
$ call unpack MOVE.C;1 268841531 ""
$!
$ create 'f'
X/*`09process.c`09`098/8/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`20code`20to`20process`20user`20input.
X`20*==========================================================================
V=
X`20*/
X
X
X
X/*----------------------------------------------------------------------
X`20*`09process`20--`20process`20a`20game`20while`20it`20needs`20local`20input
X`20*
X`20*`20This`20function`20calls`20the`20appropriate`20handler,`20according`20to
V`20what
X`20*`20state`20the`20game`20is`20in,`20to`20prompt`20the`20user`20for`20input.
V`20`20If`20a`20game
X`20*`20does`20not`20need`20local`20input,`20it`20is`20skipped.`20`20Process()
V`20returns`201
X`20*`20if`20the`20game`20still`20needs`20local`20input,`20in`20which`20case
V`20the`20main`20program
X`20*`20will`20re-call`20process`20with`20the`20same`20game.`20`20When`20the
V`20game`20no`20longer
X`20*`20needs`20local`20input,`20process`20will`20return`200,`20telling`20the
V`20main`20program
X`20*`20to`20proceed`20to`20the`20next`20game.
X`20*----------------------------------------------------------------------
X`20*/
X
Xprocess(g)
Xstruct`20game`20*g;
X`7B
Xint`20i;
X
Xif`20(g->state`20<`20OPSTATES)`09/*`20this`20game`20is`20waiting`20for`20the
V`20opponent`20*/
X`09return(0);`09`09/*`20skip`20it`20for`20now`20*/
Xif`20(`20(g->state`20==`20ST_GAMEOVER)`20`26`26`20(g->flags`20`26`20F_DISPLAYE
VD)`20)
X`09return(0);`09/*`20game`20is`20in`20"keepold"`20wait,`20no`20need`20to`20dis
Vplay`20*/
XFeDrawGame(g);`09`09`09/*`20draw`20the`20game`20*/
Xswitch`20(g->state)`20`7B
Xcase`20ST_MYTURN:`09`09`09/*`20my`20turn,`20I`20haven't`20rolled`20yet`20*/
X`09if`20(`20((g->flags`20`26`20F_IDOUBLED)`20==`200)`20`7C`7C`20(*rc.autoroll
V`20==`20'n')`20)`20`7B
X`09`09i`20=`20myturn(g);`09/*`20I`20didn't`20double`20last`20*/
X`09`09break;
X`09`09`7D
X`09rolldice(g);`09`09/*`20if`20I`20doubled`20last,`20go`20ahead`20and`20roll
V`20*/
X`09g->state`20=`20ST_MYMOVE;`09/*`20skip`20this`20state`20completely`20*/
X`09if`20(*rc.chkpt`20==`20'y')`20`7B`09/*`20checkpoint`20games`20*/
X`09`09writegames(rc.gfile,rc.gbackup,rc.pfile);
X`09`09rc.gbackup`20=`20NULL;`09/*`20only`20backup`20old`20file`20once`20*/
X`09`09`7D
X`09for`20(i`20=`200;`20i`20<`204;`20i++)`09`09/*`20draw`20my`20new`20roll`20*/
V
X`09`09FeDrawMove(g,WHO_ME,i);
X`09/****`20fall`20through`20****/
Xcase`20ST_MYMOVE:`09`09`09/*`20my`20turn,`20I`20have`20rolled`20*/
X`09i`20=`20mymove(g);`09`09/*`20user`20has`20rolled,`20must`20move`20*/
X`09break;
Xcase`20ST_MYACCEPT:
X`09i`20=`20myacpt(g);`09/*`20user`20must`20accept`20or`20decline`20double`20*/
V
X`09break;
Xcase`20ST_GAMEOVER:
X`09i`20=`20gameover(g);`09`09/*`20tell`20him`20the`20game`20is`20over`20*/
X`09break;
X`09`7D
Xreturn(i);
X`7D
X
X
X/*----------------------------------------------------------------------
X`20*`09myturn`20--`20allow`20user`20to`20roll`20or`20double
X`20*
X`20*`20This`20function`20is`20called`20to`20allow`20the`20user`20to`20choose
V`20between
X`20*`20rolling`20the`20dice`20and`20doubling.`20`20It`20also`20allows`20the
V`20user`20to`20cycle
X`20*`20through`20the`20three`20board`20displays,`20to`20concede,`20and`20to
V`20go`20to`20the`20next`20game.
X`20*----------------------------------------------------------------------
X`20*/
X
Xmyturn(g)
Xstruct`20game`20*g;
X`7B
Xchar`20c;
Xchar`20pm`20=`20'`5C0';
Xint`20gv;
Xstatic`20char`20*m`5B`5D=`7B"Roll","Double","Board","Next`20Game","Concede","Q
Vuit",NULL`7D;
X
XFeDrawMenu(m);`09`09`09/*`20display`20the`20menu`20*/
XGameState`20=`20STATE_MYTURN;
Xwhile`20(1)`20`7B
X`09c`20=`20FeMenu(m,0,0,"`5Cn`5Cr`20",pm);`09/*`20get`20a`20menu`20choice`20*/
V
X`09pm`20=`20c;
X`09switch`20(c)`20`7B
X`09case`20'`5Cn':
X`09case`20'`5Cr':
X`09case`20'`20':
X`09`09FeOnMenuItem(m,'R');`09/*`20highlight`20Roll`20item`20*/
X`09`09pm`20=`20'R';`09`09/*`20remember`20to`20unhighlight`20it`20later`20*/
X`09`09/*`20fall`20through`20*/
X`09case`20'R':`09`09`09/*`20roll`20them`20dice`20*/
X`09`09g->curbd`20=`20BD_CUR;`09/*`20bring`20up`20current`20board`20*/
X`09`09rolldice(g);
X`09`09g->state`20=`20ST_MYMOVE;`09/*`20I`20just`20entered`20a`20new`20state
V`20*/
X`09`09if`20(*rc.chkpt`20==`20'y')`20`7B`09/*`20checkpoint`20games`20*/
X`09`09`09writegames(rc.gfile,rc.gbackup,rc.pfile);
X`09`09`09rc.gbackup`20=`20NULL;`09/*`20only`20backup`20old`20file`20once`20*/
X`09`09`09`7D
X`09`09return(1);`09`09/*`20make`20sure`20process`20gets`20re-called`20*/
X`09case`20'D':`09`09`09/*`20I`20want`20to`20double`20*/
X`09`09if`20(g->flags`20`26`20F_IDOUBLED)`20`7B`09/*`20I`20doubled`20last`20*/
X`09`09`09FeMessage("You`20doubled`20last.");
X`09`09`09break;`09`09/*`20so`20I`20can't`20double`20now`20*/
X`09`09`09`7D
X`09`09if`20(g->flags`20`26`20F_CRGAME)`20`7B
X`09`09`09FeMessage("Double`20not`20allowed`20(Crawford`20rule)");
X`09`09`09break;
X`09`09`09`7D
X`09`09if`20(FeGetComment(g)`20<`200)`20`7B`09/*`20get`20message`20*/
X`09`09`09FeMessage("Double`20aborted.");
X`09`09`09break;`09`09/*`20changed`20his`20mind`20*/
X`09`09`09`7D
X`09`09g->state`20=`20ST_OPACCEPT;`09/*`20we`20are`20waiting`20for`20accept/dec
Vline`20*/
X`09`09sendpkt(g,OFRDBL);`09/*`20send`20the`20double`20packet`20*/
X`09`09return(0);`09`09/*`20this`20game`20is`20done`20for`20now`20*/
X`09case`20'C':`09`09`09/*`20I'm`20wimping`20out`20*/
X`09`09if`20(`20(check_concede(g)`20==`200)`20`7C`7C`20(FeGetComment(g)`20<`200
V)`20)`20`7B
X`09`09`09FeMessage("Concede`20aborted.");
X`09`09`09break;
X`09`09`09`7D
X`09`09ilose(g,T_ICONCEDE,0);`09/*`20this`20game`20is`20over`20*/
X`09`09sendpkt(g,CONCEDE);`09/*`20send`20the`20packet`20*/
X`09`09return(1);`09`09/*`20display`20the`20gameover`20screen`20*/
X`09case`20'B':`09`09`09/*`20display`20different`20board`20*/
X`09`09if`20(g->curbd++`20>=`20BD_CUR)`09/*`20go`20to`20next`20board`20*/
X`09`09`09g->curbd`20=`20BD_BEFOP;`09/*`20wrap`20around`20*/
X`09`09return(1);`09`09/*`20redraw`20`26`20call`20us`20again`20*/
X`09case`20'N':`09`09`09/*`20I`20don't`20want`20to`20decide`20right`20now`20*/
X`09`09return(0);
X`09case`20'Q':`09`09`09/*`20I`20want`20to`20quit`20ldb`20*/
X`09`09return(-1);
X`09`09`7D
X`09`7D
X`7D
X
X
X/*----------------------------------------------------------------------
X`20*`09mymove`20--`20allow`20user`20to`20move
X`20*
X`20*`20This`20function`20is`20called`20to`20allow`20the`20user`20to`20use`20hi
Vs`20roll.
X`20*`20It`20also`20allows`20the`20user`20to`20cycle`20through`20the`20three
V`20board`20displays,
X`20*`20to`20concede,`20and`20to`20go`20to`20the`20next`20game.
X`20*`20Since`20the`20user`20has`20already`20rolled,`20doubling`20is`20not`20al
Vlowed`20here.
X`20*----------------------------------------------------------------------
X`20*/
X
Xmymove(g)
Xstruct`20game`20*g;
X`7B
Xchar`20c;
Xint`20i,`20n;
Xstatic`20char`20used`5B`5D`20=`20"That`20move`20is`20already`20used`20--`20use
V`20Reset`20to`20start`20over";
Xstruct`20mv`20tmp;
Xstatic`20char`20*m`5B`5D`20=`20`7B"Reset","Send","Board","Next`20Game","Conced
Ve",
X`09`09`09"Point","Off","Quit",NULL`7D;
Xchar`20pm`20=`20'`5C0';
Xint`20lastpt`20=`2099;`09`09/*`20point`20last`20move`20started`20from`20*/
Xint`20lastd`20=`2099;`09`09`09/*`20point`20last`20move`20ended`20at`20*/
X
XFeDrawMenu(m);
XGameState`20=`20STATE_MYMOVE;
Xwhile`20(1)`20`7B
X`09c`20=`20FeMenu(m,g->mvs`5B0`5D.roll,g->mvs`5B1`5D.roll,"`5Cn`5Cr`20",pm);
X`09pm`20=`20c;
X`09switch`20(c)`20`7B
X`09case`20'S':`09`09`09/*`20send`20moves`20*/
X`09`09if`20(checkused(g))`09/*`20didn't`20use`20all`20our`20moves`20*/
X`09`09`09break;
X`09`09if`20(FeGetComment(g)`20<`200)`20`7B`09/*`20get`20our`20comment`20*/
X`09`09`09FeMessage("Send`20aborted.");
X`09`09`09break;
X`09`09`09`7D
X`09`09if`20(g->board`5BOFFPT(g->mydir)`5D.qty`20==`2015)`09/*`20I`20win`20*/
X`09`09`09iwin(g,T_IWIN,0);
X`09`09else
X`09`09`09g->state`20=`20ST_OPTURN;
X`09`09sendpkt(g,MOVE);`09`09/*`20send`20our`20move`20*/
X`09`09return(g->state`20==`20ST_GAMEOVER);/*`20need`20to`20call`20gameover()
V`20*/
X`09case`20'R':`09`09`09/*`20reset`20--`20erase`20moves`20`26`20start`20over
V`20*/
X`09`09if`20(g->curbd`20!=`20BD_CUR)`09`09/*`20if`20we`20are`20not`20looking
V`20at`20*/
X`09`09`09g->curbd`20=`20BD_CUR;`09/*`20current`20board,`20switch`20*/
X`09`09for`20(i`20=`200;`20i`20<`204;`20i++)`20`7B
X`09`09`09g->mvs`5Bi`5D.pt`20=`20-1;
X`09`09`09FeDrawMove(g,WHO_ME,i);
X`09`09`09`7D
X`09`09copyboard(g->mybd,g->board);
X`09`09FeDrawBoard(g->board,NULL,g->mydir,0,g->flags`20`26`20F_INVERT);
X`09`09FeLabelBoard(g);
X`09`09FeDrawPip(g->board,g);
X`09`09break;
X`09case`20'B':`09`09`09`09/*`20display`20different`20board`20*/
X`09`09if`20(g->curbd++`20>=`20BD_CUR)`09/*`20go`20to`20next`20board`20*/
X`09`09`09g->curbd`20=`20BD_BEFOP;`09/*`20wrap`20around`20*/
X`09`09return(1);`09`09/*`20redraw`20`26`20call`20us`20again`20*/
X`09case`20'C':`09`09`09/*`20I'm`20wimping`20out`20*/
X`09`09if`20(`20(check_concede(g)`20==`200)`20`7C`7C`20(FeGetComment(g)`20<`200
V)`20)`20`7B
X`09`09`09FeMessage("Concede`20aborted.");
X`09`09`09break;
X`09`09`09`7D
X`09`09ilose(g,T_ICONCEDE,0);
X`09`09sendpkt(g,CONCEDE);`09/*`20send`20the`20packet`20*/
X`09`09return(1);`09`09/*`20display`20the`20gameover`20screen`20*/
X`09case`20'N':`09`09`09/*`20I`20don't`20want`20to`20decide`20right`20now`20*/
X`09`09return(0);
X`09case`20'Q':`09`09`09/*`20I`20want`20to`20quit`20ldb`20*/
X`09`09return(-1);
X`09case`20'`20':`09`09`09/*`20continue`20last`20move`20*/
X`09`09if`20(g->curbd`20!=`20BD_CUR)`20`7B
X`09`09`09g->curbd`20=`20BD_CUR;
X`09`09`09FeDrawBoard(g->board,NULL,g->mydir,0,
X`09`09`09`09g->flags`20`26`20F_INVERT);
X`09`09`09FeLabelBoard(g);
X`09`09`09`7D
X`09`09n`20=`20(g->mvs`5B0`5D.roll`20==`20g->mvs`5B1`5D.roll)`20?`204`20:`202;
X`09`09for`20(i`20=`200;`20i`20<`20n;`20i++)`09`09/*`20search`20for`20an`20unus
Ved`20move`20*/
X`09`09`09if`20(g->mvs`5Bi`5D.pt`20<`200)
X`09`09`09`09break;
X`09`09if`20(i`20>=`20n)`20`7B
X`09`09`09FeMessage("You`20don't`20have`20any`20moves`20left.");
X`09`09`09break;
X`09`09`09`7D
X`09`09if`20(`20(lastd`20<`201)`20`7C`7C`20(lastd`20>`2024)`20)`20`7B
X`09`09`09FeMessage(
X`09`09`09`20`20`20"No`20move`20to`20continue`20--`20please`20select`20a`20roll
V.");
X`09`09`09break;
X`09`09`09`7D
X`09`09g->mvs`5Bi`5D.pt`20=`20lastd;
X`09`09n`20=`20apply(g,WHO_ME,i,A_REDRAW,`26lastd);
X`09`09if`20(n`20<`200)`20`7B`09/*`20move`20rejected`20*/
X`09`09`09g->mvs`5Bi`5D.pt`20=`20-1;
X`09`09`09FeMessage(rejlcl`5B-n`5D);
X`09`09`09lastd`20=`2099;
X`09`09`09`7D
X`09`09else
X`09`09`09lastpt`20=`20g->mvs`5Bi`5D.pt;
X`09`09FeDrawMove(g,WHO_ME,i);
X`09`09FeCheckContact(g);
X`09`09break;
X`09case`20'`5Cn':`09`09`09/*`20repeat`20last`20move`20*/
X`09case`20'`5Cr':
X`09`09if`20(g->curbd`20!=`20BD_CUR)`20`7B
X`09`09`09g->curbd`20=`20BD_CUR;
X`09`09`09FeDrawBoard(g->board,NULL,g->mydir,0,
X`09`09`09`09g->flags`20`26`20F_INVERT);
X`09`09`09FeLabelBoard(g);
X`09`09`09`7D
X`09`09n`20=`20(g->mvs`5B0`5D.roll`20==`20g->mvs`5B1`5D.roll)`20?`204`20:`202;
X`09`09for`20(i`20=`200;`20i`20<`20n;`20i++)`09`09/*`20search`20for`20an`20unus
Ved`20move`20*/
X`09`09`09if`20(g->mvs`5Bi`5D.pt`20<`200)
X`09`09`09`09break;
X`09`09if`20(i`20>=`20n)`20`7B
X`09`09`09FeMessage("You`20don't`20have`20any`20moves`20left.");
X`09`09`09break;
X`09`09`09`7D
X`09`09if`20(`20(lastpt`20<`200)`20`7C`7C`20(lastpt`20>`2025)`20)`20`7B
X`09`09`09FeMessage("No`20move`20to`20repeat`20--`20please`20select`20a`20roll.
V");
X`09`09`09break;
X`09`09`09`7D
X`09`09g->mvs`5Bi`5D.pt`20=`20lastpt;
X`09`09n`20=`20apply(g,WHO_ME,i,A_REDRAW,`26lastd);
X`09`09if`20(n`20<`200)`20`7B`09/*`20move`20rejected`20*/
X`09`09`09g->mvs`5Bi`5D.pt`20=`20-1;
X`09`09`09FeMessage(rejlcl`5B-n`5D);
X`09`09`09lastpt`20=`2099;
X`09`09`09`7D
X`09`09FeDrawMove(g,WHO_ME,i);
X`09`09FeCheckContact(g);
X`09`09break;
X`09case`20'P':`09`09`09`09/*`20make`20point`20from`20last`20move`20*/
X`09`09if`20(g->curbd`20!=`20BD_CUR)`20`7B
X`09`09`09g->curbd`20=`20BD_CUR;
X`09`09`09FeDrawBoard(g->board,NULL,g->mydir,0,
X`09`09`09`09g->flags`20`26`20F_INVERT);
X`09`09`09FeLabelBoard(g);
X`09`09`09`7D
X`09`09n`20=`20(g->mvs`5B0`5D.roll`20==`20g->mvs`5B1`5D.roll)`20?`204`20:`202;
X`09`09for`20(i`20=`200;`20i`20<`20n;`20i++)`09`09/*`20search`20for`20an`20unus
Ved`20move`20*/
X`09`09`09if`20(g->mvs`5Bi`5D.pt`20<`200)
X`09`09`09`09break;
X`09`09if`20(i`20>=`20n)`20`7B
X`09`09`09FeMessage("You`20don't`20have`20any`20moves`20left.");
X`09`09`09break;
X`09`09`09`7D
X`09`09if`20(`20(lastpt`20<`200)`20`7C`7C`20(lastpt`20>`2025)`20)`20`7B
X`09`09`09FeMessage("No`20point`20to`20make`20--`20please`20select`20a`20roll."
V);
X`09`09`09break;
X`09`09`09`7D
X`09`09g->mvs`5Bi`5D.pt`20=`20lastd`20-`20g->mydir*g->mvs`5Bi`5D.roll;
X`09`09n`20=`20apply(g,WHO_ME,i,A_REDRAW,`26lastd);
X`09`09if`20(n`20<`200)`20`7B`09/*`20move`20rejected`20*/
X`09`09`09g->mvs`5Bi`5D.pt`20=`20-1;
X`09`09`09FeMessage(rejlcl`5B-n`5D);
X`09`09`09`7D
X`09`09FeDrawMove(g,WHO_ME,i);
X`09`09FeCheckContact(g);
X`09`09break;
X`09case`20'O':`09`09`09`09/*`20bear`20off`20with`20next`20roll`20*/
X`09`09if`20(g->curbd`20!=`20BD_CUR)`20`7B
X`09`09`09g->curbd`20=`20BD_CUR;
X`09`09`09FeDrawBoard(g->board,NULL,g->mydir,0,
X`09`09`09`09g->flags`20`26`20F_INVERT);
X`09`09`09FeLabelBoard(g);
X`09`09`09`7D
X`09`09n`20=`20(g->mvs`5B0`5D.roll`20==`20g->mvs`5B1`5D.roll)`20?`204`20:`202;
X`09`09for`20(i`20=`200;`20i`20<`20n;`20i++)`09`09/*`20search`20for`20an`20unus
Ved`20move`20*/
X`09`09`09if`20(g->mvs`5Bi`5D.pt`20<`200)
X`09`09`09`09break;
X`09`09if`20(i`20>=`20n)`20`7B
X`09`09`09FeMessage("You`20don't`20have`20any`20moves`20left.");
X`09`09`09break;
X`09`09`09`7D
X`09`09n`20=`20(`20(g->mydir`20>`200)`20?`2025`20:`200`20)`20-`20g->mydir*g->mv
Vs`5Bi`5D.roll;
X`09`09while`20(`20(n`20>`200)`20`26`26`20(n`20<`2025)`20`26`26`20(`20(g->board
V`5Bn`5D.qty`20<=`200)`20`7C`7C
X`09`09`20`20`20(g->board`5Bn`5D.color`20!=`20g->mycolor)`20)`20`20)
X`09`09`09n`20+=`20g->mydir;`09`09/*`20search`20for`20occupied`20point`20*/
X`09`09if`20(`20(n`20<`201)`20`7C`7C`20(n`20>`2024)`20)`20`7B
X`09`09`09FeMessage("You`20cannot`20bear`20off`20with`20that`20roll.");
X`09`09`09break;
X`09`09`09`7D
X`09`09g->mvs`5Bi`5D.pt`20=`20n;
X`09`09n`20=`20apply(g,WHO_ME,i,A_REDRAW,`26lastd);
X`09`09if`20(n`20<`200)`20`7B`09/*`20move`20rejected`20*/
X`09`09`09g->mvs`5Bi`5D.pt`20=`20-1;
X`09`09`09FeMessage(rejlcl`5B-n`5D);
X`09`09`09`7D
X`09`09FeDrawMove(g,WHO_ME,i);
X`09`09FeCheckContact(g);
X`09`09break;
X`09case`20'1':
X`09case`20'2':
X`09case`20'3':
X`09case`20'4':
X`09case`20'5':
X`09case`20'6':
X`09`09if`20(g->curbd`20!=`20BD_CUR)`20`7B
X`09`09`09g->curbd`20=`20BD_CUR;
X`09`09`09FeDrawBoard(g->board,NULL,g->mydir,0,
X`09`09`09`09g->flags`20`26`20F_INVERT);
X`09`09`09FeLabelBoard(g);
X`09`09`09`7D
X`09`09c`20-=`20'0';
X`09`09if`20(`20(c`20==`20g->mvs`5B0`5D.roll)`20`26`26`20(c`20==`20g->mvs`5B1
V`5D.roll)`20)`20`7B
X`09`09`09for`20(i`20=`200;`20i`20<`204;`20i++)`09`09/*`20doubles`20*/
X`09`09`09`09if`20(g->mvs`5Bi`5D.pt`20<`200)
X`09`09`09`09`09break;
X`09`09`09if`20(i`20==`204)`20`7B
X`09`09`09`09FeMessage(used);
X`09`09`09`09break;
X`09`09`09`09`7D
X`09`09`09`7D
X`09`09else`20if`20(c`20==`20g->mvs`5B0`5D.roll)`20`7B`09`09/*`20used`201st`20m
Vove`20*/
X`09`09`09if`20(g->mvs`5B0`5D.pt`20>=`200)`20`7B
X`09`09`09`09FeMessage(used);
X`09`09`09`09break;
X`09`09`09`09`7D
X`09`09`09i`20=`200;
X`09`09`09`7D
X`09`09else`20`7B
X`09`09`09if`20(g->mvs`5B0`5D.pt`20<`200)`20`7B`09/*`20used`202nd`20move`201st
V`20*/
X`09`09`09`09tmp`20=`20g->mvs`5B0`5D;`09/*`20swap`20moves`20*/
X`09`09`09`09g->mvs`5B0`5D`20=`20g->mvs`5B1`5D;
X`09`09`09`09g->mvs`5B1`5D`20=`20tmp;
X`09`09`09`09FeDrawMove(g,WHO_ME,0);
X`09`09`09`09FeDrawMove(g,WHO_ME,1);
X`09`09`09`09i`20=`200;
X`09`09`09`09`7D
X`09`09`09else`20if`20(g->mvs`5B1`5D.pt`20>=`200)`20`7B`09/*`20this`20move`20us
Ved?`20*/
X`09`09`09`09FeMessage(used);
X`09`09`09`09break;
X`09`09`09`09`7D
X`09`09`09else
X`09`09`09`09i`20=`201;
X`09`09`09`7D
X`09`09n`20=`20FeGetPoint(g,i,lastpt,lastd);
X`09`09if`20(n`20>=`200)`20`7B
X`09`09`09if`20(n`20>`2025)`20`7B
X`09`09`09`09FeMessage("Invalid`20point`20number");
X`09`09`09`09FeDrawMove(g,WHO_ME,i);
X`09`09`09`09break;
X`09`09`09`09`7D
X`09`09`09g->mvs`5Bi`5D.pt`20=`20n;
X`09`09`09n`20=`20apply(g,WHO_ME,i,A_REDRAW,`26lastd);
X`09`09`09if`20(n`20<`200)`20`7B`09/*`20move`20rejected`20*/
X`09`09`09`09g->mvs`5Bi`5D.pt`20=`20-1;
X`09`09`09`09FeMessage(rejlcl`5B-n`5D);
X`09`09`09`09`7D
X`09`09`09else
X`09`09`09`09lastpt`20=`20g->mvs`5Bi`5D.pt;
X`09`09`09`7D
X`09`09FeDrawMove(g,WHO_ME,i);
X`09`09FeCheckContact(g);
X`09`09break;
X`09default:
X`09`09FeMessage("Invalid`20command.");
X`09`09break;
X`09`09`7D
X`09`7D
X`7D
X
X
X/*----------------------------------------------------------------------
X`20*`09myacpt`20--`20allow`20user`20to`20accept`20or`20decline`20double.
X`20*
X`20*`20This`20function`20allows`20the`20user`20to`20decide`20whether`20he
X`20*`20wants`20to`20accept`20or`20decline`20his`20opponent's`20double.
X`20*`20It`20also`20allows`20the`20user`20to`20cycle`20through`20the`20three
V`20board`20displays,
X`20*`20to`20concede,`20and`20to`20go`20to`20the`20next`20game.
X`20*`20Rolling`20and`20doubling`20are`20not`20allowed`20here.
X`20*----------------------------------------------------------------------
X`20*/
X
Xmyacpt(g)
Xstruct`20game`20*g;
X`7B
Xchar`20c;
Xchar`20pm`20=`20'`5C0';
Xint`20gv;
Xstatic`20char`20*m`5B`5D`20=`20`7B"Accept","Decline","Board","Next`20Game","Qu
Vit",NULL`7D;
X
XFeDrawMenu(m);
XGameState`20=`20STATE_MYACPT;
Xwhile`20(1)`20`7B
X`09c`20=`20FeMenu(m,0,0,"",pm);
X`09pm`20=`20c;
X`09switch`20(c)`20`7B
X`09case`20'A':`09`09`09`09/*`20I`20accepted`20*/
X`09`09if`20(FeGetComment(g)`20<`200)`20`7B`09`09/*`20get`20message`20*/
X`09`09`09FeMessage("Accept`20aborted.");
X`09`09`09break;
X`09`09`09`7D
X`09`09g->gameval`20*=`202;`09`09/*`20the`20game`20value`20is`20doubled`20*/
X`09`09g->state`20=`20ST_OPTURN;`09`09/*`20it's`20opponent's`20turn`20*/
X`09`09sendpkt(g,ACPTDBL);`09`09/*`20send`20accept`20packet`20*/
X`09`09return(0);`09`09`09/*`20done`20w/`20this`20game`20for`20now`20*/
X`09case`20'D':`09`09`09`09/*`20I`20declined`20*/
X`09`09if`20(FeGetComment(g)`20<`200)`20`7B`09`09/*`20get`20message`20*/
X`09`09`09FeMessage("Decline`20aborted.");
X`09`09`09break;
X`09`09`09`7D
X`09`09ilose(g,T_IDECLINE,0);
X`09`09sendpkt(g,DECDBL);`09`09/*`20tell`20the`20opponent`20*/
X`09`09return(1);`09`09`09/*`20call`20gameover()`20*/
X`09case`20'B':`09`09`09`09/*`20display`20different`20board`20*/
X`09`09if`20(g->curbd++`20>=`20BD_CUR)`09/*`20go`20to`20next`20board`20*/
X`09`09`09g->curbd`20=`20BD_BEFOP;`09/*`20wrap`20around`20*/
X`09`09return(1);`09`09/*`20redraw`20`26`20call`20us`20again`20*/
X`09case`20'N':
X`09`09return(0);`09`09/*`20I'm`20done`20with`20this`20game`20for`20now`20*/
X`09case`20'Q':`09`09`09/*`20I`20want`20to`20quit`20ldb`20*/
X`09`09return(-1);
X`09default:
X`09`09FeMessage("Invalid`20command.");
X`09`09break;
X`09`09`7D
X`09`7D
X`7D
X
X
X/*----------------------------------------------------------------------
X`20*`09gameover`20--`20show`20game`20to`20user`20before`20it`20is`20deleted.
X`20*
X`20*`20This`20function`20displays`20a`20game`20that`20has`20just`20terminated.
V
X`20*`20It`20displays`20the`20final`20board,`20the`20reason`20the`20game`20ende
Vd,`20and`20the
X`20*`20number`20of`20points`20won`20or`20lost.`20`20The`20game`20will`20be`20d
Veleted`20by
X`20*`20writegames()`20when`20ldb`20exits.
X`20*----------------------------------------------------------------------
X`20*/
X
Xgameover(g)
Xstruct`20game`20*g;
X`7B
Xchar`20c,`20c1,`20c2;
Xchar`20pm`20=`20'`5C0';
Xint`20i;
Xstatic`20char`20*m`5B`5D`20=`20`7B"Board","Next`20Game","Quit",NULL`7D;
X
Xif`20(g->flags`20`26`20F_DISPLAYED)`09`09/*`20this`20game`20already`20displaye
Vd`20*/
X`09return(0);
XFeDrawMenu(m);
XGameState`20=`20STATE_GAMEOVER;
Xwhile`20(1)`20`7B
X`09c`20=`20FeMenu(m,0,0,"`5Cn`5Cr`20",pm);
X`09pm`20=`20c;
X`09switch`20(c)`20`7B
X`09case`20'B':`09`09`09`09/*`20display`20different`20board`20*/
X`09`09if`20(g->curbd++`20>=`20BD_CUR)`09/*`20go`20to`20next`20board`20*/
X`09`09`09g->curbd`20=`20BD_BEFOP;`09/*`20wrap`20around`20*/
X`09`09return(1);`09`09/*`20redraw`20`26`20call`20us`20again`20*/
X`09case`20'`20':
X`09case`20'`5Cr':
X`09case`20'`5Cn':
X`09`09FeOnMenuItem(m,'N');`09/*`20highlight`20Next`20Game`20item`20*/
X`09`09pm`20=`20'N';`09`09/*`20remember`20to`20unhighlight`20*/
X`09`09/*`20fall`20through`20*/
X`09case`20'N':`09`09`09/*`20delete`20game`20`26`20go`20to`20next`20*/
X`09`09if`20(`20(g->mcurrent`5BWHO_ME`5D`20<`20g->mtotal)`20`26`26
X`09`09`20`20`20`20`20(g->mcurrent`5BWHO_OPP`5D`20<`20g->mtotal)`20)`20`7B
X`09`09`09g->state`20=`20ST_OPSTART;
X`09`09`09if`20(`20(g->term`20==`20T_ILOSE)`20`7C`7C`20(g->term`20==`20T_OPCONC
VEDE)
X`09`09`09`20`20`20`20`20`7C`7C`20(g->term`20==`20T_OPDECLINE)`20)`20`7B
X`09`09`09`09g->gameval`20=`201;`09/*`20reset`20for`20next`20game`20*/
X`09`09`09`09g->adcnt`20=`200;
X`09`09`09`09g->flags`20`26=`20`7EF_IDOUBLED;
X`09`09`09`09g->term`20=`200;
X`09`09`09`09clearmvs(g->mvs);
X`09`09`09`09clearmvs(g->opmvs);
X`09`09`09`09if`20(g->mydir`20>`200)`20`7B
X`09`09`09`09`09c1`20=`20g->mycolor;
X`09`09`09`09`09c2`20=`20g->opcolor;
X`09`09`09`09`09`7D
X`09`09`09`09else`20`7B
X`09`09`09`09`09c1`20=`20g->opcolor;
X`09`09`09`09`09c2`20=`20g->mycolor;
X`09`09`09`09`09`7D
X`09`09`09`09newboard(g->opbd,c1,c2);
X`09`09`09`09newboard(g->mybd,c1,c2);
X`09`09`09`09newboard(g->board,c1,c2);
X`09`09`09`09for`20(i`20=`200;`20i`20<`206;`20i++)`20`7B
X`09`09`09`09`09g->rolls`5Bi`5D`20=`200;
X`09`09`09`09`09g->doubles`5Bi`5D`20=`200;
X`09`09`09`09`09g->oprolls`5Bi`5D`20=`200;
X`09`09`09`09`09g->opdoubles`5Bi`5D`20=`200;
X`09`09`09`09`09`7D
X`09`09`09`09crawford_check(g);
X`09`09`09`09g->mvs`5B0`5D.roll`20=`20Rolldie();
X`09`09`09`09sendpkt(g,MSTART);
X`09`09`09`09`7D
X`09`09`09`7D
X`09`09else`20`7B
X`09`09`09g->flags`20`7C=`20F_DISPLAYED;/*`20done`20looking`20at`20this`20game
V`20*/
X`09`09`09if`20(g->mtotal`20>`200)`20`7B`09/*`20finished`20match`20*/
X`09`09`09`09if`20(g->term`20<=`20T_ILOSE)
X`09`09`09`09`09g->ppl->score`5BSC_MLOST`5D++;
X`09`09`09`09else
X`09`09`09`09`09g->ppl->score`5BSC_MWON`5D++;
X`09`09`09`09`7D
X`09`09`09`7D
X`09`09return(0);`09`09/*`20I'm`20done`20looking`20at`20this`20game`20*/
X`09case`20'Q':`09`09`09/*`20delete`20game`20`26`20quit`20*/
X`09`09return(-1);
X`09default:
X`09`09FeMessage("Invalid`20command.");
X`09`09break;
X`09`09`7D
X`09`7D
X`7D
X
X
Xcheck_concede(g)
Xstruct`20game`20*g;
X`7B
Xint`20gv,`20bg;
Xchar`20*msg;
X
Xg->term`20=`20T_ICONCEDE;
Xbg`20=`20gvalue(g,`26gv);
Xswitch`20(bg)`20`7B
Xcase`201:
X`09msg`20=`20"This`20will`20score`20as`20a`20gammon.`20`20Are`20you`20sure?
V`20`5Byn`5D";
X`09break;
Xcase`202:
X`09msg`20=`20"This`20will`20score`20as`20a`20backgammon.`20`20Are`20you`20sure
V?`20`5Byn`5D";
X`09break;
Xdefault:
X`09msg`20=`20"Are`20you`20sure?`20`5Byn`5D";
X`09break;
X`09`7D
Xreturn(FeYesNo(msg));
X`7D
$ call unpack PROCESS.C;1 796178223 ""
$!
$ create 'f'
X/*`09rcvop.c`09`098/6/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`20which`20make`20up`20the`20re
Vceive`20state
X`20*`20machine.`20`20These`20are`20called`20through`20the`20func`5B`5D`5B`5D
V`20matrix,`20which`20takes
X`20*`20the`20current`20state`20and`20a`20received`20operation`20and`20calls
V`20the`20appropriate
X`20*`20handler`20function.`20`20These`20functions`20will`20typically`20change
V`20the`20game
X`20*`20state`20into`20one`20requiring`20user`20input`20at`20this`20host`20(ST_
VMY*),`20and`20return.
X`20*==========================================================================
V=
X`20*/
X
X
X/*---------------------------------------------------------------------------
X`20*`09start`20--`20initiate`20a`20game
X`20*
X`20*`20This`20function`20is`20called`20when`20a`20remote`20user`20starts`20a
V`20game`20with`20us.
X`20*`20We`20store`20his`20personal`20information`20(opaddr`20`26`20opname),
V`20roll`201`20die,
X`20*`20and`20compare`20it`20to`20the`20one`20he`20sent.`20`20If`20we`20won`20t
Vhe`20roll,`20the`20roll
X`20*`20is`20stored`20in`20mvs`5B`5D`20and`20state`20is`20set`20to`20MYMOVE.
V`20`20If`20we`20lost`20the`20roll,
X`20*`20both`20dice`20are`20sent`20back`20in`20a`20USTART`20line.`20`20If`20the
V`20roll`20was`20a`20tie,
X`20*`20a`20TIE`20packet`20is`20sent`20back`20.`20`20The`20originator`20will
V`20re-roll`20and`20send
X`20*`20us`20a`20RESTART`20packet,`20which`20will`20repeat`20the`20opening`20ro
Vll.
X`20*--------------------------------------------------------------------------
V-
X`20*/
X
Xstart(g)
Xstruct`20game`20*g;
X`7B
Xint`20mydie;
Xchar`20c1,`20c2;
X
Xg->opaddr`20=`20P.addr;`09/*`20save`20mail`20address`20of`20opponent`20*/
Xg->gameid`20=`20P.gameid;`09`09/*`20copy`20game`20id`20*/
Xg->opver`20=`20P.version;`09`09/*`20save`20opponent's`20ldb`20version`20*/
Xg->mycolor`20=`20P.colors`5B1`5D;`09/*`20copy`20out`20colors`20*/
Xg->opcolor`20=`20P.colors`5B0`5D;
Xif`20(isupper(*P.dir))
X`09*P.dir`20=`20tolower(*P.dir);
Xg->mydir`20=`20(*P.dir`20==`20'u')`20?`201`20:`20-1;`09/*`20copy`20out`20direc
Vtions`20*/
Xg->opdir`20=`20REV(g->mydir);
Xg->gameval`20=`201;`09`09`09/*`20no`20doubles`20yet`20*/
Xg->flags`20=`200;
Xg->seq`20=`202;`09`09`09/*`20we`20rcvd`201`20pkt`20already,`20init`20to`202
V`20*/
Xif`20(`20(g->ppl`20=`20findppl(g->opaddr,P_ADDR))`20==`20NULL)`20`7B`20/*`20kn
Vow`20this`20guy?`20*/
X`09g->myaddr`20=`20save(rc.myaddr);`09/*`20nope,`20create`20a`20new`20ppl`20re
Vcord`20*/
X`09newppl(g);
X`09`7D
Xelse
X`09g->myaddr`20=`20save(g->ppl->myaddr);
Xg->starttime`20=`20P.timestamp;`09/*`20store`20timestamp`20from`20start`20pack
Vet`20*/
Xg->lastacc`20=`20P.timestamp;`09/*`20set`20last`20access`20time`20to`20start
V`20time`20*/
Xif`20(P.autodbl`20==`20NULL)`09`09/*`20set`20admax`20to`20MIN(my`20count,`20op
V's`20count)`20*/
X`09g->admax`20=`200;
Xelse
X`09g->admax`20=`20atoi(P.autodbl);
Xif`20(rc.autodouble`20<`20g->admax)
X`09g->admax`20=`20rc.autodouble;
Xg->adcnt`20=`200;`09`09`09/*`20no`20autodoubles`20yet`20*/
Xclearmvs(g->mvs);
Xclearmvs(g->opmvs);
Xif`20(g->mydir`20>`200)`20`7B
X`09c1`20=`20g->mycolor;`09/*`20upbound`20color`20is`20mine`20*/
X`09c2`20=`20g->opcolor;`09/*`20downbound`20color`20is`20opponent's`20*/
X`09`7D
Xelse`20`7B
X`09c1`20=`20g->opcolor;`09/*`20upbound`20color`20is`20opponent's`20*/
X`09c2`20=`20g->mycolor;`09/*`20downbound`20color`20is`20mine`20*/
X`09`7D
Xnewboard(g->opbd,c1,c2);`09`09/*`20set`20up`20boards`20for`20new`20game`20*/
Xnewboard(g->mybd,c1,c2);
Xnewboard(g->board,c1,c2);
Xif`20(P.jacoby`20!=`20NULL)
X`09g->flags`20`7C=`20F_JACOBY;
Xif`20(P.crawford`20!=`20NULL)
X`09g->flags`20`7C=`20F_CRAWFORD;
Xif`20(P.european`20!=`20NULL)
X`09g->flags`20`7C=`20F_EUROPE;
Xif`20(P.perm`20!=`20NULL)
X`09g->flags`20`7C=`20F_PERM;
Xif`20(P.match`20!=`20NULL)
X`09g->mtotal`20=`20atoi(P.match);
Xg->curbd`20=`20boardnums`5B*rc.initboard`20-`20'a'`5D;`09/*`20display`20initia
Vl`20board`20*/
Xmydie`20=`20Rolldie();
Xif`20(P.mvs`5B0`5D.roll`20==`20mydie)`20`7B`09`09/*`20a`20!#$%`26@`20tie`20*/
X`09if`20(g->adcnt`20<`20g->admax)`09/*`20do`20an`20autodouble`20*/
X`09`09g->gameval`20=`201`20<<`20++(g->adcnt);
X`09sendpkt(g,TIE);
X`09message("Tie`20on`20initial`20roll`20with`20%s`20(%s).`5Cn",g->opname,g->op
Vaddr);
X`09return;`09`09`09/*`20opponent`20will`20send`20RESTART`20*/
X`09`7D
Xif`20(mydie`20>`20(int)`20P.mvs`5B0`5D.roll)`20`7B`09`09/*`20we`20won`20the
V`20initial`20roll`20*/
X`09g->mvs`5B0`5D.roll`20=`20P.mvs`5B0`5D.roll;`09/*`20copy`20initial`20roll
V`20*/
X`09g->mvs`5B1`5D.roll`20=`20mydie;
X`09g->mvs`5B0`5D.pt`20=`20-1;`09/*`20mark`20both`20rolls`20unused`20*/
X`09g->mvs`5B1`5D.pt`20=`20-1;
X`09g->state`20=`20ST_MYMOVE;`09/*`20set`20state`20so`20we`20make`20a`20move
V`20*/
X`09legalmoves(g);`09`09/*`20calculate`20legal`20moves`20for`20these`20rolls
V`20*/
X`09g->rolls`5Bg->mvs`5B0`5D.roll`20-`201`5D++;`09/*`20count`20the`20rolls`20we
V`20got`20*/
X`09g->rolls`5Bg->mvs`5B1`5D.roll`20-`201`5D++;
X`09`7D
Xelse`20`7B`09`09`09`09/*`20we`20lost,`20tell`20the`20opponent`20to`20start`20*
V/
X`09g->mvs`5B0`5D.roll`20=`20P.mvs`5B0`5D.roll;`09/*`20copy`20initial`20roll
V`20*/
X`09g->mvs`5B1`5D.roll`20=`20mydie;`09/*`20store`20so`20sendpkt`20can`20find
V`20it`20*/
X`09g->state`20=`20ST_OPTURN;
X`09sendpkt(g,USTART);
X`09message("Started`20game`20with`20%s`20(%s).`5Cn",g->opname,g->opaddr);
X`09`7D
X`7D
X
X
X/*---------------------------------------------------------------------------
X`20*`09istart`20--`20I`20won`20the`20opening`20toss
X`20*
X`20*`20This`20function`20is`20called`20when`20a`20USTART`20packet`20is`20recei
Vved.`20`20Both`20rolls
X`20*`20are`20copied`20into`20the`20game`20structure`20and`20the`20state`20is
V`20set`20to`20MYMOVE,
X`20*`20allowing`20us`20to`20use`20the`20roll`20but`20not`20to`20double.
X`20*--------------------------------------------------------------------------
V-
X`20*/
X
Xistart(g)
Xstruct`20game`20*g;
X`7B
X
Xg->mvs`5B0`5D.roll`20=`20P.mvs`5B0`5D.roll;`09/*`20copy`20rolls`20from`20packe
Vt`20*/
Xg->mvs`5B1`5D.roll`20=`20P.mvs`5B1`5D.roll;
Xg->mvs`5B0`5D.pt`20=`20-1;`09/*`20mark`20both`20rolls`20unused`20*/
Xg->mvs`5B1`5D.pt`20=`20-1;
Xg->state`20=`20ST_MYMOVE;`09/*`20set`20state`20so`20we`20make`20a`20move`20*/
Xlegalmoves(g);`09`09/*`20calculate`20legal`20moves`20*/
Xg->rolls`5Bg->mvs`5B0`5D.roll`20-`201`5D++;`09/*`20count`20the`20rolls`20we
V`20got`20*/
Xg->rolls`5Bg->mvs`5B1`5D.roll`20-`201`5D++;
X`7D
X
X
X/*---------------------------------------------------------------------------
X`20*`09tie`20--`20The`20opening`20toss`20was`20a`20tie,`20try`20again
X`20*
X`20*`20This`20function`20is`20called`20when`20we`20receive`20a`20TIE`20packet.
V`20`20We`20reroll
X`20*`20one`20die`20and`20send`20a`20RESTART`20packet.`20`20If`20the`20autodbl
V`20field`20in
X`20*`20the`20received`20packet`20is`20>`200,`20the`20game`20value`20is`20set
V`20to`202`20**`20autodbl.
X`20*--------------------------------------------------------------------------
V-
X`20*/
X
Xtie(g)
Xstruct`20game`20*g;
X`7B
X
Xclearmvs(g->mvs);
Xg->mvs`5B0`5D.roll`20=`20Rolldie();
Xif`20(P.autodbl`20!=`20NULL)
X`09g->gameval`20=`201`20<<`20(g->adcnt`20=`20atoi(P.autodbl));
Xsendpkt(g,RESTART);
Xmessage("Tie`20on`20initial`20roll`20with`20%s`20(%s).`5Cn",g->opname,g->opadd
Vr);
X`7D
X
X
X/*---------------------------------------------------------------------------
X`20*`09restart`20--`20restart`20after`20opening`20tie
X`20*
X`20*`20This`20function`20is`20called`20when`20we`20receive`20a`20RESTART`20pac
Vket.`20`20It`20is
X`20*`20mostly`20the`20same`20as`20start().
X`20*--------------------------------------------------------------------------
V-
X`20*/
X
Xrestart(g)
Xstruct`20game`20*g;
X`7B
Xint`20mydie;
X
Xclearmvs(g->mvs);
Xclearmvs(g->opmvs);
Xmydie`20=`20Rolldie();
Xif`20(P.mvs`5B0`5D.roll`20==`20mydie)`20`7B`09`09/*`20a`20!#$%`26@`20tie`20*/
X`09if`20(g->adcnt`20<`20g->admax)`09/*`20do`20an`20autodouble`20*/
X`09`09g->gameval`20=`201`20<<`20++(g->adcnt);
X`09sendpkt(g,TIE);
X`09message("Tie`20on`20initial`20roll`20with`20%s`20(%s).`5Cn",g->opname,g->op
Vaddr);
X`09return;`09`09`09/*`20opponent`20will`20send`20RESTART`20*/
X`09`7D
Xg->mvs`5B0`5D.roll`20=`20P.mvs`5B0`5D.roll;`09/*`20copy`20initial`20roll`20*/
Xg->mvs`5B1`5D.roll`20=`20mydie;`09/*`20store`20so`20sendpkt`20can`20find`20it
V`20*/
Xif`20(mydie`20>`20(int)`20P.mvs`5B0`5D.roll)`20`7B`09`09/*`20we`20won`20the
V`20initial`20roll`20*/
X`09g->state`20=`20ST_MYMOVE;`09/*`20set`20state`20so`20we`20make`20a`20move
V`20*/
X`09legalmoves(g);`09`09/*`20calculate`20legal`20moves`20for`20these`20rolls
V`20*/
X`09g->rolls`5Bg->mvs`5B0`5D.roll`20-`201`5D++;`09/*`20count`20the`20rolls`20we
V`20got`20*/
X`09g->rolls`5Bg->mvs`5B1`5D.roll`20-`201`5D++;
X`09`7D
Xelse`20`7B`09`09`09`09/*`20we`20lost,`20tell`20the`20opponent`20to`20start`20*
V/
X`09g->state`20=`20ST_OPTURN;
X`09sendpkt(g,USTART);
X`09message("Started`20game`20with`20%s`20(%s).`5Cn",g->opname,g->opaddr);
X`09`7D
X`7D
X
X
X/*---------------------------------------------------------------------------
X`20*`09mstart`20--`20start`20next`20game`20of`20match
X`20*
X`20*`20This`20function`20is`20called`20when`20we`20receive`20an`20MSTART`20pac
Vket.`20`20It`20is
X`20*`20similar`20to`20restart,`20except`20that`20it`20also`20reinitializes`20t
Vhe`20game
X`20*`20structure`20for`20the`20next`20game`20of`20the`20match.`20`20All`20game
Vs`20of`20a`20match
X`20*`20use`20the`20same`20gameid`20and`20game`20structure.`20`20Mstart`20also
V`20checks`20to
X`20*`20see`20if`20this`20is`20a`20Crawford`20rule`20game,`20and`20if`20so,`20s
Vets`20F_CRGAME`20in`20g->flags.
X`20*--------------------------------------------------------------------------
V-
X`20*/
X
Xmstart(g)
Xstruct`20game`20*g;
X`7B
Xint`20mydie;
Xint`20i;
Xchar`20c1,`20c2;
X
Xg->state`20=`20ST_OPSTART;
Xg->gameval`20=`201;`09`09/*`20reset`20for`20next`20game`20*/
Xg->adcnt`20=`200;
Xg->flags`20`26=`20`7EF_IDOUBLED;
Xg->term`20=`200;
Xif`20(g->mydir`20>`200)`20`7B
X`09c1`20=`20g->mycolor;`09/*`20upbound`20color`20is`20mine`20*/
X`09c2`20=`20g->opcolor;`09/*`20downbound`20color`20is`20opponent's`20*/
X`09`7D
Xelse`20`7B
X`09c1`20=`20g->opcolor;`09/*`20upbound`20color`20is`20opponent's`20*/
X`09c2`20=`20g->mycolor;`09/*`20downbound`20color`20is`20mine`20*/
X`09`7D
Xnewboard(g->opbd,c1,c2);
Xnewboard(g->mybd,c1,c2);
Xnewboard(g->board,c1,c2);
Xfor`20(i`20=`200;`20i`20<`206;`20i++)`20`7B
X`09g->rolls`5Bi`5D`20=`200;
X`09g->doubles`5Bi`5D`20=`200;
X`09g->oprolls`5Bi`5D`20=`200;
X`09g->opdoubles`5Bi`5D`20=`200;
X`09`7D
Xclearmvs(g->mvs);
Xclearmvs(g->opmvs);
Xcrawford_check(g);`09`09`09/*`20is`20this`20the`20Crawford`20rule`20game?`20*/
V
Xmydie`20=`20Rolldie();
Xif`20(P.mvs`5B0`5D.roll`20==`20mydie)`20`7B`09`09/*`20a`20!#$%`26@`20tie`20*/
X`09if`20(g->adcnt`20<`20g->admax)`09/*`20do`20an`20autodouble`20*/
X`09`09g->gameval`20=`201`20<<`20++(g->adcnt);
X`09sendpkt(g,TIE);
X`09message("Tie`20on`20initial`20roll`20with`20%s`20(%s).`5Cn",g->opname,g->op
Vaddr);
X`09return;`09`09`09/*`20opponent`20will`20send`20RESTART`20*/
X`09`7D
Xg->mvs`5B0`5D.roll`20=`20P.mvs`5B0`5D.roll;`09/*`20copy`20initial`20roll`20*/
Xg->mvs`5B1`5D.roll`20=`20mydie;`09/*`20store`20so`20sendpkt`20can`20find`20it
V`20*/
Xif`20(mydie`20>`20(int)`20P.mvs`5B0`5D.roll)`20`7B`09`09/*`20we`20won`20the
V`20initial`20roll`20*/
X`09g->state`20=`20ST_MYMOVE;`09/*`20set`20state`20so`20we`20make`20a`20move
V`20*/
X`09legalmoves(g);`09`09/*`20calculate`20legal`20moves`20for`20these`20rolls
V`20*/
X`09g->rolls`5Bg->mvs`5B0`5D.roll`20-`201`5D++;`09/*`20count`20the`20rolls`20we
V`20got`20*/
X`09g->rolls`5Bg->mvs`5B1`5D.roll`20-`201`5D++;
X`09`7D
Xelse`20`7B`09`09`09`09/*`20we`20lost,`20tell`20the`20opponent`20to`20start`20*
V/
X`09g->state`20=`20ST_OPTURN;
X`09sendpkt(g,USTART);
X`09message("Started`20game`20with`20%s`20(%s).`5Cn",g->opname,g->opaddr);
X`09`7D
X`7D
X
X
X/*---------------------------------------------------------------------------
X`20*`09opmove`20--`20opponent`20moved
X`20*
X`20*`20This`20function`20is`20called`20when`20we`20receive`20a`20MOVE`20packet
V.`20`20The`20move`20is
X`20*`20copied`20into`20the`20opmvs`20field`20of`20the`20game`20structure`20and
V`20applied`20to`20the
X`20*`20board.`20`20A`20copy`20of`20the`20board`20before`20the`20moves`20are
V`20applied`20is`20stored
X`20*`20in`20the`20opbd`20field,`20and`20a`20copy`20of`20the`20board`20after
V`20the`20moves`20are`20applied
X`20*`20is`20stored`20in`20the`20mybd`20field.`20`20These`20two`20boards,`20alo
Vng`20with`20the
X`20*`20current`20board`20in`20the`20board`20field,`20make`20up`20the`20three
V`20boards`20that`20can
X`20*`20be`20displayed`20with`20the`20"Board"`20command`20in`20the`20user`20men
Vus`20in`20process.c
X`20*--------------------------------------------------------------------------
V-
X`20*/
X
Xopmove(g)
Xstruct`20game`20*g;
X`7B
Xint`20i,`20n,`20r;
Xstatic`20char`20buf`5B`5D`20=`20"Opponent`20move`20dated`20DDD`20MMM`20NN`20HH
V:MM:SS`20YYYY";
Xstruct`20game`20*pg;
X
Xcopyboard(g->board,g->opbd);`09/*`20save`20board`20before`20opponent`20moved
V`20*/
Xg->curbd`20=`20boardnums`5B*rc.initboard`20-`20'a'`5D;`09/*`20display`20initia
Vl`20board`20*/
Xclearmvs(g->opmvs);`09`09/*`20clear`20old`20moves`20*/
Xg->opmvs`5B0`5D`20=`20P.mvs`5B0`5D;`09/*`20extract`20opponent's`20moves`20*/
Xg->opmvs`5B1`5D`20=`20P.mvs`5B1`5D;
Xg->oprolls`5Bg->opmvs`5B0`5D.roll`20-`201`5D++;`09`09/*`20count`20rolls`20oppo
Vnent`20got`20*/
Xg->oprolls`5Bg->opmvs`5B1`5D.roll`20-`201`5D++;
Xif`20(g->opmvs`5B0`5D.roll`20==`20g->opmvs`5B1`5D.roll)`20`7B
X`09g->opmvs`5B2`5D`20=`20P.mvs`5B2`5D;`09/*`20he`20got`20doubles`20*/
X`09g->opmvs`5B3`5D`20=`20P.mvs`5B3`5D;`09/*`20extract`202`20more`20moves`20*/
X`09g->opdoubles`5Bg->opmvs`5B0`5D.roll`20-`201`5D++;
X`09n`20=`204;
X`09`7D
Xelse
X`09n`20=`202;
Xfor`20(i`20=`200;`20i`20<`204;`20i++)
X`09g->blot`5Bi`5D`20=`200;`09`09/*`20clear`20all`20blot`20locations`20*/
Xfor`20(i`20=`200;`20i`20<`20n;`20i++)`20`7B
X`09if`20(`20(r`20=`20apply(g,WHO_OPP,i,0,NULL))`20<`200)`20`7B`09/*`20err`20w/
V`20op`20move`20*/
X`09`09copyboard(g->opbd,g->board);`09/*`20restore`20board`20*/
X`09`09message("ERROR:`20Opponent`20move`20rejected,`20id=%s`5Cn",
X`09`09`09P.gameid);
X`09`09message("`20`20`20`20`20`20`20%s`5Cn",rejmsg`5B-r`5D);
X`09`09return;
X`09`09`7D
X`09else`09`09/*`20if`20opponent`20hit`20our`20blot`20*/
X`09`09g->blot`5Bi`5D`20=`20r;`09`09/*`20save`20location`20*/
X`09`7D
Xcopyboard(g->board,g->mybd);`09`09/*`20save`20board`20after`20op`20move`20*/
Xif`20(g->board`5BOFFPT(g->opdir)`5D.qty`20==`2015)`09/*`20opponent`20won`20*/
X`09ilose(g,T_ILOSE,1);
Xelse
X`09g->state`20=`20ST_MYTURN;`09`09/*`20opponent`20has`20moved,`20it's`20our
V`20turn`20*/
Xclearmvs(g->mvs);`09`09/*`20erase`20our`20previous`20move`20*/
Xif`20(P.timestamp`20>`200)`20`7B`09`09/*`20if`20we`20got`20a`20timestamp`20*/
X`09strncpy(`26buf`5B20`5D,ctime(`26P.timestamp),24);`09/*`20gen`20message`20*/
V
X`09g->dispmsg`20=`20save(buf);`09`09/*`20save`20copy`20in`20game`20*/
X`09`7D
X`7D
X
X
X/*---------------------------------------------------------------------------
X`20*`09opofr`20--`20opponent`20offered`20to`20double
X`20*
X`20*`20This`20function`20is`20called`20when`20we`20receive`20an`20OFRDBL`20pac
Vket,`20indicating
X`20*`20the`20opponent`20wishes`20to`20double.`20`20The`20game`20moves`20to`20s
Vtate`20MYACCEPT,
X`20*`20where`20the`20user`20will`20decide`20to`20accept`20or`20decline`20the
V`20double.
X`20*--------------------------------------------------------------------------
V-
X`20*/
X
Xopofr(g)
Xstruct`20game`20*g;
X`7B
X
Xif`20(g->flags`20`26`20F_CRGAME)`20`7B
X`09message("ERROR:`20Opponent`20move`20rejected,`20id=%s`5Cn",P.gameid);
X`09message("`20`20`20`20`20`20`20Invalid`20double`20(Crawford`20rule)`5Cn");
X`09return;
X`09`7D
Xg->state`20=`20ST_MYACCEPT;`09`09`09/*`20send`20us`20to`20an`20accept`20screen
V`20*/
Xg->flags`20`26=`20`7EF_IDOUBLED;`09`09/*`20I`20didn't`20double`20last`20*/
Xcopyboard(g->board,g->opbd);
Xcopyboard(g->board,g->mybd);
Xg->curbd`20=`20BD_CUR;`09`09/*`20display`20current`20board`20*/
Xclearmvs(g->opmvs);`09`09/*`20clear`20old`20moves`20*/
Xclearmvs(g->mvs);`09`09/*`20erase`20our`20previous`20move`20*/
X`7D
X
X
X/*---------------------------------------------------------------------------
X`20*`09opconc`20--`20opponent`20conceded
X`20*
X`20*`20This`20function`20is`20called`20when`20we`20receive`20a`20CONCEDE`20pac
Vket,`20indicating
X`20*`20the`20opponent`20has`20given`20up.
X`20*--------------------------------------------------------------------------
V-
X`20*/
X
Xopconc(g)
Xstruct`20game`20*g;
X`7B
Xint`20gv;
X
Xiwin(g,T_OPCONCEDE,1);`09`09`09/*`20wimp`20*/
X`7D
X
X
X/*---------------------------------------------------------------------------
X`20*`09opacpt`20--`20opponent`20accepted`20double
X`20*
X`20*`20This`20function`20is`20called`20when`20we`20receive`20an`20ACPTDBL`20pa
Vcket,`20indicating
X`20*`20the`20opponent`20has`20accepted`20our`20double.`20`20The`20IDOUBLED`20f
Vlag`20is`20set`20to
X`20*`20prevent`20us`20from`20doubling`20again`20until`20the`20opponent`20doubl
Ves.`20`20Since`20it
X`20*`20is`20now`20our`20turn,`20we`20go`20ahead`20and`20roll`20the`20dice`20an
Vd`20proceed`20to`20the
X`20*`20MYMOVE`20state.
X`20*--------------------------------------------------------------------------
V-
X`20*/
X
Xopacpt(g)
Xstruct`20game`20*g;
X`7B
X
Xg->gameval`20*=`202;`09`09/*`20double`20game`20value`20*/
Xg->flags`20`7C=`20F_IDOUBLED;`09`09/*`20I`20doubled`20last`20*/
Xg->state`20=`20ST_MYMOVE;`09`09/*`20It`20is`20my`20move`20*/
Xcopyboard(g->board,g->opbd);
Xcopyboard(g->board,g->mybd);
Xg->curbd`20=`20BD_CUR;`09`09/*`20display`20current`20board`20*/
Xclearmvs(g->opmvs);`09`09/*`20clear`20old`20moves`20*/
Xclearmvs(g->mvs);`09`09/*`20erase`20our`20previous`20move`20*/
Xrolldice(g);`09`09`09/*`20go`20ahead`20and`20roll,`20I`20can't`20double`20*/
Xg->dispmsg`20=`20save("Opponent`20has`20accepted`20your`20double.");/*`20notif
Vy`20user`20*/
X`7D
X
X
X/*---------------------------------------------------------------------------
X`20*`09opdec`20--`20opponent`20declined`20double
X`20*
X`20*`20This`20function`20is`20called`20when`20a`20DECDBL`20packet`20is`20recei
Vved.`20`20This
X`20*`20indicates`20that`20the`20opponent`20has`20declined`20our`20double,`20an
Vd`20the`20game`20is`20over.
X`20*--------------------------------------------------------------------------
V-
X`20*/
X
Xopdec(g)
Xstruct`20game`20*g;
X`7B
Xint`20gv;
X
Xiwin(g,T_OPDECLINE,1);
Xcopyboard(g->board,g->opbd);
Xcopyboard(g->board,g->mybd);
Xg->curbd`20=`20BD_CUR;`09`09/*`20display`20current`20board`20*/
Xclearmvs(g->opmvs);`09`09/*`20clear`20old`20moves`20*/
Xclearmvs(g->mvs);`09`09/*`20erase`20our`20previous`20move`20*/
X`7D
X
X
X/*---------------------------------------------------------------------------
X`20*`09smerr`20--`20an`20illegal`20operation`20was`20received`20for`20this`20s
Vtate
X`20*
X`20*`20This`20function`20is`20called`20when`20a`20packet`20is`20received`20tha
Vt`20is`20invalid
X`20*`20for`20the`20game`20state.`20`20An`20example`20of`20this`20would`20be
V`20receiving`20an
X`20*`20ACPTDBL`20packet`20when`20we`20did`20not`20send`20an`20OFRDBL.
X`20*--------------------------------------------------------------------------
V-
X`20*/
X
Xsmerr(g)
Xstruct`20game`20*g;
X`7B
X
Xmessage("ERROR:`20invalid`20operation`20(%d)`20for`20state`20(%d),`20id=%s`5Cn
V",
X`09P.opcode,`20g->state,`20g->gameid);
X`7D
$ call unpack RCVOP.C;1 861626388 ""
$!
$ create 'f'
X/*`09readmail.c`09`098/7/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*`09readmail`20--`20read`20the`20incoming`20mail`20and`20process`20it
X`20*
X`20*`20This`20function`20extracts`20each`20packet`20from`20the`20mail`20file
V`20and`20applies`20it
X`20*`20to`20the`20appropriate`20game`20structure.`20`20Most`20packets`20are
V`20processed`20by
X`20*`20calling`20the`20handler`20found`20in`20the`20func`20array,`20which`20is
V`20a`202-dimensional
X`20*`20array`20indexed`20by`20the`20current`20game`20state`20and`20the`20recei
Vved`20opcode.
X`20*`20The`20handlers`20are`20responsible`20for`20transforming`20the`20game
V`20state`20as
X`20*`20necessary.`20`20The`20START`20and`20RSTART`20opcodes`20receive`20specia
Vl`20processing,
X`20*`20since`20they`20apply`20to`20games`20that`20do`20not`20exist`20and`20thu
Vs`20have`20no`20state.
X`20*`20START`20packets`20result`20in`20the`20creation`20of`20a`20game,`20whose
V`20state`20is`20set
X`20*`20such`20that`20the`20correct`20handler`20will`20be`20called.`20`20The
V`20RSTART`20opcode
X`20*`20is`20processed`20in`20the`20same`20way`20as`20the`20-start`20command
V`20line`20argument;
X`20*`20the`20packet`20is`20then`20discarded.
X`20*
+-+-+-+-+-+-+-+- END OF PART 12 +-+-+-+-+-+-+-+-