[Commit] rrclient rrtest.c,1.1,1.2
Carl Worth
commit at keithp.com
Mon Jun 2 08:17:48 PDT 2003
- Previous message: [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
- Next message: [Commit] rrclient .cvsignore,NONE,1.1
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
Committed by: cworth
Update of /local/src/CVS/rrclient
In directory home.keithp.com:/tmp/cvs-serv7245
Modified Files:
rrtest.c
Log Message:
Added a second board diagram.
Included tests of moving pieces around the board.
Index: rrtest.c
===================================================================
RCS file: /local/src/CVS/rrclient/rrtest.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- rrtest.c 1 Jun 2003 04:29:30 -0000 1.1
+++ rrtest.c 2 Jun 2003 14:17:46 -0000 1.2
@@ -28,60 +28,127 @@
#include <rr.h>
-static char DIAGRAM[] =
-" === === === === === === === === === === === === === === === === \n"
-"|... ... ... ...|... ... ... ... ... ...|... ... ... ... ... b..|\n"
-" === \n"
-"|... ... ... ... ... .go|... ... ... ... ... ... ... ...|.RT ...|\n"
-" === \n"
-"|...|.rs ... ... ... ... ... ... ... ... ...|.bo ... ... ... ...|\n"
-" === === \n"
-"|... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...|\n"
-" === === === \n"
-"|g.. ... ... ... ... ...|.yc ... ... ... ... ... ... ... ... ...|\n"
-" \n"
-"|... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...|\n"
-" === \n"
-"|... ... .bt|... ... ... ... ... ... ... ... ... ... .gc|... ...|\n"
-" === === === === \n"
-"|... ... ... ... ... ... ...|... ...|... .ys|... ... ... ... ...|\n"
-" === \n"
-"|... ... ... ... ... ... ...|... ...|... ... ...|.ww ... ... ...|\n"
-" === === === \n"
-"|... ... ... .yo|... ... ... ... ... ...|.bc ... ... ... ... ...|\n"
-" === \n"
-"|... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...|\n"
-" === \n"
-"|...|.rc ... ... ... ... ... ... ... .yt|... ... ... ... ... ...|\n"
-" === === === \n"
-"|... ... ... ... ... ... .bs|... y.. ... ... ... ... ... .gs|...|\n"
-" === \n"
-"|... ... ... ... ... ... ... R.. ... ... ... ... ... ... ... ...|\n"
-" === === === \n"
-"|... ...|.gt ... ... ... ... ... ... ... ... ... ...|.ro ... ...|\n"
-" \n"
-"|... ... ... ... ... ...|... ... ... ... ...|... ... ... ... ...|\n"
-" === === === === === === === === === === === === === === === === ";
+typedef struct move {
+ rr_robot_t robot;
+ rr_direction_t direction;
+} move_t;
+
+#define MAX_SOLUTION 100
+typedef struct puzzle {
+ char *board;
+ int solution_length;
+ move_t solution[MAX_SOLUTION];
+} puzzle_t;
+
+static puzzle_t puzzle[] = {
+ {
+ "\n"
+ " === === === \n"
+ "|R..|... g..|\n"
+ " \n"
+ "|... .RT|...|\n"
+ " === \n"
+ "|... ... .gs|\n"
+ " === === === ",
+ 4,
+ {
+ {RR_ROBOT_GREEN, RR_DIRECTION_SOUTH},
+ {RR_ROBOT_GREEN, RR_DIRECTION_WEST},
+ {RR_ROBOT_RED, RR_DIRECTION_SOUTH},
+ {RR_ROBOT_RED, RR_DIRECTION_EAST},
+ }
+ },
+ {
+ "\n"
+ " === === === === === === === === === === === === === === === === \n"
+ "|... ... ... ...|... ... ... ... ... ...|... ... ... ... ... b..|\n"
+ " === \n"
+ "|... ... ... ... ... .go|... ... ... ... ... ... ... ...|.RT ...|\n"
+ " === \n"
+ "|...|.rs ... ... ... ... ... ... ... ... ...|.bo ... ... ... ...|\n"
+ " === === \n"
+ "|... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...|\n"
+ " === === === \n"
+ "|g.. ... ... ... ... ...|.yc ... ... ... ... ... ... ... ... ...|\n"
+ " \n"
+ "|... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...|\n"
+ " === \n"
+ "|... ... .bt|... ... ... ... ... ... ... ... ... ... .gc|... ...|\n"
+ " === === === === \n"
+ "|... ... ... ... ... ... ...|... ...|... .ys|... ... ... ... ...|\n"
+ " === \n"
+ "|... ... ... ... ... ... ...|... ...|... ... ...|.ww ... ... ...|\n"
+ " === === === \n"
+ "|... ... ... .yo|... ... ... ... ... ...|.bc ... ... ... ... ...|\n"
+ " === \n"
+ "|... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...|\n"
+ " === \n"
+ "|...|.rc ... ... ... ... ... ... ... .yt|... ... ... ... ... ...|\n"
+ " === === === \n"
+ "|... ... ... ... ... ... .bs|... y.. ... ... ... ... ... .gs|...|\n"
+ " === \n"
+ "|... ... ... ... ... ... ... R.. ... ... ... ... ... ... ... ...|\n"
+ " === === === \n"
+ "|... ...|.gt ... ... ... ... ... ... ... ... ... ...|.ro ... ...|\n"
+ " \n"
+ "|... ... ... ... ... ...|... ... ... ... ...|... ... ... ... ...|\n"
+ " === === === === === === === === === === === === === === === === ",
+ 18,
+ {
+ {RR_ROBOT_BLUE, RR_DIRECTION_SOUTH},
+ {RR_ROBOT_GREEN, RR_DIRECTION_EAST},
+ {RR_ROBOT_GREEN, RR_DIRECTION_NORTH},
+ {RR_ROBOT_GREEN, RR_DIRECTION_EAST},
+ {RR_ROBOT_GREEN, RR_DIRECTION_NORTH},
+ {RR_ROBOT_GREEN, RR_DIRECTION_EAST},
+ {RR_ROBOT_GREEN, RR_DIRECTION_SOUTH},
+ {RR_ROBOT_YELLOW, RR_DIRECTION_NORTH},
+ {RR_ROBOT_YELLOW, RR_DIRECTION_EAST},
+ {RR_ROBOT_YELLOW, RR_DIRECTION_NORTH},
+ {RR_ROBOT_RED, RR_DIRECTION_NORTH},
+ {RR_ROBOT_RED, RR_DIRECTION_EAST},
+ {RR_ROBOT_RED, RR_DIRECTION_NORTH},
+ {RR_ROBOT_RED, RR_DIRECTION_EAST},
+ {RR_ROBOT_RED, RR_DIRECTION_NORTH},
+ {RR_ROBOT_RED, RR_DIRECTION_EAST},
+ {RR_ROBOT_RED, RR_DIRECTION_SOUTH},
+ {RR_ROBOT_RED, RR_DIRECTION_WEST},
+ }
+ }
+};
int
main (void)
{
- rr_board_t *board;
rr_status_t status;
+ rr_board_t *board;
+ move_t *move;
+ int i, j;
- board = rr_board_create (16, 16);
-
- puts (rr_board_to_str (board));
+ for (i=0; i < sizeof (puzzle) / sizeof (puzzle[0]); i++) {
+ board = rr_board_create (3, 3);
- status = rr_board_parse (board, DIAGRAM);
- if (status) {
- fprintf (stderr, "Error parsing board: %s\n", rr_status_str (status));
- return 1;
- }
+ status = rr_board_parse (board, puzzle[i].board);
+ if (status) {
+ fprintf (stderr, "Error parsing puzzle[%d]->board: %s\n",
+ i, rr_status_str (status));
+ return 1;
+ }
- puts (rr_board_to_str (board));
+ puts (rr_board_to_str (board));
- rr_board_destroy (board);
+ for (j=0; j < puzzle[i].solution_length; j++) {
+ move = &puzzle[i].solution[j];
+ status = rr_board_move (board, move->robot, move->direction);
+ if (status == RR_STATUS_BLOCKED) {
+ fprintf (stderr, "Robot blocked at move %d of puzzle %d\n", j, i);
+ break;
+ }
+ }
+ puts (rr_board_to_str (board));
+ rr_board_destroy (board);
+ }
+
return 0;
}
- Previous message: [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
- Next message: [Commit] rrclient .cvsignore,NONE,1.1
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
More information about the Commit
mailing list