]> git.cworth.org Git - rrsolve/commitdiff
Added support for solving boards in files provided on the command line.
authorCarl Worth <cworth@cworth.org>
Thu, 3 Jul 2003 14:43:10 +0000 (14:43 +0000)
committerCarl Worth <cworth@cworth.org>
Thu, 3 Jul 2003 14:43:10 +0000 (14:43 +0000)
Added a few example boards in the boards directory.

.cvsignore
boards/min09 [new file with mode: 0644]
boards/min14 [new file with mode: 0644]
boards/min16 [new file with mode: 0644]
src/args.c
src/args.h
src/rrsolve.c

index 43b89a7c57a3bdccf7a27bd979305f97e8be391b..49e940748293824782a1efafc80dca4031b9a0f9 100644 (file)
@@ -8,6 +8,7 @@ config.status
 config.sub
 configure
 install-sh
+ltmain.sh
 Makefile
 Makefile.in
 missing
diff --git a/boards/min09 b/boards/min09
new file mode 100644 (file)
index 0000000..eac9ef4
--- /dev/null
@@ -0,0 +1,34 @@
+ === === === === === === === === === === === === === === === === 
+|... ... ... ...|... ... ... ... ... ...|... ... ... ... ... ...|
+                                 ===                             
+|... ... ... ... ... ...|.bc ... .YS|... ... ... ... ... ... ...|
+                         ===                                     
+|... ... ... ... ... ... ... ... ... ... .gc|... ... ... ... ...|
+     ===                                 ===                     
+|... .yt|... ... g.. ... ... ... ... ... ... ... ... ... ... ...|
+                     ===                                     === 
+|... ... ... ... ...|.gs ... ... ... ... ... ... ... ... ... ...|
+                                                                 
+|... ... .ro|... ... ... ... .ww|... ... ... ... ...|.bo ... ...|
+         ===                 ===                     ===         
+|... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...|
+ ===                         === ===     ===                     
+|... ... ... ... ... ... ...|... ...|Y..|.rt ... ... ... ... ...|
+                                                                 
+|... ... ... ... ... ... ...|... ...|... ... ... ... ... ... ...|
+                 ===         === ===             ===             
+|... ... ... ... .yc|... ... ... ... ... ... ... .rc|... ... ...|
+     ===                                                     === 
+|...|rbt ... ... ... ... ... ... ...|.bs ... ... ... ... ... ...|
+                                     ===                         
+|... ... ... ... ... ... ... ... ... ... ... ... ... ... b.. ...|
+ ===                                                             
+|... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...|
+                         ===                                     
+|... ... ... ... ... ... .go|... ... ... ... ... ... ... .gt|...|
+                                     ===                 ===     
+|... ... .rs|... ... ... ... ... ...|.yo ... ... ... ... ... ...|
+         ===                                                     
+|... ... ... ...|... ... ... ... ... ... ...|... ... ... ... ...|
+ === === === === === === === === === === === === === === === === 
+
diff --git a/boards/min14 b/boards/min14
new file mode 100644 (file)
index 0000000..da8d34d
--- /dev/null
@@ -0,0 +1,33 @@
+ === === === === === === === === === === === === === === === === 
+|... ... ... ...|... ... ... ... ... ... ... ...|... ... ... ...|
+                                                     ===         
+|... ... ... ... ... ... ... ... ... ... ... ... ...|.rs ... ...|
+                                                                 
+|... ... ... ... ... .bo|... ... ... .BT|... ... ... ... ... ...|
+                     ===             ===                         
+|... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...|
+                                                             === 
+|... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...|
+         ===                                                     
+|... ... .gc|... ... ... ...|.rt ... ... ... ... ... ...|.go ...|
+ ===                         ===             ===         ===     
+|... ... ... ... ... ... ... ... ... ... ... .yc|... ... ... ...|
+     ===                     === ===                             
+|...|.ys ... ... ... ... ...|... ...|... ... ... ... ... ... ...|
+                                                                 
+|... ... ... ... ... ... ...|... ...|... ... ... ... ... ... ...|
+                             === ===             ===             
+|... ... ... ...|.yt ... ... ... ... ... ... ... .bs|y.. ... ...|
+                 ===     ===                                 === 
+|... ... ... ... ... ...|Bbc ... ... ... ... ... ... ... ... ...|
+ ===                                                             
+|... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...|
+                             ===     ===                         
+|... ... ... ... ... ... ... .ww|...|.yo ... ... ... ... ... ...|
+     ===                                                         
+|... .ro|... ... ... ... ... ... ... ... ... ... ... ...|ggt ...|
+                                                         ===     
+|... ... ... .gs|... ... ... ... ... ... ... rrc|... ... ... ...|
+             ===                             ===                 
+|... ... ... ... ...|... ... ... ... ... ... ... ... ...|... ...|
+ === === === === === === === === === === === === === === === === 
diff --git a/boards/min16 b/boards/min16
new file mode 100644 (file)
index 0000000..6d3a58b
--- /dev/null
@@ -0,0 +1,33 @@
+ === === === === === === === === === === === === === === === === 
+|... ... ... ...|r.. ... ... ... ... ... ... ...|... ... ... ...|
+                                                     ===         
+|... ... ... ... ... ... ... ... ... ... ... ... ...|.rs Y.. ...|
+                                                                 
+|... ... ... ... ... .bo|... ... ... .bt|... ... ... ... ... ...|
+                     ===             ===                         
+|... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...|
+                                                             === 
+|... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...|
+         ===                                                     
+|... ... .gc|... ... ... ...|.rt ... ... ... ... ... ...|.go ...|
+ ===                         ===             ===         ===     
+|... ... ... ... ... ... ... ... ... ... ... .yc|... ... ... ...|
+     ===                     === ===                             
+|...|.YS ... ... ... ... ...|... ...|... ... ... ... ... ... ...|
+                                                 ===             
+|... ... ... ... ... ... ...|... ...|... ... ...|.ww ... ... ...|
+     ===             ===     === ===                             
+|... .yo|... ... ...|bbs ... ... ... ...|.bc ... ... ... ... ...|
+                                         ===                     
+|... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...|
+ ===                                                         === 
+|... ... ... ... ... ... ... ... ... .yt|... ... ... ... ... ...|
+                                     ===                 ===     
+|... ... ... ... ... ... .rc|... ... ... ... ... ... ... .gs|...|
+                         ===                                     
+|... ... ... ... ... ... ... ... ... ... ... ... ... ... ... g..|
+                                                     ===         
+|... ...|.gt ... ... ... ... ... ... ... ... ... ...|.ro ... ...|
+         ===                                                     
+|... ... ... ... ... ...|... ... ... ... ...|... ... ... ... ...|
+ === === === === === === === === === === === === === === === === 
index 67d970361df624784842a2971e993f64d22d1ddf..90edc984f154dc882f0a58aab62361d4d4c6377f 100644 (file)
@@ -35,7 +35,7 @@ const char *argp_program_bug_address = "<carl@theworths.org>";
 
 static char doc[] = "rrsolve - Ricochet Robot solver";
 
