[Commit] librr/src rr.c,1.1,1.2 rr.h,1.1,1.2 rr_board.c,1.2,1.3
rr_cell.c,1.1,1.2 rrint.h,1.1,1.2
Carl Worth
commit at keithp.com
Mon Jun 2 08:16:55 PDT 2003
Committed by: cworth
Update of /local/src/CVS/librr/src
In directory home.keithp.com:/tmp/cvs-serv7198/src
Modified Files:
rr.c rr.h rr_board.c rr_cell.c rrint.h
Log Message:
Fixes to help board representation remain consistent.
New rr_board_add_wall function adds a wall to both affected cells.
Index: rr.c
===================================================================
RCS file: /local/src/CVS/librr/src/rr.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- rr.c 1 Jun 2003 04:27:55 -0000 1.1
+++ rr.c 2 Jun 2003 14:16:52 -0000 1.2
@@ -24,8 +24,30 @@
* Author: Carl Worth <carl at theworths.org>
*/
+#include <ctype.h>
+
#include "rrint.h"
+#define RR_ROBOT_CHAR_BLUE 'b'
+#define RR_ROBOT_CHAR_GREEN 'g'
+#define RR_ROBOT_CHAR_RED 'r'
+#define RR_ROBOT_CHAR_YELLOW 'y'
+#define RR_ROBOT_CHAR_NONE '.'
+
+#define RR_TARGET_COLOR_CHAR_BLUE 'b'
+#define RR_TARGET_COLOR_CHAR_GREEN 'g'
+#define RR_TARGET_COLOR_CHAR_RED 'r'
+#define RR_TARGET_COLOR_CHAR_YELLOW 'y'
+#define RR_TARGET_COLOR_CHAR_MULTI 'w'
+#define RR_TARGET_COLOR_CHAR_NONE '.'
+
+#define RR_TARGET_SHAPE_CHAR_CIRCLE 'c'
+#define RR_TARGET_SHAPE_CHAR_OCTAGON 'o'
+#define RR_TARGET_SHAPE_CHAR_SQUARE 's'
+#define RR_TARGET_SHAPE_CHAR_TRIANGLE 't'
+#define RR_TARGET_SHAPE_CHAR_WHIRL 'w'
+#define RR_TARGET_SHAPE_CHAR_NONE '.'
+
const char *
rr_status_str (rr_status_t status)
{
@@ -40,11 +62,142 @@
return "not a direction";
case RR_STATUS_BLOCKED:
return "robot is blocked";
+ case RR_STATUS_OCCUPIED:
+ return "space is already occupied";
case RR_STATUS_HISTORY_EMPTY:
return "move history is empty";
case RR_STATUS_PARSE_ERROR:
return "parse error";
default:
return "unidentified error";
+ }
+}
+
+char
+_rr_robot_to_char (rr_robot_t robot)
+{
+ switch (robot) {
+ case RR_ROBOT_BLUE:
+ return RR_ROBOT_CHAR_BLUE;
+ case RR_ROBOT_GREEN:
+ return RR_ROBOT_CHAR_GREEN;
+ case RR_ROBOT_RED:
+ return RR_ROBOT_CHAR_RED;
+ case RR_ROBOT_YELLOW:
+ return RR_ROBOT_CHAR_YELLOW;
+ case RR_ROBOT_NONE:
+ default:
+ return RR_ROBOT_CHAR_NONE;
+ }
+}
+
+rr_robot_t
+_rr_char_to_robot (char c)
+{
+ switch (tolower (c)) {
+ case RR_ROBOT_CHAR_BLUE:
+ return RR_ROBOT_BLUE;
+ case RR_ROBOT_CHAR_GREEN:
+ return RR_ROBOT_GREEN;
+ case RR_ROBOT_CHAR_RED:
+ return RR_ROBOT_RED;
+ case RR_ROBOT_CHAR_YELLOW:
+ return RR_ROBOT_YELLOW;
+ case RR_ROBOT_CHAR_NONE:
+ default:
+ return RR_ROBOT_NONE;
+ }
+}
+
+rr_target_t
+_rr_chars_to_target (char color, char shape)
+{
+ rr_target_color_t target_color;
+ rr_target_shape_t target_shape;
+
+ switch (tolower (color)) {
+ case RR_TARGET_COLOR_CHAR_BLUE:
+ target_color = RR_TARGET_BLUE;
+ break;
+ case RR_TARGET_COLOR_CHAR_GREEN:
+ target_color = RR_TARGET_GREEN;
+ break;
+ case RR_TARGET_COLOR_CHAR_RED:
+ target_color = RR_TARGET_RED;
+ break;
+ case RR_TARGET_COLOR_CHAR_YELLOW:
+ target_color = RR_TARGET_YELLOW;
+ break;
+ case RR_TARGET_COLOR_CHAR_MULTI:
+ target_color = RR_TARGET_MULTI;
+ break;
+ case RR_TARGET_COLOR_CHAR_NONE:
+ default:
+ target_color = RR_TARGET_COLOR_NONE;
+ break;
+ }
+
+ switch (tolower (shape)) {
+ case RR_TARGET_SHAPE_CHAR_CIRCLE:
+ target_shape = RR_TARGET_CIRCLE;
+ break;
+ case RR_TARGET_SHAPE_CHAR_OCTAGON:
+ target_shape = RR_TARGET_OCTAGON;
+ break;
+ case RR_TARGET_SHAPE_CHAR_SQUARE:
+ target_shape = RR_TARGET_SQUARE;
+ break;
+ case RR_TARGET_SHAPE_CHAR_TRIANGLE:
+ target_shape = RR_TARGET_TRIANGLE;
+ break;
+ case RR_TARGET_SHAPE_CHAR_WHIRL:
+ target_shape = RR_TARGET_WHIRL;
+ break;
+ case RR_TARGET_SHAPE_CHAR_NONE:
+ default:
+ target_shape = RR_TARGET_SHAPE_NONE;
+ break;
+ }
+
+ return (target_color | target_shape);
+}
+
+char
+_rr_target_color_to_char (rr_target_color_t color)
+{
+ switch (color) {
+ case RR_TARGET_BLUE:
+ return RR_TARGET_COLOR_CHAR_BLUE;
+ case RR_TARGET_GREEN:
+ return RR_TARGET_COLOR_CHAR_GREEN;
+ case RR_TARGET_RED:
+ return RR_TARGET_COLOR_CHAR_RED;
+ case RR_TARGET_YELLOW:
+ return RR_TARGET_COLOR_CHAR_YELLOW;
+ case RR_TARGET_MULTI:
+ return RR_TARGET_COLOR_CHAR_MULTI;
+ case RR_TARGET_NONE:
+ default:
+ return RR_TARGET_COLOR_CHAR_NONE;
+ }
+}
+
+char
+_rr_target_shape_to_char (rr_target_shape_t shape)
+{
+ switch (shape) {
+ case RR_TARGET_CIRCLE:
+ return RR_TARGET_SHAPE_CHAR_CIRCLE;
+ case RR_TARGET_OCTAGON:
+ return RR_TARGET_SHAPE_CHAR_OCTAGON;
+ case RR_TARGET_SQUARE:
+ return RR_TARGET_SHAPE_CHAR_SQUARE;
+ case RR_TARGET_TRIANGLE:
+ return RR_TARGET_SHAPE_CHAR_TRIANGLE;
+ case RR_TARGET_WHIRL:
+ return RR_TARGET_SHAPE_CHAR_WHIRL;
+ case RR_TARGET_NONE:
+ default:
+ return RR_TARGET_SHAPE_CHAR_NONE;
}
}
Index: rr.h
===================================================================
RCS file: /local/src/CVS/librr/src/rr.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- rr.h 1 Jun 2003 04:27:55 -0000 1.1
+++ rr.h 2 Jun 2003 14:16:52 -0000 1.2
@@ -35,6 +35,7 @@
RR_STATUS_ROBOT_NOT_FOUND,
RR_STATUS_NOT_DIRECTION,
RR_STATUS_BLOCKED,
+ RR_STATUS_OCCUPIED,
RR_STATUS_HISTORY_EMPTY,
RR_STATUS_PARSE_ERROR
} rr_status_t;
@@ -101,9 +102,16 @@
typedef enum {
RR_DIRECTION_UP,
+ RR_DIRECTION_NORTH = RR_DIRECTION_UP,
+
RR_DIRECTION_LEFT,
+ RR_DIRECTION_WEST = RR_DIRECTION_LEFT,
+
RR_DIRECTION_RIGHT,
- RR_DIRECTION_DOWN
+ RR_DIRECTION_EAST = RR_DIRECTION_RIGHT,
+
+ RR_DIRECTION_DOWN,
+ RR_DIRECTION_SOUTH = RR_DIRECTION_DOWN
} rr_direction_t;
/* rr_board.c */
@@ -114,6 +122,21 @@
void
rr_board_destroy (rr_board_t *board);
+rr_status_t
+rr_board_empty (rr_board_t *board);
+
+rr_status_t
+rr_board_add_wall (rr_board_t *board,
+ int x, int y, rr_wall_t wall);
+
+rr_status_t
+rr_board_add_robot (rr_board_t *board, int x, int y,
+ rr_robot_t robot, int is_goal_robot);
+
+rr_status_t
+rr_board_add_target (rr_board_t *board, int x, int y,
+ rr_target_t target, int is_goal_target);
+
/* rr_board_find_robot: Find X/Y location for given robot.
Possible errors:
@@ -165,8 +188,9 @@
rr_board_to_str (rr_board_t *board);
/* rr_board_parse: Parse a string diagram in the same format as
- returned by rr_board_to_str. It is an error if the dimensions of
- the diagram do not match the curren board dimensions.
+ returned by rr_board_to_str. The diagram may have dimensions
+ different than that of the current board. If so, the dimensions of
+ the board are changed to match the diagram provided.
Possible errors: RR_BOARD_PARSE_ERROR
*/
Index: rr_board.c
===================================================================
RCS file: /local/src/CVS/librr/src/rr_board.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- rr_board.c 1 Jun 2003 04:39:56 -0000 1.2
+++ rr_board.c 2 Jun 2003 14:16:52 -0000 1.3
@@ -27,6 +27,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
+#include <string.h>
#include "rrint.h"
@@ -66,8 +67,7 @@
_rr_board_init (rr_board_t *board, int width, int height)
{
rr_status_t status;
- int i, j;
- rr_cell_t *cell;
+ int j;
board->width = width;
board->height = height;
@@ -79,7 +79,7 @@
if (status)
return status;
- board->str = malloc (((4 * width) + 2) * (2 * height + 1));
+ board->str = malloc (((4 * width) + 2) * (2 * height + 1) + 1);
if (board->str == NULL)
return RR_STATUS_NO_MEMORY;
@@ -98,20 +98,7 @@
}
}
- for (j=0; j < height; j++) {
- for (i=0; i < width; i++) {
- cell = &board->cell[j][i];
- _rr_cell_init (cell);
- if (j==0)
- _rr_cell_add_wall (cell, RR_WALL_ABOVE);
- if (i==0)
- _rr_cell_add_wall (cell, RR_WALL_LEFT);
- if (j == height-1)
- _rr_cell_add_wall (cell, RR_WALL_BELOW);
- if (i == width-1)
- _rr_cell_add_wall (cell, RR_WALL_RIGHT);
- }
- }
+ rr_board_empty (board);
return RR_STATUS_SUCCESS;
}
@@ -145,6 +132,92 @@
}
rr_status_t
+rr_board_empty (rr_board_t *board)
+{
+ int i, j;
+ rr_cell_t *cell;
+
+ for (j=0; j < board->height; j++) {
+ for (i=0; i < board->width; i++) {
+ cell = &board->cell[j][i];
+ _rr_cell_empty (cell);
+ if (j==0)
+ _rr_cell_add_wall (cell, RR_WALL_ABOVE);
+ if (i==0)
+ _rr_cell_add_wall (cell, RR_WALL_LEFT);
+ if (j == board->height - 1)
+ _rr_cell_add_wall (cell, RR_WALL_BELOW);
+ if (i == board->width - 1)
+ _rr_cell_add_wall (cell, RR_WALL_RIGHT);
+ }
+ }
+
+ return RR_STATUS_SUCCESS;
+}
+
+rr_status_t
+rr_board_add_wall (rr_board_t *board,
+ int x, int y, rr_wall_t wall)
+{
+ _rr_cell_add_wall (&board->cell[y][x], wall);
+
+ switch (wall) {
+ case RR_WALL_ABOVE:
+ if (y > 0)
+ _rr_cell_add_wall (&board->cell[y-1][x], RR_WALL_BELOW);
+ break;
+ case RR_WALL_LEFT:
+ if (x > 0)
+ _rr_cell_add_wall (&board->cell[y][x-1], RR_WALL_RIGHT);
+ break;
+ case RR_WALL_RIGHT:
+ if (x < board->width - 1)
+ _rr_cell_add_wall (&board->cell[y][x+1], RR_WALL_LEFT);
+ break;
+ case RR_WALL_BELOW:
+ if (y < board->height - 1)
+ _rr_cell_add_wall (&board->cell[y+1][x], RR_WALL_ABOVE);
+ break;
+ }
+
+ return RR_STATUS_SUCCESS;
+}
+
+rr_status_t
+rr_board_add_robot (rr_board_t *board, int x, int y,
+ rr_robot_t robot, int is_goal_robot)
+{
+ rr_cell_t *cell = &board->cell[y][x];
+
+ if (_rr_cell_has_robot (cell))
+ return RR_STATUS_OCCUPIED;
+
+ _rr_cell_add_robot (cell, robot);
+
+ if (is_goal_robot)
+ board->goal_robot = robot;
+
+ return RR_STATUS_SUCCESS;
+}
+
+rr_status_t
+rr_board_add_target (rr_board_t *board, int x, int y,
+ rr_target_t target, int is_goal_target)
+{
+ rr_cell_t *cell = &board->cell[y][x];
+
+ if (_rr_cell_has_target (cell))
+ return RR_STATUS_OCCUPIED;
+
+ _rr_cell_add_target (cell, target);
+
+ if (is_goal_target)
+ board->goal_target = target;
+
+ return RR_STATUS_SUCCESS;
+}
+
+rr_status_t
rr_board_find_robot (rr_board_t *board,
rr_robot_t robot, int *x, int *y)
{
@@ -154,7 +227,8 @@
for (j=0; j < board->height; j++) {
for (i=0; i < board->height; i++) {
cell = &board->cell[j][i];
- if (_rr_cell_has_robot (cell, robot)) {
+ if (_rr_cell_has_robot (cell)
+ && _rr_cell_get_robot (cell) == robot) {
*x = i;
*y = j;
return RR_STATUS_SUCCESS;
@@ -223,7 +297,7 @@
}
if (_rr_cell_has_wall (&board->cell[y][x], wall)
- || _rr_cell_occupied (&board->cell[y+dy][x+dx]))
+ || _rr_cell_has_robot (&board->cell[y+dy][x+dx]))
return RR_STATUS_BLOCKED;
status = _rr_history_push (&board->history, robot, x, y);
@@ -235,7 +309,7 @@
x += dx;
y += dy;
} while (_rr_cell_has_wall (&board->cell[y][x], wall) == 0
- && _rr_cell_occupied (&board->cell[y+dy][x+dx]) == 0);
+ && _rr_cell_has_robot (&board->cell[y+dy][x+dx]) == 0);
_rr_cell_add_robot (&board->cell[y][x], robot);
return RR_STATUS_SUCCESS;
@@ -287,7 +361,7 @@
rr_robot_t robot;
robot = _rr_cell_get_robot (cell);
- *r = _rr_cell_robot_to_char (robot);
+ *r = _rr_robot_to_char (robot);
if (robot == board->goal_robot)
*r = toupper (*r);
@@ -302,8 +376,8 @@
rr_target_t target;
target = _rr_cell_get_target (cell);
- *color = _rr_cell_target_color_to_char (target & RR_TARGET_COLOR_ANY);
- *shape = _rr_cell_target_shape_to_char (target & RR_TARGET_SHAPE_ANY);
+ *color = _rr_target_color_to_char (target & RR_TARGET_COLOR_ANY);
+ *shape = _rr_target_shape_to_char (target & RR_TARGET_SHAPE_ANY);
if (target == board->goal_target) {
*color = toupper (*color);
@@ -365,30 +439,32 @@
rr_board_parse (rr_board_t *board, const char *str)
{
int i, j;
- const char *s;
+ const char *s, *n;
char c, d;
- rr_cell_t *cell;
rr_robot_t robot;
- rr_target_color_t target_color;
- rr_target_shape_t target_shape;
+ rr_target_t target;
#define NEXT *s; if (*s == '\0') return RR_STATUS_PARSE_ERROR; s++
#define EXPECT(e) c = NEXT; if (c != (e)) return RR_STATUS_PARSE_ERROR
- for (j=0; j < board->height; j++)
- for (i=0; i < board->width; i++)
- _rr_cell_empty (&board->cell[j][i]);
+ _rr_board_fini (board);
s = str;
EXPECT ('\n');
+ n = strchr (s, '\n');
+ if (n == NULL)
+ return RR_STATUS_PARSE_ERROR;
+ board->width = ((n - s) - 1) / 4;
+ board->height = ((strlen (s) + 1) / (board->width * 4 + 2) - 1) / 2;
+ _rr_board_init (board, board->width, board->height);
+
for (j=0; j < board->height; j++) {
for (i=0; i < board->width; i++) {
- cell = &board->cell[j][i];
EXPECT (' ');
c = NEXT;
if (c == '=')
- _rr_cell_add_wall (cell, RR_WALL_ABOVE);
+ rr_board_add_wall (board, i, j, RR_WALL_ABOVE);
else if (c != ' ')
return RR_STATUS_PARSE_ERROR;
EXPECT (c);
@@ -397,50 +473,33 @@
EXPECT (' ');
EXPECT ('\n');
for (i=0; i < board->width; i++) {
- cell = &board->cell[j][i];
if (i==0) {
EXPECT ('|');
} else {
c = NEXT;
}
if (c == '|')
- _rr_cell_add_wall (cell, RR_WALL_LEFT);
+ rr_board_add_wall (board, i, j, RR_WALL_LEFT);
else if (c != ' ')
return RR_STATUS_PARSE_ERROR;
c = NEXT;
- if (isupper (c)) {
- c = tolower (c);
- robot = _rr_cell_char_to_robot (c);
- rr_board_set_goal_robot (board, robot);
- } else {
- robot = _rr_cell_char_to_robot (c);
- }
- _rr_cell_add_robot (cell, robot);
+ robot = _rr_char_to_robot (c);
+ rr_board_add_robot (board, i, j, robot, isupper (c));
c = NEXT;
d = NEXT;
- if (isupper (c)) {
- c = tolower (c);
- d = tolower (d);
- target_color = _rr_cell_char_to_target_color (c);
- target_shape = _rr_cell_char_to_target_shape (d);
- rr_board_set_goal_target (board, target_color, target_shape);
- } else {
- target_color = _rr_cell_char_to_target_color (c);
- target_shape = _rr_cell_char_to_target_shape (d);
- }
- _rr_cell_add_target (cell, target_color, target_shape);
+ target = _rr_chars_to_target (c, d);
+ rr_board_add_target (board, i, j, target, isupper (c));
}
EXPECT ('|');
- _rr_cell_add_wall (cell, RR_WALL_RIGHT);
+ rr_board_add_wall (board, board->width - 1, j, RR_WALL_RIGHT);
EXPECT ('\n');
}
for (i=0; i < board->width; i++) {
- cell = &board->cell[board->height - 1][i];
EXPECT (' ');
EXPECT ('=');
EXPECT ('=');
EXPECT ('=');
- _rr_cell_add_wall (cell, RR_WALL_BELOW);
+ rr_board_add_wall (board, i, board->height - 1, RR_WALL_BELOW);
}
EXPECT(' ');
Index: rr_cell.c
===================================================================
RCS file: /local/src/CVS/librr/src/rr_cell.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- rr_cell.c 1 Jun 2003 04:27:55 -0000 1.1
+++ rr_cell.c 2 Jun 2003 14:16:52 -0000 1.2
@@ -26,26 +26,6 @@
#include "rrint.h"
-#define RR_ROBOT_CHAR_BLUE 'b'
-#define RR_ROBOT_CHAR_GREEN 'g'
-#define RR_ROBOT_CHAR_RED 'r'
-#define RR_ROBOT_CHAR_YELLOW 'y'
-#define RR_ROBOT_CHAR_NONE '.'
-
-#define RR_TARGET_COLOR_CHAR_BLUE 'b'
-#define RR_TARGET_COLOR_CHAR_GREEN 'g'
-#define RR_TARGET_COLOR_CHAR_RED 'r'
-#define RR_TARGET_COLOR_CHAR_YELLOW 'y'
-#define RR_TARGET_COLOR_CHAR_MULTI 'w'
-#define RR_TARGET_COLOR_CHAR_NONE '.'
-
-#define RR_TARGET_SHAPE_CHAR_CIRCLE 'c'
-#define RR_TARGET_SHAPE_CHAR_OCTAGON 'o'
-#define RR_TARGET_SHAPE_CHAR_SQUARE 's'
-#define RR_TARGET_SHAPE_CHAR_TRIANGLE 't'
-#define RR_TARGET_SHAPE_CHAR_WHIRL 'w'
-#define RR_TARGET_SHAPE_CHAR_NONE '.'
-
void
_rr_cell_init (rr_cell_t *cell)
{
@@ -71,11 +51,9 @@
}
void
-_rr_cell_add_target (rr_cell_t *cell,
- rr_target_color_t color,
- rr_target_shape_t shape)
+_rr_cell_add_target (rr_cell_t *cell, rr_target_t target)
{
- *cell |= (color | shape);
+ *cell |= target;
}
void
@@ -103,13 +81,7 @@
}
int
-_rr_cell_has_robot (rr_cell_t *cell, rr_robot_t robot)
-{
- return *cell & robot;
-}
-
-int
-_rr_cell_occupied (rr_cell_t *cell)
+_rr_cell_has_robot (rr_cell_t *cell)
{
return *cell & RR_ROBOT_ANY;
}
@@ -126,124 +98,9 @@
return *cell & RR_TARGET_ANY;
}
-rr_target_t
-_rr_cell_has_target (rr_cell_t *cell, rr_target_t target)
-{
- return *cell & target;
-}
-
-char
-_rr_cell_robot_to_char (rr_robot_t robot)
-{
- switch (robot) {
- case RR_ROBOT_BLUE:
- return RR_ROBOT_CHAR_BLUE;
- case RR_ROBOT_GREEN:
- return RR_ROBOT_CHAR_GREEN;
- case RR_ROBOT_RED:
- return RR_ROBOT_CHAR_RED;
- case RR_ROBOT_YELLOW:
- return RR_ROBOT_CHAR_YELLOW;
- case RR_ROBOT_NONE:
- default:
- return RR_ROBOT_CHAR_NONE;
- }
-}
-
-rr_robot_t
-_rr_cell_char_to_robot (char c)
-{
- switch (c) {
- case RR_ROBOT_CHAR_BLUE:
- return RR_ROBOT_BLUE;
- case RR_ROBOT_CHAR_GREEN:
- return RR_ROBOT_GREEN;
- case RR_ROBOT_CHAR_RED:
- return RR_ROBOT_RED;
- case RR_ROBOT_CHAR_YELLOW:
- return RR_ROBOT_YELLOW;
- case RR_ROBOT_CHAR_NONE:
- default:
- return RR_ROBOT_NONE;
- }
-}
-
-char
-_rr_cell_target_color_to_char (rr_target_color_t color)
-{
- switch (color) {
- case RR_TARGET_BLUE:
- return RR_TARGET_COLOR_CHAR_BLUE;
- case RR_TARGET_GREEN:
- return RR_TARGET_COLOR_CHAR_GREEN;
- case RR_TARGET_RED:
- return RR_TARGET_COLOR_CHAR_RED;
- case RR_TARGET_YELLOW:
- return RR_TARGET_COLOR_CHAR_YELLOW;
- case RR_TARGET_MULTI:
- return RR_TARGET_COLOR_CHAR_MULTI;
- case RR_TARGET_NONE:
- default:
- return RR_TARGET_COLOR_CHAR_NONE;
- }
-}
-
-rr_target_color_t
-_rr_cell_char_to_target_color (char c)
-{
- switch (c) {
- case RR_TARGET_COLOR_CHAR_BLUE:
- return RR_TARGET_BLUE;
- case RR_TARGET_COLOR_CHAR_GREEN:
- return RR_TARGET_GREEN;
- case RR_TARGET_COLOR_CHAR_RED:
- return RR_TARGET_RED;
- case RR_TARGET_COLOR_CHAR_YELLOW:
- return RR_TARGET_YELLOW;
- case RR_TARGET_COLOR_CHAR_MULTI:
- return RR_TARGET_MULTI;
- case RR_TARGET_COLOR_CHAR_NONE:
- default:
- return RR_TARGET_COLOR_NONE;
- }
-}
-
-char
-_rr_cell_target_shape_to_char (rr_target_shape_t shape)
+int
+_rr_cell_has_target (rr_cell_t *cell)
{
- switch (shape) {
- case RR_TARGET_CIRCLE:
- return RR_TARGET_SHAPE_CHAR_CIRCLE;
- case RR_TARGET_OCTAGON:
- return RR_TARGET_SHAPE_CHAR_OCTAGON;
- case RR_TARGET_SQUARE:
- return RR_TARGET_SHAPE_CHAR_SQUARE;
- case RR_TARGET_TRIANGLE:
- return RR_TARGET_SHAPE_CHAR_TRIANGLE;
- case RR_TARGET_WHIRL:
- return RR_TARGET_SHAPE_CHAR_WHIRL;
- case RR_TARGET_NONE:
- default:
- return RR_TARGET_SHAPE_CHAR_NONE;
- }
+ return *cell & RR_TARGET_ANY;
}
-rr_target_shape_t
-_rr_cell_char_to_target_shape (char c)
-{
- switch (c) {
- case RR_TARGET_SHAPE_CHAR_CIRCLE:
- return RR_TARGET_CIRCLE;
- case RR_TARGET_SHAPE_CHAR_OCTAGON:
- return RR_TARGET_OCTAGON;
- case RR_TARGET_SHAPE_CHAR_SQUARE:
- return RR_TARGET_SQUARE;
- case RR_TARGET_SHAPE_CHAR_TRIANGLE:
- return RR_TARGET_TRIANGLE;
- case RR_TARGET_SHAPE_CHAR_WHIRL:
- return RR_TARGET_WHIRL;
- case RR_TARGET_SHAPE_CHAR_NONE:
- default:
- return RR_TARGET_SHAPE_NONE;
- }
-}
Index: rrint.h
===================================================================
RCS file: /local/src/CVS/librr/src/rrint.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- rrint.h 1 Jun 2003 04:27:55 -0000 1.1
+++ rrint.h 2 Jun 2003 14:16:52 -0000 1.2
@@ -51,6 +51,22 @@
char *str;
};
+/* rr.c */
+char
+_rr_robot_to_char (rr_robot_t robot);
+
+rr_robot_t
+_rr_char_to_robot (char c);
+
+rr_target_t
+_rr_chars_to_target (char color, char shape);
+
+char
+_rr_target_color_to_char (rr_target_color_t color);
+
+char
+_rr_target_shape_to_char (rr_target_shape_t shape);
+
/* rr_cell.c */
void
_rr_cell_init (rr_cell_t *cell);
@@ -71,9 +87,7 @@
_rr_cell_remove_wall (rr_cell_t *cell, rr_wall_t wall);
void
-_rr_cell_add_target (rr_cell_t *cell,
- rr_target_color_t color,
- rr_target_shape_t shape);
+_rr_cell_add_target (rr_cell_t *cell, rr_target_t target);
void
_rr_cell_remove_target (rr_cell_t *cell);
@@ -82,38 +96,16 @@
_rr_cell_has_wall (rr_cell_t *cell, rr_wall_t wall);
int
-_rr_cell_has_robot (rr_cell_t *cell, rr_robot_t robot);
-
-int
-_rr_cell_occupied (rr_cell_t *cell);
+_rr_cell_has_robot (rr_cell_t *cell);
rr_robot_t
_rr_cell_get_robot (rr_cell_t *cell);
-rr_target_t
-_rr_cell_get_target (rr_cell_t *cell);
+int
+_rr_cell_has_target (rr_cell_t *cell);
rr_target_t
-_rr_cell_has_target (rr_cell_t *cell, rr_target_t target);
-
-char
-_rr_cell_robot_to_char (rr_robot_t robot);
-
-rr_robot_t
-_rr_cell_char_to_robot (char c);
-
-char
-_rr_cell_target_color_to_char (rr_target_color_t color);
-
-rr_target_color_t
-_rr_cell_char_to_target_color (char c);
-
-char
-_rr_cell_target_shape_to_char (rr_target_shape_t shape);
-
-rr_target_shape_t
-_rr_cell_char_to_target_shape (char c);
-
+_rr_cell_get_target (rr_cell_t *cell);
/* rr_history.c */
More information about the Commit
mailing list