Example #1
0
void
roll(void)
{
	char    c;
	int     row;
	int     col;

	if (iroll) {
		getyx(stdscr, row, col);
		mvprintw(17, 0, "ROLL: ");
		c = readc();
		if (c != '\n') {
			while (c < '1' || c > '6')
				c = readc();
			D0 = c - '0';
			printw(" %c", c);
			c = readc();
			while (c < '1' || c > '6')
				c = readc();
			D1 = c - '0';
			printw(" %c", c);
			move(17, 0);
			clrtoeol();
			move(row, col);
			return;
		}
		move(17, 0);
		clrtoeol();
		move(row, col);
	}
	D0 = rnum(6) + 1;
	D1 = rnum(6) + 1;
	d0 = 0;
}
Example #2
0
void
rdflt(void)			/* default verb messages	*/
{
	for (;;) {
		if ((verb = rnum()) < 0)
			break;
		actspk[verb] = rnum();
	}
}
Example #3
0
/* default verb messages */
static void
rdflt(void)
{
	for (;;) {
		if ((verb = rnum()) < 0)
			break;
		actspk[verb] = rnum();
	}
}
Example #4
0
/* read travel table */
static void
rtrav(void)
{
	int locc;
	struct travlist *t;
	char *s;
	char buf[12];
	int len, m, n, entries;

	entries = 0;
	t = NULL;
	for (oldloc = -1;;) {		/* get another line */
		/* end of entry */
		if ((locc = rnum()) != oldloc && oldloc >= 0) {
			t->next = 0;	/* terminate the old entry */
#if DEBUG
			printf("%d:%d entries\n", oldloc, entries);
			twrite(oldloc);
#endif
		}
		if (locc == -1)
			return;
		if (locc != oldloc) {	/* getting a new entry */
			t = travel[locc] = malloc(sizeof(*t));
			if (t == NULL)
				errx(1, "Out of memory!");
			/* printf("New travel list for %d\n", locc); */
			entries = 0;
			oldloc = locc;
		}
		for (s = buf;; s++)		/* get the newloc number /ASCII */
			if ((*s = next()) == TAB || *s == LF)
				break;
		*s = 0;
		len = strlen(buf);	/* quad long number handling */
		/* printf("Newloc: %s (%d chars)\n", buf, len); */
		if (len < 4) {		/* no "m" conditions */
			m = 0;
			n = atoi(buf);	/* newloc mod 1000 = newloc */
		} else {		/* a long integer */
			n = atoi(buf + len - 3);
			buf[len - 3] = 0;	/* terminate newloc/1000 */
			m = atoi(buf);
		}
		while (breakch != LF) {	/* only do one line at a time */
			if (entries++) {
				t = t->next = malloc(sizeof(*t));
				if (t == NULL)
					errx(1, "Out of memory!");
			}
			t->tverb = rnum();	/* get verb from the file */
			t->tloc = n;		/* table entry mod 1000 */
			t->conditions = m;	/* table entry / 1000 */
			/* printf("entry %d for %d\n", entries, locc); */
		}
	}
}
Example #5
0
void
rlocs(void)				/* initial object locations	*/
{
	for (;;) {
		if ((obj = rnum()) < 0)
			break;
		plac[obj] = rnum();	/* initial loc for this obj	*/
		if (breakch == TAB)	/* there's another entry	*/
			fixd[obj] = rnum();
		else
			fixd[obj] = 0;
	}
}
Example #6
0
void* blaster(void* arg) {
    info_t* info = arg;
#if TICKS
    int tick = rnum(5000);
#endif

    for (;;) {
#if TICKS
        tick++;
        if (tick == 10000) {
            printf("(%d)\n", info->n);
            tick = rnum(5000);
        }
#endif
        int n = rnum(BUCKETS);
        if (info->bucket[n] == NULL) {
        allocnew:
            info->size[n] = 7 + rnum(MALLOC_SIZE);
            LOCK();
            info->bucket[n] = malloc(info->size[n]);
            UNLOCK();
            if (info->bucket[n] == NULL) {
                printf("blaster %d malloc failed %d\n", info->n, n);
                __builtin_trap();
            }
            memset(info->bucket[n], info->n * n, info->size[n]);
        } else {
            int sz = info->size[n];
            uint8_t* x = info->bucket[n];
            int val = n * info->n;
            for (int i = 0; i < sz; i++) {
                if (x[i] != val) {
                    printf("blaster %d bad bucket %d\n", info->n, n);
                    __builtin_trap();
                }
            }
            if (rnum(1000) < 750) {
                LOCK();
                free(info->bucket[n]);
                UNLOCK();
                goto allocnew;
            } else {
                memset(x, val, sz);
            }
        }
    }

    return NULL;
}
Example #7
0
/* liquid assets &c: cond bits */
static void
rliq(void)
{
	int bitnum;

	for (;;) {			/* read new bit list */
		if ((bitnum = rnum()) < 0)
			break;
		for (;;) {		/* read locs for bits */
			cond[rnum()] |= setbit[bitnum];
			if (breakch == LF)
				break;
		}
	}
}
Example #8
0
void
rhints(void)
{
	int     hintnum, i;

	hntmax = 0;
	for (;;) {
		if ((hintnum = rnum()) < 0)
			break;
		for (i = 1; i < 5; i++)
			hints[hintnum][i] = rnum();
		if (hintnum > hntmax)
			hntmax = hintnum;
	}
}
Example #9
0
void
rliq(void)			/* liquid assets &c: cond bits	*/
{
	int bitnum;

	for (;;) {		/* read new bit list		*/
		if ((bitnum = rnum()) < 0)
			break;
		for (;;) {	/* read locs for bits		*/
			cond[rnum()] |= setbit[bitnum];
			if (breakch == LF)
				break;
		}
	}
}
Example #10
0
void
roll(struct move *mm)
{
	char    c;
	int     row;
	int     col;

	row = col = 0;
	if (iroll) {
		if (tflag) {
			row = curr;
			col = curc;
			curmove(17, 0);
		} else
			writec('\n');
		writel("ROLL: ");
		c = readc();
		if (c != '\n') {
			while (c < '1' || c > '6')
				c = readc();
			mm->D0 = c - '0';
			writec(' ');
			writec(c);
			c = readc();
			while (c < '1' || c > '6')
				c = readc();
			mm->D1 = c - '0';
			writec(' ');
			writec(c);
			if (tflag) {
				curmove(17, 0);
				cline();
				curmove(row, col);
			} else
				writec('\n');
			return;
		}
		if (tflag) {
			curmove(17, 0);
			cline();
			curmove(row, col);
		} else
			writec('\n');
	}
	mm->D0 = rnum(6) + 1;
	mm->D1 = rnum(6) + 1;
	mm->d0 = 0;
}
Example #11
0
void test_read(cbuf * thebuf)
{
    double shouldwe;
    int got, thislen;
    buf_t destbuf[BSIZE];
    FILE *fptr;

    fptr = stdout;
    shouldwe = rnum(1);
    if (shouldwe > 0.10)
	return;			/* only test 10% of the time */
    thislen = (int)rnum(BSIZE);
    got = read_cbuf(thebuf, destbuf, thislen);
    errlog2(5,"test_read asked: %d  got: %d\n",thislen, got);
    do_write(destbuf, got);
}
Example #12
0
void test_unget(cbuf * thebuf)
{
    double shouldwe;
    int rval;
    buf_t c;

    shouldwe = rnum(1);
    if (shouldwe > 0.10)
	return;			/* only test 10% of the time */
    c = (int) rnum(BSIZE);
    rval = unget_cbuf(thebuf, c);
    if (rval == 0) {
	fprintf(stderr, "!");
	fflush(stderr);
    } else {
	rval = remove_cbuf(thebuf, &c, 1);
    }
}
Example #13
0
void test_lookahead(cbuf * thebuf)
{
    int got, lachars;
    buf_t destbuf[BSIZE];

    lachars = (int)rnum(BSIZE);
    if (lachars > 0.10 * BSIZE)
	return;			/*only test if chars < 10% of buffer */
    got = lookahead_cbuf(thebuf, destbuf, lachars);
}
Example #14
0
static void randomize(void)
{
   strcpy(param_values[3], rnum(2, 12));
   strcpy(param_values[4], rnum(1, 8));
   strcpy(param_values[5], rnum(0.1, 1));
   strcpy(param_values[6], rnum(0, 5));
   strcpy(param_values[7], rnum(0, 5));
   strcpy(param_values[8], rnum(0, 5));
   regenerate = true;
}
Example #15
0
/* Read from stdin, filling the circular buffer. Use random
   sizes for the read/fill operation */
