date and time created 88/06/01 18:32:07 by bostic
[unix-history] / usr / src / games / robots / rnd_pos.c
CommitLineData
7d1a081c
KM
1/*
2 * Copyright (c) 1980 Regents of the University of California.
4cd7a139
KB
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms are permitted
6 * provided that this notice is preserved and that due credit is given
7 * to the University of California at Berkeley. The name of the University
8 * may not be used to endorse or promote products derived from this
9 * software without specific prior written permission. This software
10 * is provided ``as is'' without express or implied warranty.
7d1a081c
KM
11 */
12
13#ifndef lint
4cd7a139
KB
14static char sccsid[] = "@(#)rnd_pos.c 5.2 (Berkeley) %G%";
15#endif /* not lint */
7d1a081c
KM
16
17# include "robots.h"
18
19# define IS_SAME(p,y,x) ((p).y != -1 && (p).y == y && (p).x == x)
20
21/*
22 * rnd_pos:
23 * Pick a random, unoccupied position
24 */
25COORD *
26rnd_pos()
27{
28 static COORD pos;
29 static int call = 0;
30 register int i = 0;
31
32 do {
33 pos.y = rnd(Y_FIELDSIZE - 1) + 1;
34 pos.x = rnd(X_FIELDSIZE - 1) + 1;
35 refresh();
36 } while (Field[pos.y][pos.x] != 0);
37 call++;
38 return &pos;
39}
40
41rnd(range)
42int range;
43{
44 unsigned int rand();
45
46 return rand() % range;
47}