+2003-07-09 Carl Worth <cworth@isi.edu>
+
+ * src/rrsolve.c (main): Added an error message for board parse
+ failure.
+ (handle_events): Cleaned things up considerably with support for
+ new RR_NOTICE_BOARD, (a couple more from the server could clean up
+ even more).
+ (handle_events): Tracked some librr API changes.
+ (trace_solution): Fixed uninitialized variable.
+ (handle_events): Fixed to print solution when it doesn't get a
+ chance to show it.
+
+ * boards/min09: Moved a robot to force a more interesting solution.
+
--- /dev/null
+Here are some random notes I'm keeping on a new approach for solving
+backwards.
+
+ === === === ===
+|R..|... ... ...|
+ === ===
+|y.. ... ... ...|
+ === ===
+|... .RS|...|g..|
+
+|... ... ...|b..|
+ ===
+|... ... ... ...|
+ === === === ===
+
+ === === === ===
+|A..|.B. .b. .B.|
+ === ===
+|aB. .b. .b. .B.|
+ === ===
+|a.C ..C|...|...|
+
+|a.. ... ...|...|
+ ===
+|A.C a.C a.. A.C|
+ === === === ===
+
+ === === === ===
+|R0.|... ... ...|
+ === ===
+|r1. ... ... ...|
+ === ===
+|r1. ...|...|...|
+
+|r1. ... ...|...|
+ ===
+|R1. r2. r2. R2.|
+ === === === ===
+
+ === === === ===
+|...|... ... ...|
+ === ===
+|F.. ... 4F. ...|
+ === ===
+|1.. 0..|4F.|...|
+
+|2F. 1.. 4F.|...|
+ ===
+|2F. 1.. 3F. 3F.|
+ === === === ===
+
+ === === === ===
+|...|... ... ...|
+ === ===
+|... ... ... ...|
+ === ===
+|1.. 0..|...|...|
+
+|... 1.. ...|...|
+ ===
+|... 1.. ... ...|
+ === === === ===
+
+ === === === ===
+|...|... ... ...|
+ === ===
+|... ... 3A. ...|
+ === ===
+|1.. 0..|3A.|...|
+
+|... 1.. 3A.|...|
+ ===
+|A.. 1.. 2A.2A..|
+ === === === ===
+
+ === === === ===
+|3B.|6B. 6B. 5B.|
+ === ===
+|3B. 4B. 4B. 4B.|
+ === ===
+|1.. 0..|5B.|...|
+
+|3B. 1.. 5B.|...|
+ ===
+|2B. 1.. B?? 6B?|
+ === === === ===
+
+ === === === ===
+|...|... ... ...|
+ === ===
+|... ... ... ...|
+ === ===
+|1.. 0..|...|...|
+
+|C.. 1.. 2C....|
+ ===
+|... 1.. ... ...|
+ === === === ===
+
+ === === === ===
+|...|... ... ...|
+ === ===
+|... ... ... ...|
+ === ===
+|1.. 0..|...|...|
+
+|2D. 1.. D..|...|
+ ===
+|... 1.. ... ...|
+ === === === ===
+
+ === === === ===
+|2E.|5E. 5E. 4E.|
+ === ===
+|2E. 3E. 3E. 3E.|
+ === ===
+|1.. 0..|4E.|...|
+
+|E.. 1.. 4E.|...|
+ ===
+|5E. 1.. 4E. 5E.|
+ === === === ===
+
+ === === === ===
+|...|... ... ...|
+ === ===
+|F.. ... 4F. ...|
+ === ===
+|1.. 0..|4F.|...|
+
+|2F. 1.. 4F.|...|
+ ===
+|2F. 1.. 3F. 3F.|
+ === === === ===
+
+
+ === === === === === === === === === === === === === === === ===
+|2+* 2+* 2+* 2+* 1+*|7.* 5.* 5.* 5.* 8.* 8.* 7.*|6.* 6.* 4.* 5.*|
+ ===
+|3.* 3.* 3.* 3.* 1.. 4.* 4.*|5.* 5.* 6.* 6.* 6.* 6.*|6.* 4.* 5.*|
+ === ===
+|3.*|9.* 3.* 3.* 1.. 7.* 4.* 5.* 5.* 9.*|6.* 6.* 6.* 6.* 4.* 5.*|
+ ===
+|3.* 4.* 3.* 3.* 1.. 4.* 4.* 4.* 4.* 4.* 4.* 4.* 4.* 4.* 4.* 4.*|
+ ===
+|3.* 3.* 3.* 3.* 1.. 3.* 3.* 3.* 3.* 3.* 3.* 3.* 3.* 3.* 3.* 2.*|
+ ===
+|3.* 3.* 3.* 3.* 1.. 3.* 2.*|5.* 5.* 5.* 6.* 6.* 6.* 6.*|3.* 2.*|
+ === === ===
+|4.* 4.* 3.*|3.* 1.. 4.* 2.* 4.* 4.* 4.* 4.* 4.*|3.* 3.* 3.* 2.*|
+ === === ===
+|3.* 3.* 3.* 3.* 1.. 3.* 2.*|... ...|3.* 3.* 3.* 3.* 3.* 3.* 2.*|
+
+|3.* 3.* 3.* 3.* 1.. 3.* 2.*|... ...|5.* 5.* 5.* 5.* 5.* 4.*|2.*|
+ === === ===
+|5.* 5.* 3.* 4.*|0+. 1.. 1+. 1+* 1.* 1.* 1.* 1.* 1.* 1.* 1.* 1.*|
+ === === === ===
+|5.* 6.* 3.* 4.* 6.* 6.*|7.* 2.* 7.*|5.* 6.* 5.* 6.*|7.* 2.* 8.*|
+ === ===
+|9.* 9.* 3.* 4.* 7.* 7.* 7.* 2.* 7.* 5.* 9.* 5.* 7.* 9.* 2.* 9.*|
+ ===
+|8.* 8.* 3.* 4.* 7.* 7.* 7.* 7.*|7.* 5.* 8.* 5.* 7.* 8.* 2.* 8.*|
+ === ===
+|9.* 9.*|3.* 4.* 4.* 4.* 4.* 7.* 4.* 4.*|7.* 5.* 7.* 8.* 2.* 8.*|
+
+|5.* 5.* 3.* 4.*|7.* 7.* 7.* 7.* 7.* 5.* 7.* 5.* 7.* 8.* 2.* 8.*|
+ ===
+|8.* 8.* 3.* 8.* 7.*|6.* 6.* 6.* 6.* 5.* 6.* 5.*|7.* 8.* 2.* 8.*|
+ === === === === === === === === === === === === === === === ===
+|... ... ... ... ...|... ... ... ... ... ... ...|... ... ... ...|
+ ===
+|... ... ... ... ... r.. .yo|... ... ... ... ... ...|.rs ... ...|
+ === ===
+|...|.gt ... ... ... ... ... ... g.. .bt|... ... ... ... ... ...|
+ ===
+|... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...|
+ ===
+|... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...|
+ ===
+|... ... ... ... ... ... .bs|... ... ... ... ... ... ...|.go ...|
+ === === ===
+|... ... ...|.rc ... ... ... ... ... ... ... .yc|... ... ... ...|
+ === === ===
+|... ... ... ... ... ... ...|... ...|... ... ... ... ... ... ...|
+
+|... ... ... ... ... ... ...|... ...|... ... ... ... ... Yys|...|
+ === === ===
+|... ... ... ...|.YT ... ... ... ... ... ... ... ... ... ... ...|
+ === === === ===
+|... ... ... ... ... ...|.bc ... .rt|... ... ... ...|.gc ... ...|
+ === ===
+|... b.. ... ... ... ... ... ... ... ... ... ... ... ... ... ...|
+ ===
+|... ... ... ... ... ... ... .ww|... ... ... ... ... ... ... ...|
+ === ===
+|... .ro|... ... ... ... ... ... ... ...|.bo ... ... ... ... ...|
+
+|... ... ... .gs|... ... ... ... ... ... ... ... ... ... ... ...|
+ ===
+|... ... ... ... ...|... ... ... ... ... ... ...|... ... ... ...|
+ === === === === === === === === === === === === === === === ===
--- /dev/null
+My solution:
+
+ Move #1: yellow east
=== ===
|...|rbt ... ... ... ... ... ... ...|.bs ... ... ... ... ... ...|
===
-|... ... ... ... ... ... ... ... ... ... ... ... ... ... b.. ...|
+|... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...|
===
|... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...|
===
-|... ... ... ... ... ... .go|... ... ... ... ... ... ... .gt|...|
+|... ... ... ... ... ... .go|... ... ... ... ... ... b.. .gt|...|
=== ===
|... ... .rs|... ... ... ... ... ...|.yo ... ... ... ... ... ...|
===
--- /dev/null
+ === === === === === === === === === === === === === === === ===
+|... ... ... ...|... ... ... ... ...|... ... ... ... ... ... ...|
+
+|... ... ... ... ... ... ... ... ... ... ... ... .yt|... ... ...|
+ ===
+|... ... ... ... ... .bo|... ... ... ...|.ro ... ... ... ... ...|
+ === ===
+|... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...|
+ ===
+|... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...|
+ === ===
+|... ... .gc|... ... ... ...|.rt ... ... ... ggs|... ... ... ...|
+ === === ===
+|... ... ... ... ... ... ... ... ... ... ... ... ... ...|.bc ...|
+ === === ===
+|...|.YS ... ... ... ... ...|... ...|...|.ww ... ... ... ... ...|
+ ===
+|... ... ... ... ... ... ...|... ...|... ... ... ... ... ... ...|
+ === === === === ===
+|... Yyo|... ... ...|bbs ... ... ... ... ... ... ...|.go ... ...|
+
+|... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...|
+ === ===
+|... ... ... ... ... ... ... ... ...|.yc ... ... ... ... ... ...|
+ ===
+|... ... ... ... ... ... .rc|... ... ... ... ... ... ... ... ...|
+ === ===
+|r.. ... ... ... ... ... ... ... ... ... ... ... ... ... .rs|...|
+
+|... ...|.gt ... ... ... ... ... ... ...|.bt ... ... ... ... ...|
+ === ===
+|... ... ... ... ... ...|... ... ... ... ... ...|... ... ... ...|
+ === === === === === === === === === === === === === === === ===
--- /dev/null
+My solution:
+
+ Move #1: red south
+ Move #2: blue south
+ Move #3: yellow west, north
+ Move #5: blue west, north, west
+ Move #8: yellow south, east
+ Move #10: green west, north, east, south, west, south
+ Move #16: yellow west, north
--- /dev/null
+ === === === === === === === === === === === === === === === ===
+|... ... ... ...|... ... ... ... ... ...|... ... ... ... ... ...|
+ ===
+|... ... ... ... ... ...|.bc ... ... ... ... ... ... ...|.rt ...|
+ ===
+|... ... ... ... ... ... ... ... ... ... ...|.bo ... ... ... ...|
+ === ===
+|... .yt|... ... ... ... ... ... ... ... ... ... ... ... ... B..|
+ === ===
+|... ... ... ... ...|.gs ... ... ... ... ... ... ... ... ... ...|
+
+|... ... .ro|... ... ... ... .ww|... ... ... ... ... ... ... ...|
+ === ===
+|... ... ... ... ... ... ... ... ... ... ... ... ... .gc|... ...|
+ === === === === ===
+|... ... ... ... ... ... ...|... ...|... .ys|... ... ... ... ...|
+
+|... ... ... ... ... ... ...|... ...|... ... ... ... ... ... ...|
+ === === ===
+|... ... ... yyo|... ... ... ... ... ... ... ... ...|.BT ... ...|
+ ===
+|... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...|
+
+|...|.rc ... ... ... ... ... ... ... .yc|... ... ... ... ... ...|
+ === === ===
+|... ... ... ... ... ... .bs|... ... ... ... ... ... ... ... ...|
+ === ===
+|... ... ... ... ... ... ... ... ... ... ... ... ... ... .rs|...|
+ === === ===
+|... ...|.gt ... ... ... ... ... ... ...|ggo ... ... ... ... ...|
+
+|... ... ... ... r.. ...|... ... ... ... ... ...|... ... ... ...|
+ === === === === === === === === === === === === === === === ===
--- /dev/null
+My solution:
+
+ Move #1: green east, north, west, north, west
+ Move #6: red north, east
+ Move #8: green east, north, west, south
+ Move #12: blue north, west, south, east, south, west
--- /dev/null
+ === === === === === === === === === === === === === === === ===
+|... ... ... ... ...|... ... ... ... ... ... ...|... ... ... ...|
+ ===
+|... ... ... ... ... ... .yo|... ... ... ... ... ...|.rs ... ...|
+ === ===
+|...|.gt ... ... ... ... ... ... ... .bt|... ... ... ... ... ...|
+ ===
+|... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...|
+ ===
+|... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...|
+ ===
+|Y.. ... ... ... ... ... .bs|... ... ... ... ... ... ...|.go ...|
+ === === ===
+|... ... ...|.rc ... ... ... ... ... ... ... .yc|... ... ... ...|
+ === === ===
+|... ... ... ... ... ... ...|... ...|... ... ... ... ... ... ...|
+ ===
+|... ... ... ... ... .ww|...|... ...|... ... ... ... ... .YS|...|
+ === === ===
+|... bbc|... ... ... ... ... ... ... ... ... ... ... ... ... ...|
+ === === ===
+|... ... ... ...|.gs ... ... ... .rt|... ... ... ...|.gc ... ...|
+ === ===
+|... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...|
+ ===
+|g.. ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...|
+ === ===
+|... ... ... ... ... rro|... ... ... ...|.bo ... ... ... ... ...|
+ ===
+|... ... ...|.yt ... ... ... ... ... ... ... ... ... ... ... ...|
+
+|... ... ... ... ... ... ...|... ... ... ... ...|... ... ... ...|
+ === === === === === === === === === === === === === === === ===
--- /dev/null
+My solution:
+
+ Move #1: yellow east
+ Move #2: green south, east, north, east, south
+ Move #7: red south, east, north, east
+ Move #11: green north
+ Move #12: yellow west, north, east, south, east, south, east, north, east
--- /dev/null
+ === === === === === === === === === === === === === === === ===
+|... ... ... ... ...|... ... ... ... ... ... ...|... ... ... ...|
+ ===
+|... ... ... ... ... ... .yo|... ... ... ... ... ...|.rs ... ...|
+ === ===
+|...|.gt ... ... ... ... ... ... ... .bt|... ... ... ... ... ...|
+ ===
+|... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...|
+ ===
+|... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...|
+ ===
+|Y.. ... ... ... ... ... .bs|... ... ... ... ... ... ...|.go ...|
+ === === ===
+|... ... ...|.rc ... ... ... ... ... ... ... .yc|... ... ... ...|
+ === === ===
+|... ... ... ... ... ... ...|... ...|... ... ... ... ... ... ...|
+ ===
+|... ... ... ... ... .ww|...|... ...|... ... ... ... ... .YS|...|
+ === === ===
+|... bbc|... ... ... ... ... ... ... ... ... ... ... ... ... ...|
+ === === ===
+|... ... ... ...|.gs ... ... ... .rt|... ... ... ...|.gc ... ...|
+ === ===
+|... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...|
+ ===
+|g.. ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...|
+ === ===
+|... ... ... ... ... rro|... ... ... ...|.bo ... ... ... ... ...|
+ ===
+|... ... ...|.yt ... ... ... ... ... ... ... ... ... ... ... ...|
+
+|... ... ... ... ... ... ...|... ... ... ... ...|... ... ... ...|
+ === === === === === === === === === === === === === === === ===
--- /dev/null
+ === === === === ===
+|R.. ... ... ... ...|
+ ===
+|y.. ... ... ...|b..|
+ ===
+|... .RS|... ...|g..|
+ ===
+|... ... ... ... ...|
+
+|... ... ... ... ...|
+ === === === === ===
for (i = 0; args.files[i]; i++) {
board = rr_board_create_from_file (args.files[i]);
- if (board == NULL)
+ if (board == NULL) {
+ fprintf (stderr, "Failed to parse board in %s\n", args.files[i]);
continue;
+ }
rrs_solution_init (&solution);
solve_board (board, &solution);
rrs_solution_print (&solution);
}
switch (notice->type) {
- /* XXX: The processing needed for GAMEOVER, JOIN, and TURN
- is a mess right now. There should be one NOTICE to say
- the board has changed and one to say a TURN has started,
- rather than the current mess. */
- case RR_NOTICE_GAMEOVER:
- status = rr_client_show (client, &diagram);
- if (status) {
- fprintf (stderr, "Error in rr_client_show: %s\n", rr_status_str (status));
- goto DONE;
- }
- rr_board_parse (board, diagram);
- free (diagram);
+ case RR_NOTICE_BOARD:
+ rr_board_parse (board, notice->u.string);
break;
case RR_NOTICE_TURN:
rr_board_set_goal_target (board, notice->u.target);
rr_client_nobid (client);
break;
case RR_NOTICE_POSITION:
- rr_board_position_robot (board,
- notice->u.position.robot,
- notice->u.position.x,
- notice->u.position.y);
+ rr_board_add_robot (board,
+ notice->u.position.robot,
+ notice->u.position.x,
+ notice->u.position.y);
break;
case RR_NOTICE_GAMESTATE:
- if (notice->u.gamestate == RR_GAMESTATE_SHOW) {
+ if (notice->u.gamestate == RR_GAMESTATE_DONE
+ || notice->u.gamestate == RR_GAMESTATE_SHOW) {
if (solution.num_moves) {
printf ("My solution (%d moves):", solution.num_moves);
rrs_solution_print (&solution);
}
}
break;
+ case RR_NOTICE_GAMEOVER:
case RR_NOTICE_GAME:
case RR_NOTICE_USER:
case RR_NOTICE_JOIN:
int i;
int x, y;
+ for (i=0; i < RR_NUM_ROBOTS; i++)
+ rr_board_remove_robot (board, rr_robot_from_idx (i));
+
for (i=0; i < RR_NUM_ROBOTS; i++) {
RRS_STATE_GET_ROBOT (state, i, x, y);
- rr_board_position_robot (board, rr_robot_from_idx (i), x, y);
+ rr_board_add_robot (board, rr_robot_from_idx (i), x, y);
}
-
}
static rr_status_t
rr_status_t status;
int i, j;
rrs_state_buf_t *buf;
- int found_move;
+ int found_move = 0;
rr_robot_t robot, robot_found, last_robot_found = RR_ROBOT_NONE;
rr_direction_t dir, dir_found;
rrs_state_t state_found;
state = initial->state[i];
rrs_state_set_board (state, board);
+
+ if (state == 0x611a4350)
+ printf ("I'm within one move now\n");
for (ri = 0; ri < RR_NUM_ROBOTS; ri++) {
robot = rr_robot_from_idx (ri);
for (dir = RR_DIRECTION_NORTH; dir <= RR_DIRECTION_EAST; dir++) {