From a278d8f2b6534fc46e035d6a2a9984407c2c7aba Mon Sep 17 00:00:00 2001 From: Carl Worth Date: Fri, 11 Jul 2003 01:03:15 +0000 Subject: [PATCH] Small cleanups. --- ChangeLog | 14 +++ NOTES | 201 ++++++++++++++++++++++++++++++++++++++++ boards/min01_solution | 3 + boards/min09 | 4 +- boards/min17-2 | 33 +++++++ boards/min17-2_solution | 9 ++ boards/min17-3 | 33 +++++++ boards/min17-3_solution | 6 ++ boards/min20 | 33 +++++++ boards/min20_solution | 7 ++ boards/min20~ | 33 +++++++ boards/test | 11 +++ src/rrsolve.c | 41 ++++---- 13 files changed, 405 insertions(+), 23 deletions(-) create mode 100644 NOTES create mode 100644 boards/min01_solution create mode 100644 boards/min17-2 create mode 100644 boards/min17-2_solution create mode 100644 boards/min17-3 create mode 100644 boards/min17-3_solution create mode 100644 boards/min20 create mode 100644 boards/min20_solution create mode 100644 boards/min20~ create mode 100644 boards/test diff --git a/ChangeLog b/ChangeLog index e69de29..34e11a5 100644 --- a/ChangeLog +++ b/ChangeLog @@ -0,0 +1,14 @@ +2003-07-09 Carl Worth + + * 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. + diff --git a/NOTES b/NOTES new file mode 100644 index 0000000..9201de7 --- /dev/null +++ b/NOTES @@ -0,0 +1,201 @@ +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|... ... ... ... ... ... ... ... ... ... ... ...| + === +|... ... ... ... ...|... ... ... ... ... ... ...|... ... ... ...| + === === === === === === === === === === === === === === === === diff --git a/boards/min01_solution b/boards/min01_solution new file mode 100644 index 0000000..73f8ea2 --- /dev/null +++ b/boards/min01_solution @@ -0,0 +1,3 @@ +My solution: + + Move #1: yellow east diff --git a/boards/min09 b/boards/min09 index eac9ef4..1c06187 100644 --- a/boards/min09 +++ b/boards/min09 @@ -21,11 +21,11 @@ === === |...|rbt ... ... ... ... ... ... ...|.bs ... ... ... ... ... ...| === -|... ... ... ... ... ... ... ... ... ... ... ... ... ... b.. ...| +|... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...| === |... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...| === -|... ... ... ... ... ... .go|... ... ... ... ... ... ... .gt|...| +|... ... ... ... ... ... .go|... ... ... ... ... ... b.. .gt|...| === === |... ... .rs|... ... ... ... ... ...|.yo ... ... ... ... ... ...| === diff --git a/boards/min17-2 b/boards/min17-2 new file mode 100644 index 0000000..9deb580 --- /dev/null +++ b/boards/min17-2 @@ -0,0 +1,33 @@ + === === === === === === === === === === === === === === === === +|... ... ... ...|... ... ... ... ...|... ... ... ... ... ... ...| + +|... ... ... ... ... ... ... ... ... ... ... ... .yt|... ... ...| + === +|... ... ... ... ... .bo|... ... ... ...|.ro ... ... ... ... ...| + === === +|... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...| + === +|... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...| + === === +|... ... .gc|... ... ... ...|.rt ... ... ... ggs|... ... ... ...| + === === === +|... ... ... ... ... ... ... ... ... ... ... ... ... ...|.bc ...| + === === === +|...|.YS ... ... ... ... ...|... ...|...|.ww ... ... ... ... ...| + === +|... ... ... ... ... ... ...|... ...|... ... ... ... ... ... ...| + === === === === === +|... Yyo|... ... ...|bbs ... ... ... ... ... ... ...|.go ... ...| + +|... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...| + === === +|... ... ... ... ... ... ... ... ...|.yc ... ... ... ... ... ...| + === +|... ... ... ... ... ... .rc|... ... ... ... ... ... ... ... ...| + === === +|r.. ... ... ... ... ... ... ... ... ... ... ... ... ... .rs|...| + +|... ...|.gt ... ... ... ... ... ... ...|.bt ... ... ... ... ...| + === === +|... ... ... ... ... ...|... ... ... ... ... ...|... ... ... ...| + === === === === === === === === === === === === === === === === diff --git a/boards/min17-2_solution b/boards/min17-2_solution new file mode 100644 index 0000000..e5a67cd --- /dev/null +++ b/boards/min17-2_solution @@ -0,0 +1,9 @@ +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 diff --git a/boards/min17-3 b/boards/min17-3 new file mode 100644 index 0000000..e1db2c4 --- /dev/null +++ b/boards/min17-3 @@ -0,0 +1,33 @@ + === === === === === === === === === === === === === === === === +|... ... ... ...|... ... ... ... ... ...|... ... ... ... ... ...| + === +|... ... ... ... ... ...|.bc ... ... ... ... ... ... ...|.rt ...| + === +|... ... ... ... ... ... ... ... ... ... ...|.bo ... ... ... ...| + === === +|... .yt|... ... ... ... ... ... ... ... ... ... ... ... ... B..| + === === +|... ... ... ... ...|.gs ... ... ... ... ... ... ... ... ... ...| + +|... ... .ro|... ... ... ... .ww|... ... ... ... ... ... ... ...| + === === +|... ... ... ... ... ... ... ... ... ... ... ... ... .gc|... ...| + === === === === === +|... ... ... ... ... ... ...|... ...|... .ys|... ... ... ... ...| + +|... ... ... ... ... ... ...|... ...|... ... ... ... ... ... ...| + === === === +|... ... ... yyo|... ... ... ... ... ... ... ... ...|.BT ... ...| + === +|... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...| + +|...|.rc ... ... ... ... ... ... ... .yc|... ... ... ... ... ...| + === === === +|... ... ... ... ... ... .bs|... ... ... ... ... ... ... ... ...| + === === +|... ... ... ... ... ... ... ... ... ... ... ... ... ... .rs|...| + === === === +|... ...|.gt ... ... ... ... ... ... ...|ggo ... ... ... ... ...| + +|... ... ... ... r.. ...|... ... ... ... ... ...|... ... ... ...| + === === === === === === === === === === === === === === === === diff --git a/boards/min17-3_solution b/boards/min17-3_solution new file mode 100644 index 0000000..77e478b --- /dev/null +++ b/boards/min17-3_solution @@ -0,0 +1,6 @@ +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 diff --git a/boards/min20 b/boards/min20 new file mode 100644 index 0000000..62050b9 --- /dev/null +++ b/boards/min20 @@ -0,0 +1,33 @@ + === === === === === === === === === === === === === === === === +|... ... ... ... ...|... ... ... ... ... ... ...|... ... ... ...| + === +|... ... ... ... ... ... .yo|... ... ... ... ... ...|.rs ... ...| + === === +|...|.gt ... ... ... ... ... ... ... .bt|... ... ... ... ... ...| + === +|... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...| + === +|... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...| + === +|Y.. ... ... ... ... ... .bs|... ... ... ... ... ... ...|.go ...| + === === === +|... ... ...|.rc ... ... ... ... ... ... ... .yc|... ... ... ...| + === === === +|... ... ... ... ... ... ...|... ...|... ... ... ... ... ... ...| + === +|... ... ... ... ... .ww|...|... ...|... ... ... ... ... .YS|...| + === === === +|... bbc|... ... ... ... ... ... ... ... ... ... ... ... ... ...| + === === === +|... ... ... ...|.gs ... ... ... .rt|... ... ... ...|.gc ... ...| + === === +|... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...| + === +|g.. ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...| + === === +|... ... ... ... ... rro|... ... ... ...|.bo ... ... ... ... ...| + === +|... ... ...|.yt ... ... ... ... ... ... ... ... ... ... ... ...| + +|... ... ... ... ... ... ...|... ... ... ... ...|... ... ... ...| + === === === === === === === === === === === === === === === === diff --git a/boards/min20_solution b/boards/min20_solution new file mode 100644 index 0000000..179735b --- /dev/null +++ b/boards/min20_solution @@ -0,0 +1,7 @@ +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 diff --git a/boards/min20~ b/boards/min20~ new file mode 100644 index 0000000..c019d77 --- /dev/null +++ b/boards/min20~ @@ -0,0 +1,33 @@ + === === === === === === === === === === === === === === === === +|... ... ... ... ...|... ... ... ... ... ... ...|... ... ... ...| + === +|... ... ... ... ... ... .yo|... ... ... ... ... ...|.rs ... ...| + === === +|...|.gt ... ... ... ... ... ... ... .bt|... ... ... ... ... ...| + === +|... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...| + === +|... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...| + === +|Y.. ... ... ... ... ... .bs|... ... ... ... ... ... ...|.go ...| + === === === +|... ... ...|.rc ... ... ... ... ... ... ... .yc|... ... ... ...| + === === === +|... ... ... ... ... ... ...|... ...|... ... ... ... ... ... ...| + === +|... ... ... ... ... .ww|...|... ...|... ... ... ... ... .YS|...| + === === === +|... bbc|... ... ... ... ... ... ... ... ... ... ... ... ... ...| + === === === +|... ... ... ...|.gs ... ... ... .rt|... ... ... ...|.gc ... ...| + === === +|... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...| + === +|g.. ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...| + === === +|... ... ... ... ... rro|... ... ... ...|.bo ... ... ... ... ...| + === +|... ... ...|.yt ... ... ... ... ... ... ... ... ... ... ... ...| + +|... ... ... ... ... ... ...|... ... ... ... ...|... ... ... ...| + === === === === === === === === === === === === === === === === diff --git a/boards/test b/boards/test new file mode 100644 index 0000000..cb5c100 --- /dev/null +++ b/boards/test @@ -0,0 +1,11 @@ + === === === === === +|R.. ... ... ... ...| + === +|y.. ... ... ...|b..| + === +|... .RS|... ...|g..| + === +|... ... ... ... ...| + +|... ... ... ... ...| + === === === === === diff --git a/src/rrsolve.c b/src/rrsolve.c index 1057481..5e92cbb 100644 --- a/src/rrsolve.c +++ b/src/rrsolve.c @@ -85,8 +85,10 @@ main (int argc, char *argv[]) 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); @@ -165,18 +167,8 @@ handle_events (rr_client_t *client) } 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); @@ -206,19 +198,21 @@ handle_events (rr_client_t *client) 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: @@ -291,11 +285,13 @@ rrs_state_set_board (rrs_state_t state, rr_board_t *board) 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 @@ -420,7 +416,7 @@ trace_solution (rr_board_t *board, 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; @@ -547,6 +543,9 @@ rrs_find_new_states (rr_board_t *board, 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++) { -- 2.43.0