Annotation of 42BSD/games/backgammon/table.c, revision 1.1

1.1     ! root        1: static char sccsid[] = "       table.c 4.1     82/05/11        ";
        !             2: 
        !             3: #include "back.h"
        !             4: 
        !             5: char   *help2[] = {
        !             6:        "   Enter moves as <s>-<f> or <s>/<r> where <s> is the starting",
        !             7:        "position, <f> is the finishing position, and <r> is the roll.",
        !             8:        "Remember, each die roll must be moved separately.",
        !             9:        0
        !            10: };
        !            11: 
        !            12: struct state   {
        !            13:        char    ch;
        !            14:        int     fcode;
        !            15:        int     newst;
        !            16: };
        !            17: 
        !            18: struct state   atmata[] = {
        !            19: 
        !            20:        'R', 1, 0,      '?', 7, 0,      'Q', 0, -3,     'B', 8, 25,
        !            21:        '9', 2, 25,     '8', 2, 25,     '7', 2, 25,     '6', 2, 25,
        !            22:        '5', 2, 25,     '4', 2, 25,     '3', 2, 25,     '2', 2, 19,
        !            23:        '1', 2, 15,     '0', 2, 25,     '.', 0, 0,      '9', 2, 25,
        !            24:        '8', 2, 25,     '7', 2, 25,     '6', 2, 25,     '5', 2, 25,
        !            25: 
        !            26:        '4', 2, 25,     '3', 2, 25,     '2', 2, 25,     '1', 2, 25,
        !            27:        '0', 2, 25,     '/', 0, 32,     '-', 0, 39,     '.', 0, 0,
        !            28:        '/', 5, 32,     ' ', 6, 3,      ',', 6, 3,      '\n', 0, -1,
        !            29:        '6', 3, 28,     '5', 3, 28,     '4', 3, 28,     '3', 3, 28,
        !            30:        '2', 3, 28,     '1', 3, 28,     '.', 0, 0,      'H', 9, 61,
        !            31: 
        !            32:        '9', 4, 61,     '8', 4, 61,     '7', 4, 61,     '6', 4, 61,
        !            33:        '5', 4, 61,     '4', 4, 61,     '3', 4, 61,     '2', 4, 53,
        !            34:        '1', 4, 51,     '0', 4, 61,     '.', 0, 0,      '9', 4, 61,
        !            35:        '8', 4, 61,     '7', 4, 61,     '6', 4, 61,     '5', 4, 61,
        !            36:        '4', 4, 61,     '3', 4, 61,     '2', 4, 61,     '1', 4, 61,
        !            37: 
        !            38:        '0', 4, 61,     ' ', 6, 3,      ',', 6, 3,      '-', 5, 39,
        !            39:        '\n', 0, -1,    '.', 0, 0
        !            40: };
        !            41: 
        !            42: checkmove (ist)
        !            43: 
        !            44: int    ist;
        !            45: 
        !            46: {
        !            47:        register int    j, n;
        !            48:        register char   c;
        !            49:        char            a;
        !            50: 
        !            51: domove:
        !            52:        if (ist == 0)  {
        !            53:                if (tflag)
        !            54:                        curmove (curr,32);
        !            55:                else
        !            56:                        writel ("\t\t");
        !            57:                writel ("Move:  ");
        !            58:        }
        !            59:        ist = mvl = ncin = 0;
        !            60:        for (j = 0; j < 5; j++)
        !            61:                p[j] = g[j] = -1;
        !            62: 
        !            63: dochar:
        !            64:        c = readc();
        !            65: 
        !            66:        if (c == 'S')  {
        !            67:                raflag = 0;
        !            68:                save (1);
        !            69:                if (tflag)  {
        !            70:                        curmove (cturn == -1? 18: 19,39);
        !            71:                        ist = -1;
        !            72:                        goto domove;
        !            73:                } else  {
        !            74:                        proll ();
        !            75:                        ist = 0;
        !            76:                        goto domove;
        !            77:                }
        !            78:        }
        !            79: 
        !            80:        if (c == tty.sg_erase && ncin > 0)  {
        !            81:                if (tflag)
        !            82:                        curmove (curr,curc-1);
        !            83:                else  {
        !            84:                        if (tty.sg_erase == '\010')
        !            85:                                writel ("\010 \010");
        !            86:                        else
        !            87:                                writec (cin[ncin-1]);
        !            88:                }
        !            89:                ncin--;
        !            90:                n = rsetbrd();
        !            91:                if (n == 0)  {
        !            92:                        n = -1;
        !            93:                        if (tflag)
        !            94:                                refresh();
        !            95:                }
        !            96:                if ((ist = n) > 0)
        !            97:                        goto dochar;
        !            98:                goto domove;
        !            99:        }
        !           100: 
        !           101:        if (c == tty.sg_kill && ncin > 0)  {
        !           102:                if (tflag)  {
        !           103:                        refresh();
        !           104:                        curmove (curr,39);
        !           105:                        ist = -1;
        !           106:                        goto domove;
        !           107:                } else  if (tty.sg_erase == '\010')  {
        !           108:                        for (j = 0; j < ncin; j++)
        !           109:                                writel ("\010 \010");
        !           110:                        ist = -1;
        !           111:                        goto domove;
        !           112:                } else  {
        !           113:                        writec ('\\');
        !           114:                        writec ('\n');
        !           115:                        proll ();
        !           116:                        ist = 0;
        !           117:                        goto domove;
        !           118:                }
        !           119:        }
        !           120: 
        !           121:        n = dotable(c,ist);
        !           122:        if (n >= 0)  {
        !           123:                cin[ncin++] = c;
        !           124:                if (n > 2)
        !           125:                if ((! tflag) || c != '\n')
        !           126:                        writec (c);
        !           127:                ist = n;
        !           128:                if (n)
        !           129:                        goto dochar;
        !           130:                else
        !           131:                        goto domove;
        !           132:        }
        !           133: 
        !           134:        if (n == -1 && mvl >= mvlim)
        !           135:                return(0);
        !           136:        if (n == -1 && mvl < mvlim-1)
        !           137:                return(-4);
        !           138: 
        !           139:        if (n == -6)  {
        !           140:                if (! tflag)  {
        !           141:                        if (movokay(mvl+1))  {
        !           142:                                wrboard();
        !           143:                                movback (mvl+1);
        !           144:                        }
        !           145:                        proll ();
        !           146:                        writel ("\t\tMove:  ");
        !           147:                        for (j = 0; j < ncin;)
        !           148:                                writec (cin[j++]);
        !           149:                } else  {
        !           150:                        if (movokay(mvl+1))  {
        !           151:                                refresh();
        !           152:                                movback (mvl+1);
        !           153:                        } else
        !           154:                                curmove (cturn == -1? 18:19,ncin+39);
        !           155:                }
        !           156:                ist = n = rsetbrd();
        !           157:                goto dochar;
        !           158:        }
        !           159: 
        !           160:        if (n != -5)
        !           161:                return(n);
        !           162:        writec ('\007');
        !           163:        goto dochar;
        !           164: }
        !           165: 
        !           166: dotable (c,i)
        !           167: char           c;
        !           168: register int   i;
        !           169: 
        !           170: {
        !           171:        register int    a, j;
        !           172:        int             test;
        !           173: 
        !           174:        test = (c == 'R');
        !           175: 
        !           176:        while ( (a = atmata[i].ch) != '.')  {
        !           177:                if (a == c || (test && a == '\n'))  {
        !           178:                        switch  (atmata[i].fcode)  {
        !           179: 
        !           180:                        case 1:
        !           181:                                wrboard();
        !           182:                                if (tflag)  {
        !           183:                                        curmove (cturn == -1? 18: 19,0);
        !           184:                                        proll ();
        !           185:                                        writel ("\t\t");
        !           186:                                } else
        !           187:                                        proll ();
        !           188:                                break;
        !           189: 
        !           190:                        case 2:
        !           191:                                if (p[mvl] == -1)
        !           192:                                        p[mvl] = c-'0';
        !           193:                                else
        !           194:                                        p[mvl] = p[mvl]*10+c-'0';
        !           195:                                break;
        !           196: 
        !           197:                        case 3:
        !           198:                                if (g[mvl] != -1)  {
        !           199:                                        if (mvl < mvlim)
        !           200:                                                mvl++;
        !           201:                                        p[mvl] = p[mvl-1];
        !           202:                                }
        !           203:                                g[mvl] = p[mvl]+cturn*(c-'0');
        !           204:                                if (g[mvl] < 0)
        !           205:                                        g[mvl] = 0;
        !           206:                                if (g[mvl] > 25)
        !           207:                                        g[mvl] = 25;
        !           208:                                break;
        !           209: 
        !           210:                        case 4:
        !           211:                                if (g[mvl] == -1)
        !           212:                                        g[mvl] = c-'0';
        !           213:                                else
        !           214:                                        g[mvl] = g[mvl]*10+c-'0';
        !           215:                                break;
        !           216: 
        !           217:                        case 5:
        !           218:                                if (mvl < mvlim)
        !           219:                                        mvl++;
        !           220:                                p[mvl] = g[mvl-1];
        !           221:                                break;
        !           222: 
        !           223:                        case 6:
        !           224:                                if (mvl < mvlim)
        !           225:                                        mvl++;
        !           226:                                break;
        !           227: 
        !           228:                        case 7:
        !           229:                                if (tflag)
        !           230:                                        curmove (20,0);
        !           231:                                else
        !           232:                                        writec ('\n');
        !           233:                                text (help2);
        !           234:                                if (tflag)  {
        !           235:                                        curmove (cturn == -1? 18: 19,39);
        !           236:                                } else  {
        !           237:                                        writec ('\n');
        !           238:                                        proll();
        !           239:                                        writel ("\t\tMove:  ");
        !           240:                                }
        !           241:                                break;
        !           242: 
        !           243:                        case 8:
        !           244:                                p[mvl] = bar;
        !           245:                                break;
        !           246: 
        !           247:                        case 9:
        !           248:                                g[mvl] = home;
        !           249:                        }
        !           250: 
        !           251:                        if (! test || a != '\n')
        !           252:                                return (atmata[i].newst);
        !           253:                        else
        !           254:                                return (-6);
        !           255:                }
        !           256: 
        !           257:                i++;
        !           258:        }
        !           259: 
        !           260:        return (-5);
        !           261: }
        !           262: 
        !           263: rsetbrd ()  {
        !           264:        register int    i, j, n;
        !           265: 
        !           266:        n = 0;
        !           267:        mvl = 0;
        !           268:        for (i = 0; i < 4; i++)
        !           269:                p[i] = g[i] = -1;
        !           270:        for (j = 0; j < ncin; j++)
        !           271:                n = dotable (cin[j],n);
        !           272:        return (n);
        !           273: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.