Annotation of researchv10no/games/trek/new.c, revision 1.1

1.1     ! root        1: # include "trek.h"
        !             2: 
        !             3: # define       LOGFILE "/usr/src/games/trek/log"
        !             4: 
        !             5: /**
        !             6:  **    write out log
        !             7:  **/
        !             8: 
        !             9: extern long    score();
        !            10: extern float atof();
        !            11: CVNTAB Lentab[]
        !            12: {
        !            13:        "s",            "hort",
        !            14:        "m",            "edium",
        !            15:        "i",            "ntermediate",
        !            16:        "l",            "ong",
        !            17:        0
        !            18: };
        !            19: 
        !            20: CVNTAB Skitab[]
        !            21: {
        !            22:        "n",            "ovice",
        !            23:        "f",            "air",
        !            24:        "g",            "ood",
        !            25:        "e",            "xpert",
        !            26:        "c",            "ommodore",
        !            27:        "i",            "mpossible",
        !            28:        0
        !            29: };
        !            30: 
        !            31: 
        !            32: char *reason[] {
        !            33:        "win......",
        !            34:        "cheating.",
        !            35:        "destruct.",
        !            36:        "burned...",
        !            37:        "too fast.",
        !            38:        "no help..",
        !            39:        "suffocate",
        !            40:        "supernova",
        !            41:        "nova.....",
        !            42:        "barrier..",
        !            43:        "destroyed",
        !            44:        "energy...",
        !            45:        "time.....",
        !            46:        "captured.",
        !            47:        "no crew..",
        !            48: };
        !            49: 
        !            50: char b[200];
        !            51: char *a[20];
        !            52: float days;
        !            53: 
        !            54: main()
        !            55: {
        !            56:        int winlose;
        !            57:        int k1, k2;
        !            58:        long s;
        !            59: 
        !            60:        while(getlin()) {
        !            61:                Game.skill=index(*a[4],"nfgeci");
        !            62:                Game.length=index(*a[5],"smil");
        !            63:                days=atof(a[6]);
        !            64:                Status.ship=last(a[6]);
        !            65:                sscanf(a[7],"%d/%d",&k1,&k2);
        !            66:                Game.gkillk = k1;
        !            67:                Status.kling = k2-k1;
        !            68:                Game.helps=atoi(a[8]);
        !            69:                Game.killb=atoi(a[9]);
        !            70:                Game.kills=atoi(a[10]);
        !            71:                Game.killinhab=atoi(a[11]);
        !            72:                Game.deaths=atoi(a[12]);
        !            73:                winlose=lookup(a[3]);
        !            74:                Move.endgame=0; Game.killed=0;
        !            75:                if(winlose==0)
        !            76:                        Move.endgame++;
        !            77:                else if(winlose<12)
        !            78:                        Game.killed++;
        !            79: 
        !            80:                s=score();
        !            81:                printf("%s\t%s\t%D\t%s\t%s\t%s\t%.2f%c\t%d/%d\t%d\t%d\t%d\t%d\t%d\n",
        !            82:                        a[0],
        !            83:                        a[1],
        !            84:                        s,
        !            85:                        a[3],
        !            86:                        (Skitab[Game.skill-1].abrev),
        !            87:                        (Lentab[Game.length-1].abrev),
        !            88:                        days,
        !            89:                        Status.ship,
        !            90:                        Game.gkillk, Game.gkillk+Status.kling,
        !            91:                        Game.helps,
        !            92:                        Game.killb,
        !            93:                        Game.kills,
        !            94:                        Game.killinhab,
        !            95:                        Game.deaths
        !            96:                        );
        !            97:        }
        !            98: }
        !            99: 
        !           100: long score()
        !           101: {
        !           102:        register int            u;
        !           103:        long                    s, t;   /* should really be long */
        !           104:        double                  r;
        !           105: 
        !           106:        Initial.kling=Game.skill*Game.length*5;
        !           107:        u = Initial.kling*1.05+5;
        !           108:        if(u>Game.gkillk) u=Game.gkillk;
        !           109:        Param.klingpwr=100+150*Game.skill+(Game.skill>=6?150:0);
        !           110:        s = t = Param.klingpwr / 4 * u;;
        !           111:        r = days;
        !           112:        if (r < 1.0)
        !           113:                r = 1.0;
        !           114:        r = u / r;
        !           115:        s =+ (t = 400 * r);
        !           116:        r = Status.kling;
        !           117:        r =/ u + 1;
        !           118:        s =+ (t = -1000 * r);
        !           119:        if (Move.endgame > 0)
        !           120:        {
        !           121:                s =+ (t = 100 * (u = Game.skill));
        !           122:        }
        !           123:        if (Game.killed)
        !           124:        {
        !           125:                s =- 200;
        !           126:        }
        !           127:        s =+ (t = -100 * (u = Game.killb));
        !           128:        s =+ (t = -100 * (u = Game.helps));
        !           129:        s =+ (t = -20 * (u = Game.kills));
        !           130:        s =+ (t = -150 * (u = Game.killinhab));
        !           131:        if (Status.ship != ENTERPRISE)
        !           132:        {
        !           133:                s =- 200;
        !           134:        }
        !           135:        s =+ (t = 3 * (u = Game.captives));
        !           136:        s =+ (t = -(u = Game.deaths));
        !           137:        return (s);
        !           138: }
        !           139: 
        !           140: getlin()
        !           141: {
        !           142:        register char *bp=b, **ap=a, *ip=b;
        !           143:        char c;
        !           144: 
        !           145:        while(read(0,&c,1)==1) {
        !           146:                if(c=='\t' || c=='\n') {
        !           147:                        *ap++=ip;
        !           148:                        *bp++ = 0;
        !           149:                        ip=bp;
        !           150:                        if(c=='\n') break;
        !           151:                } else  *bp++ = c;
        !           152:        }
        !           153:        return(c=='\n' ? 1 : 0);
        !           154: }
        !           155: 
        !           156: index(c,s)
        !           157: char c;
        !           158: char *s;
        !           159: {
        !           160:        register char *p=s;
        !           161: 
        !           162:        while(*p && c != *p)
        !           163:                p++;
        !           164:        return(p-s+1);
        !           165: }
        !           166: 
        !           167: last(s)
        !           168: char *s;
        !           169: {
        !           170:        register char c;
        !           171: 
        !           172:        while(*s) {
        !           173:                c = *s; s++;
        !           174:        }
        !           175:        return(c);
        !           176: }
        !           177: 
        !           178: lookup(s)
        !           179: {
        !           180:        int r=0;
        !           181: 
        !           182:        while(cf(s,reason[r]))
        !           183:                r++;
        !           184:        return(r);
        !           185: }
        !           186: 
        !           187: cf(s1,s2)
        !           188: char *s1, *s2;
        !           189: {
        !           190:        while(*s1 == *s2 && *s2) {
        !           191:                s1++; s2++;
        !           192:        }
        !           193:        return(*s1 - *s2);
        !           194: }

unix.superglobalmegacorp.com

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