-static char args_doc[] = "";
+static char args_doc[] = "[file ...]";
 
 static struct argp_option options[] = {
     /* name,           key, arg,       flags, doc */
@@ -66,16 +66,11 @@ parse_opt (int key, char *arg, struct argp_state *state)
        break;
 
     case ARGP_KEY_ARG:
-       argp_usage (state);
+       /* Consume all remaining non-option arguments */
+       args->files =  &state->argv[state->next - 1];
+       state->next = state->argc;
        break;
 
-/*
-    case ARGP_KEY_END:
-       if (state->arg_num < 1)
-           argp_usage (state);
-       break;
-*/
-
     default:
        return ARGP_ERR_UNKNOWN;
     }
@@ -98,6 +93,9 @@ args_parse(args_t *args, int argc, char *argv[])
     args->game = getenv ("RR_GAME");
     if (args->game == NULL)
        args->game = ARGS_GAME_DEFAULT;
+    args->files = NULL;
 
-    return argp_parse (&argp, argc, argv, 0, 0, args);
+    return argp_parse (&argp, argc, argv,
+                      ARGP_LONG_ONLY,
+                      NULL, args);
 }
index a0a3c4205774876ec21ac015bc7059a07e4ab1be..526be350388498c2e8dcec0ccbbe7926d36b976b 100644 (file)
@@ -44,6 +44,7 @@ typedef struct args
     char *port;
     char *user;
     char *game;
+    char **files;
 } args_t;
 
 error_t
index a957049c3960b988192896b2a8adfed8557cd43f..fd85a57b1259a3983b2fec474fcb65f0d469241b 100644 (file)
@@ -74,67 +74,6 @@ trace_solution (rr_board_t *board,
                rrs_state_t solution_state,
                rrs_solution_t *solution);
 
