xref: /original-bsd/games/robots/rnd_pos.c (revision 540a81df)
1 /*
2  * Copyright (c) 1980 Regents of the University of California.
3  * All rights reserved.
4  *
5  * %sccs.include.redist.c%
6  */
7 
8 #ifndef lint
9 static char sccsid[] = "@(#)rnd_pos.c	5.4 (Berkeley) 06/01/90";
10 #endif /* not lint */
11 
12 # include	"robots.h"
13 
14 # define	IS_SAME(p,y,x)	((p).y != -1 && (p).y == y && (p).x == x)
15 
16 /*
17  * rnd_pos:
18  *	Pick a random, unoccupied position
19  */
20 COORD *
21 rnd_pos()
22 {
23 	static COORD	pos;
24 	static int	call = 0;
25 	register int	i = 0;
26 
27 	do {
28 		pos.y = rnd(Y_FIELDSIZE - 1) + 1;
29 		pos.x = rnd(X_FIELDSIZE - 1) + 1;
30 		refresh();
31 	} while (Field[pos.y][pos.x] != 0);
32 	call++;
33 	return &pos;
34 }
35 
36 rnd(range)
37 int	range;
38 {
39 	unsigned int	rand();
40 
41 	return rand() % range;
42 }
43