Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

dir.h

Go to the documentation of this file.
00001 /* Definitions for directions of the compass.
00002    Copyright (C) 1987-1989, 1991-1994, 1996, 2001 Stanley T. Shebs.
00003 
00004 Xconq is free software; you can redistribute it and/or modify
00005 it under the terms of the GNU General Public License as published by
00006 the Free Software Foundation; either version 2, or (at your option)
00007 any later version.  See the file COPYING.  */
00008 
00021 #define NUMDIRS 6
00022 
00023 /* Symbols naming the directions. */
00024 
00025 #define NODIR -1
00026 #define NORTHEAST 0
00027 #define EAST  1
00028 #define SOUTHEAST 2
00029 #define SOUTHWEST 3
00030 #define WEST  4
00031 #define NORTHWEST 5
00032 
00034 #define DIRNAMES { "NE", "E", "SE", "SW", "W", "NW" }
00035 
00037 #define DIRX { 0, 1,  1,  0, -1, -1 }
00038 #define DIRY { 1, 0, -1, -1,  0,  1 }
00039 
00046 #define for_all_directions(dir) \
00047 for ((dir) = 0; (dir) < NUMDIRS; ++(dir))
00048 
00049 /* \brief Interate through directions from random start.
00050  *
00051  * Iteration, starting with a random direction, but going in a
00052  * consistent order once started.  Generate a random number between
00053  * 0 and 5, inclusive, the step throught the directions using a modulo 
00054  * count.
00055  * \see xrandom, NUMDIRS.
00056  * \param dir is the direction iteration variable.
00057  * \param tmp is the starting direction (generated by xrandom).
00058  */
00059 #define for_all_directions_randomly(dir,tmp)  \
00060   for ((tmp) = 0, (dir) = xrandom(NUMDIRS); (tmp) < NUMDIRS; ++(tmp), (dir) = ((dir) + 1) % NUMDIRS)
00061 
00066 #define left_dir(d) (((d) + 5) % NUMDIRS)
00067 
00072 #define right_dir(d) (((d) + 1) % NUMDIRS)
00073 
00079 #define opposite_dir(d) (((d) + 3) % NUMDIRS)
00080 
00088 #define dir_subtract(d1, d2) (((d1) - (d2) + NUMDIRS) % NUMDIRS)
00089 
00096 #define angle_with(d1, d2)  \
00097   min(((d1) - (d2) + NUMDIRS) % NUMDIRS, ((d2) - (d1) + NUMDIRS) % NUMDIRS)
00098 
00104 #define random_dir() (xrandom(NUMDIRS))
00105 
00107 extern char *dirnames[];
00108 
00110 extern int dirx[];
00111 /*1 \brief Y delta array. */
00112 extern int diry[];

Generated on Sat Sep 17 10:28:52 2005 for XconqKernel by doxygen 1.3.6