-char TOUGH[] = "\n"
-" === === === === === === === === === === === === === === === === \n"
-"|... ... ... ...|r.. ... ... ... ... ... ... ...|... ... ... ...|\n"
-"                                                     ===         \n"
-"|... ... ... ... ... ... ... ... ... ... ... ... ...|.rs Y.. ...|\n"
-"                                                                 \n"
-"|... ... ... ... ... .bo|... ... ... .bt|... ... ... ... ... ...|\n"
-"                     ===             ===                         \n"
-"|... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...|\n"
-"                                                             === \n"
-"|... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...|\n"
-"         ===                                                     \n"
-"|... ... .gc|... ... ... ...|.rt ... ... ... ... ... ...|.go ...|\n"
-" ===                         ===             ===         ===     \n"
-"|... ... ... ... ... ... ... ... ... ... ... .yc|... ... ... ...|\n"
-"     ===                     === ===                             \n"
-"|...|.YS ... ... ... ... ...|... ...|... ... ... ... ... ... ...|\n"
-"                                                 ===             \n"
-"|... ... ... ... ... ... ...|... ...|... ... ...|.ww ... ... ...|\n"
-"     ===             ===     === ===                             \n"
-"|... .yo|... ... ...|bbs ... ... ... ...|.bc ... ... ... ... ...|\n"
-"                                         ===                     \n"
-"|... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...|\n"
-" ===                                                         === \n"
-"|... ... ... ... ... ... ... ... ... .yt|... ... ... ... ... ...|\n"
-"                                     ===                 ===     \n"
-"|... ... ... ... ... ... .rc|... ... ... ... ... ... ... .gs|...|\n"
-"                         ===                                     \n"
-"|... ... ... ... ... ... ... ... ... ... ... ... ... ... ... g..|\n"
-"                                                     ===         \n"
-"|... ...|.gt ... ... ... ... ... ... ... ... ... ...|.ro ... ...|\n"
-"         ===                                                     \n"
-"|... ... ... ... ... ...|... ... ... ... ...|... ... ... ... ...|\n"
-" === === === === === === === === === === === === === === === === ";
-/*
-Move #1 generated 11 new states.
-Move #2 generated 59 new states.
-Move #3 generated 216 new states.
-Move #4 generated 640 new states.
-Move #5 generated 1701 new states.
-Move #6 generated 4239 new states.
-Move #7 generated 10041 new states.
-Move #8 generated 22678 new states.
-Move #9 generated 49103 new states.
-Move #10 generated 102154 new states.
-Move #11 generated 204086 new states.
-Move #12 generated 391534 new states.
-Move #13 generated 722808 new states.
-Move #14 generated 1285932 new states.
-Move #15 generated 2204971 new states.
-Found solution of 16 moves in 3694.8 seconds.
-Traced solution in 0.052438 seconds.
-Solution (16 moves):
-    Move #0: yellow east, south, west
-Move #3: green south, west, north
-Move #6: blue east, north, west, south
-Move #10: yellow south, east, south
-Move #13: green west
-Move #14: yellow north
-*/
-
 int
 main (int argc, char *argv[])
 {
@@ -144,24 +83,41 @@ main (int argc, char *argv[])
 
     args_parse (&args, argc, argv);
 
-    client = rr_client_create (args.host, args.port, args.user);
-    if (client == NULL) {
-       fprintf (stderr, "Failed connecting to %s:%s as %s\n",
-                args.host, args.port, args.user);
-       return 1;
-    }
+    if (args.files) {
+       int i;
+       rr_board_t *board;
+       rrs_solution_t solution;
 
-    status = rr_client_join (client, GAME);
-    if (status == RR_STATUS_NO_GAME)
-       status = rr_client_new (client, GAME);
-    if (status) {
-       fprintf (stderr, "Error joining or creating game: %s\n", rr_status_str (status));
-       return 1;
-    }
+       for (i = 0; args.files[i]; i++) {
+           board = rr_board_create_from_file (args.files[i]);
+           if (board == NULL)
+               continue;
+           rrs_solution_init (&solution);
+           solve_board (board, &solution);
+           rrs_solution_print (&solution);
+           rrs_solution_fini (&solution);
+           rr_board_destroy (board);
+       }
+    } else {
+       client = rr_client_create (args.host, args.port, args.user);
+       if (client == NULL) {
+           fprintf (stderr, "Failed connecting to %s:%s as %s\n",
+                    args.host, args.port, args.user);
+           return 1;
+       }
 
-    handle_events (client);
+       status = rr_client_join (client, GAME);
+       if (status == RR_STATUS_NO_GAME)
+           status = rr_client_new (client, GAME);
+       if (status) {
+           fprintf (stderr, "Error joining or creating game: %s\n", rr_status_str (status));
+           return 1;
+       }
+
+       handle_events (client);
 
-    rr_client_destroy (client);
+       rr_client_destroy (client);
+    }
 
     return 0;
 }