Annotation of 43BSDReno/games/ching/cno/ching.cno.c, revision 1.1.1.1

1.1       root        1: /*
                      2:  * Copyright (c) 1988 The Regents of the University of California.
                      3:  * All rights reserved.
                      4:  *
                      5:  * This code is derived from software contributed to Berkeley by
                      6:  * Guy Harris.
                      7:  *
                      8:  * Redistribution and use in source and binary forms are permitted
                      9:  * provided that: (1) source distributions retain this entire copyright
                     10:  * notice and comment, and (2) distributions including binaries display
                     11:  * the following acknowledgement:  ``This product includes software
                     12:  * developed by the University of California, Berkeley and its contributors''
                     13:  * in the documentation or other materials provided with the distribution
                     14:  * and in all advertising materials mentioning features or use of this
                     15:  * software. Neither the name of the University nor the names of its
                     16:  * contributors may be used to endorse or promote products derived
                     17:  * from this software without specific prior written permission.
                     18:  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
                     19:  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
                     20:  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
                     21:  */
                     22: 
                     23: #ifndef lint
                     24: char copyright[] =
                     25: "@(#) Copyright (c) 1988 The Regents of the University of California.\n\
                     26:  All rights reserved.\n";
                     27: #endif /* not lint */
                     28: 
                     29: #ifndef lint
                     30: static char sccsid[] = "@(#)ching.cno.c        5.3 (Berkeley) 6/1/90";
                     31: #endif /* not lint */
                     32: 
                     33: /*
                     34:  * cno - Read a question, cast a change, and output the line values to the
                     35:  * standard output for processing by "phx".
                     36:  */
                     37: #include <stdio.h>
                     38: #include "ching.h"
                     39: 
                     40: long   now;            /* current time */
                     41: 
                     42: unsigned seed;         /* seed for random number generator */
                     43: unsigned getrand();
                     44: 
                     45: char   *change();
                     46: char   string[6+1];    /* where the actual change string is put */
                     47: 
                     48: int    table[2][2][2] = {
                     49:        { { OYIN,  YYANG,}, { YYANG, YYIN,} },
                     50:        { { YYANG, YYIN,},  { YYIN,  OYANG,} },
                     51: };
                     52: 
                     53: main()
                     54: {
                     55:        FILE *logf;
                     56: 
                     57:        time(&now);
                     58:        seed = (int)now + getquest() + getgid() + getuid() + getpid();  /* randomize */
                     59:        printf("%s\n", change());
                     60: }
                     61: 
                     62: /*
                     63:  * Hash the question by adding all the characters together.
                     64:  */
                     65: int
                     66: getquest()
                     67: {
                     68:        int result;
                     69:        register int c;
                     70: 
                     71:        result = 0;
                     72:        while ((c = getchar()) != EOF)
                     73:                result += c;
                     74:        return(result);
                     75: }
                     76: 
                     77: /*
                     78:  * Get a set of six lines making up a change.
                     79:  */
                     80: char *
                     81: change()
                     82: {
                     83:        register int i;
                     84: 
                     85:        for (i = 0; i < 6; i++)
                     86:                string[i] = table[getrnum()&01][getrnum()&01][getrnum()&01] + '0';
                     87:        string[i] = '\0';
                     88:        return(string);
                     89: }
                     90: 
                     91: /*
                     92:  * Get a number more random than what getrand() gives.
                     93:  */
                     94: getrnum()
                     95: {
                     96:        return((getrand())>>(getrand()%17));
                     97: }
                     98: 
                     99: /*
                    100:  * Get a random number.
                    101:  */
                    102: unsigned
                    103: getrand()
                    104: {
                    105:        return(seed = (seed*13077) + 6925);
                    106: }

unix.superglobalmegacorp.com

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