121472Smckusick /* 2*60840Sbostic * Copyright (c) 1980, 1993 3*60840Sbostic * The Regents of the University of California. All rights reserved. 433690Sbostic * 542589Sbostic * %sccs.include.redist.c% 621472Smckusick */ 721472Smckusick 821472Smckusick #ifndef lint 9*60840Sbostic static char sccsid[] = "@(#)rnd_pos.c 8.1 (Berkeley) 05/31/93"; 1033690Sbostic #endif /* not lint */ 1121472Smckusick 1221472Smckusick # include "robots.h" 1321472Smckusick 1421472Smckusick # define IS_SAME(p,y,x) ((p).y != -1 && (p).y == y && (p).x == x) 1521472Smckusick 1621472Smckusick /* 1721472Smckusick * rnd_pos: 1821472Smckusick * Pick a random, unoccupied position 1921472Smckusick */ 2021472Smckusick COORD * rnd_pos()2121472Smckusickrnd_pos() 2221472Smckusick { 2321472Smckusick static COORD pos; 2421472Smckusick static int call = 0; 2521472Smckusick register int i = 0; 2621472Smckusick 2721472Smckusick do { 2821472Smckusick pos.y = rnd(Y_FIELDSIZE - 1) + 1; 2921472Smckusick pos.x = rnd(X_FIELDSIZE - 1) + 1; 3021472Smckusick refresh(); 3121472Smckusick } while (Field[pos.y][pos.x] != 0); 3221472Smckusick call++; 3321472Smckusick return &pos; 3421472Smckusick } 3521472Smckusick rnd(range)3621472Smckusickrnd(range) 3721472Smckusick int range; 3821472Smckusick { 3921472Smckusick unsigned int rand(); 4021472Smckusick 4121472Smckusick return rand() % range; 4221472Smckusick } 43