[Commit] librr/src rr_notice.c,NONE,1.1 rr.c,1.6,1.7 rr.h,1.10,1.11
Carl Worth
commit at keithp.com
Mon Jun 23 00:01:27 PDT 2003
Committed by: cworth
Update of /local/src/CVS/librr/src
In directory home.keithp.com:/tmp/cvs-serv22007/src
Modified Files:
rr.c rr.h
Added Files:
rr_notice.c
Log Message:
Added rr_notice.c.
A couple new functions for mapping rr_robot_t/rr_target_t to sequential index values.
--- NEW FILE: rr_notice.c ---
(This appears to be a binary file; contents omitted.)
Index: rr.c
===================================================================
RCS file: /local/src/CVS/librr/src/rr.c,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- rr.c 19 Jun 2003 11:39:15 -0000 1.6
+++ rr.c 23 Jun 2003 06:01:24 -0000 1.7
@@ -126,7 +126,27 @@
{ "green", RR_ROBOT_GREEN },
{ "blue", RR_ROBOT_BLUE },
};
-#define RR_NUM_ROBOTS (sizeof (robots) / sizeof (robots[0]))
+
+rr_robot_t
+rr_robot_from_idx (int i)
+{
+ if (i < 0 || i >= RR_NUM_ROBOTS)
+ return RR_ROBOT_NONE;
+
+ return robots[i].robot;
+}
+
+int
+rr_robot_idx (rr_robot_t robot)
+{
+ int i;
+
+ for (i = 0; i < RR_NUM_ROBOTS; i++)
+ if (robots[i].robot == robot)
+ return i;
+
+ return 0;
+}
rr_robot_t
_rr_robot_parse (char *str)
@@ -311,6 +331,47 @@
{
return _rr_target_color_parse_symbol (color)
| _rr_target_shape_parse_symbol (shape);
+}
+
+static rr_target_t targets[] = {
+ RR_TARGET_BLUE_CIRCLE,
+ RR_TARGET_BLUE_OCTAGON,
+ RR_TARGET_BLUE_SQUARE,
+ RR_TARGET_BLUE_TRIANGLE,
+ RR_TARGET_GREEN_CIRCLE,
+ RR_TARGET_GREEN_OCTAGON,
+ RR_TARGET_GREEN_SQUARE,
+ RR_TARGET_GREEN_TRIANGLE,
+ RR_TARGET_RED_CIRCLE,
+ RR_TARGET_RED_OCTAGON,
+ RR_TARGET_RED_SQUARE,
+ RR_TARGET_RED_TRIANGLE,
+ RR_TARGET_YELLOW_CIRCLE,
+ RR_TARGET_YELLOW_OCTAGON,
+ RR_TARGET_YELLOW_SQUARE,
+ RR_TARGET_YELLOW_TRIANGLE,
+ RR_TARGET_WHIRL
+};
+
+rr_target_t
+rr_target_from_idx (int i)
+{
+ if (i < 0 || i >= RR_NUM_TARGETS)
+ return RR_TARGET_NONE;
+
+ return targets[i];
+}
+
+int
+rr_target_idx (rr_target_t target)
+{
+ int i;
+
+ for (i = 0; i < RR_NUM_TARGETS; i++)
+ if (targets[i] == target)
+ return i;
+
+ return 0;
}
static struct {
Index: rr.h
===================================================================
RCS file: /local/src/CVS/librr/src/rr.h,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -d -r1.10 -r1.11
--- rr.h 19 Jun 2003 11:39:15 -0000 1.10
+++ rr.h 23 Jun 2003 06:01:24 -0000 1.11
@@ -75,6 +75,7 @@
RR_ROBOT_YELLOW = 0x8
} rr_robot_t;
#define RR_ROBOT_ANY (RR_ROBOT_BLUE | RR_ROBOT_GREEN | RR_ROBOT_RED | RR_ROBOT_YELLOW)
+#define RR_NUM_ROBOTS 4
typedef enum {
RR_WALL_NONE = 0,
@@ -134,6 +135,7 @@
RR_TARGET_WHIRL = RR_TARGET_COLOR_WHIRL | RR_TARGET_SHAPE_WHIRL
} rr_target_t;
#define RR_TARGET_ANY (RR_TARGET_SHAPE_ANY | RR_TARGET_COLOR_ANY)
+#define RR_NUM_TARGETS 17
typedef enum {
RR_DIRECTION_NONE,
@@ -463,6 +465,12 @@
char *
rr_direction_str (rr_direction_t direction);
+rr_robot_t
+rr_robot_from_idx (int i);
+
+int
+rr_robot_idx (rr_robot_t robot);
+
char *
rr_robot_str (rr_robot_t robot);
@@ -471,5 +479,11 @@
char *
rr_target_shape_str (rr_target_shape_t shape);
+
+rr_target_t
+rr_target_from_idx (int i);
+
+int
+rr_target_idx (rr_target_t target);
#endif
More information about the Commit
mailing list