void fill_buf(cbuf * thebuf)
{
    int j = 0, thislen, retlen;
    char srcbuf[BSIZE], k = 0;
    buf_t src[BSIZE];
    FILE *fptr;

    errlog(5,"Reader starting");
    fptr = stdin;
    while (!feof(fptr)) {
	thislen = (int)rnum(BSIZE);
	thislen = fread(srcbuf, 1, thislen, fptr);
	for (j = 0; j < thislen; j++)
	    src[j] = (buf_t) srcbuf[j];
	retlen = enter_cbuf(thebuf, src, thislen);
    }
    thebuf->refcnt--;		/* End of file, we're done. Decrement the ref count */
}
Example #16
0
int tunnel(i)
{
	register struct room *p;
	register int n, j;
	int c;

	c = 20;
loop:
	n = rnum(NROOM);
	if(n == i)
		if(--c > 0)
			goto loop;
	p = &room[n];
	for(j=0; j<NTUNN; j++)
	if(p->tunn[j] == -1) {
		p->tunn[j] = i;
		return(n);
	}
	goto loop;
}
Example #17
0
/* empty the circular buffer by issuing random sized remove_cbuf
   calls, then write the result to stdout */
void empty_buf(cbuf * thebuf)
{
    int want, got, j;
    char last = 0;
    buf_t destbuf[BSIZE];
    FILE *fptr;

    errlog(5,"Writer starting");
    fptr = stdout;
    got = 1;
    while (got) {
	want = (int)rnum(BSIZE);
	test_lookahead(thebuf);
	test_unget(thebuf);
	test_read(thebuf);
	got = remove_cbuf(thebuf, destbuf, want);
	do_write(destbuf, got);
    }

}
Example #18
0
/* read the vocabulary */
static void
rvoc(void)
{
	char *s;
	int rv_index;
	char buf[6];

	for (;;) {
		rv_index = rnum();
		if (rv_index < 0)
			break;
		for (s = buf, *s = 0;; s++)	/* get the word */
			if ((*s = next()) == TAB || *s == '\n' || *s == LF
			    || *s == ' ')
				break;
		/* terminate word with newline, LF, tab, blank */
		if (*s != '\n' && *s != LF)
			FLUSHLF;		/* can be comments */
		*s = 0;
		/* printf("\"%s\"=%d\n", buf, rv_index); */
		vocab(buf, -2, rv_index);
	}
}
Example #19
0
void
rdesc(int sect)			/* read description-format msgs */
{
	int     locc;
	char   *seekstart, *maystart;

	seekhere = inptr;	/* Where are we in virtual file?*/
	outsw = 1;		/* these msgs go into tmp file	*/
	for (oldloc = -1, seekstart = seekhere;;) {
		maystart = inptr;	/* maybe starting new entry	*/
		if ((locc = rnum()) != oldloc && oldloc >= 0  /* finished msg */
		    && !(sect == 5 && (locc == 0 || locc >= 100)))/* unless sect 5*/
		{
			switch (sect) {	/* now put it into right table  */
			case 1:	/* long descriptions		*/
				ltext[oldloc].seekadr = seekhere;
				ltext[oldloc].txtlen = maystart - seekstart;
				break;
			case 2:	/* short descriptions		*/
				stext[oldloc].seekadr = seekhere;
				stext[oldloc].txtlen = maystart - seekstart;
				break;
			case 5:	/* object descriptions		*/
				ptext[oldloc].seekadr = seekhere;
				ptext[oldloc].txtlen = maystart - seekstart;
				break;
			case 6:	/* random messages		*/
				if (oldloc >= RTXSIZ)
					errx(1, "Too many random msgs");
				rtext[oldloc].seekadr = seekhere;
				rtext[oldloc].txtlen = maystart - seekstart;
				break;
			case 10:/* class messages		*/
				ctext[clsses].seekadr = seekhere;
				ctext[clsses].txtlen = maystart - seekstart;
				cval[clsses++] = oldloc;
				break;
			case 12:/* magic messages		*/
				if (oldloc >= MAGSIZ)
					errx(1, "Too many magic msgs");
				mtext[oldloc].seekadr = seekhere;
				mtext[oldloc].txtlen = maystart - seekstart;
				break;
			default:
				errx(1, "rdesc called with bad section");
			}
			seekhere += maystart - seekstart;
		}
		if (locc < 0) {
			outsw = 0;	/* turn off output		*/
			seekhere += 3;	/* -1<delimiter>		*/
			return;
		}
		if (sect != 5 || (locc > 0 && locc < 100)) {
			if (oldloc != locc)/* starting a new message	*/
				seekstart = maystart;
			oldloc = locc;
		}
		FLUSHLF;		/* scan the line		*/
	}
}
Example #20
0
int
dblgood()
{
	int     n;		/* accumulated judgment */
	int     OFFC = *offptr;	/* no. of computer's men off */
	int     OFFO = *offopp;	/* no. of player's men off */

#ifdef DEBUG
	int     i;
	if (ftrace == NULL)
		ftrace = fopen("bgtrace", "w");
		printf ("fopen\n");
#endif

	/* get real pip value */
	n = eval() * cturn;
#ifdef DEBUG
	fputs("\nDoubles:\nBoard: ", ftrace);
	for (i = 0; i < 26; i++)
		fprintf(ftrace, " %d", board[i]);
	fprintf(ftrace, "\n\tpip = %d, ", n);
#endif

	/* below adjusts pip value according to position judgments */

	/* check men moving off board */
	if (OFFC > -15 || OFFO > -15) {
		if (OFFC < 0 && OFFO < 0) {
			OFFC += 15;
			OFFO += 15;
			n +=((OFFC - OFFO) * 7) / 2;
		} else if (OFFC < 0) {
			OFFC += 15;
			n -= OFFO * 7 / 2;
		} else if (OFFO < 0) {
			OFFO += 15;
			n += OFFC * 7 / 2;
		}
		if (OFFC < 8 && OFFO > 8)
			n -= 7;
		if (OFFC < 10 && OFFO > 10)
			n -= 7;
		if (OFFC < 12 && OFFO > 12)
			n -= 7;
		if (OFFO < 8 && OFFC > 8)
			n += 7;
		if (OFFO < 10 && OFFC > 10)
			n += 7;
		if (OFFO < 12 && OFFC > 12)
			n += 7;
		n += ((OFFC - OFFO) * 7) / 2;
	}

#ifdef DEBUG
	fprintf(ftrace, "off = %d, ", n);
#endif

	/* see if men are trapped */
	n -= freemen(bar);
	n += freemen(home);
	n += trapped(home, -cturn);
	n -= trapped(bar, cturn);

#ifdef DEBUG
	fprintf(ftrace, "free = %d\n", n);
	fprintf(ftrace, "\tOFFC = %d, OFFO = %d\n", OFFC, OFFO);
	fflush(ftrace);
#endif

	/* double if 2-3 moves ahead */
	if (n > (int)(10 + rnum(7)))
		return(1);
	return(0);
}