Knight-Path 1.0.D018
|
00001 // 00002 // knight-path - shortest knight path between two squares 00003 // Copyright (C) 2011 Peter Miller 00004 // 00005 // This program is free software; you can redistribute it and/or modify 00006 // it under the terms of the GNU General Public License as published by 00007 // the Free Software Foundation; either version 3 of the License, or (at 00008 // your option) any later version. 00009 // 00010 // This program is distributed in the hope that it will be useful, 00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00013 // General Public License for more details. 00014 // 00015 // You should have received a copy of the GNU General Public License along 00016 // with this program. If not, see <http://www.gnu.org/licenses/>. 00017 // 00018 00019 #include <cstring> 00020 00021 #include <knight-path/solver/brute_force.h> 00022 #include <knight-path/solver/maze.h> 00023 #include <knight-path/solver/taxi.h> 00024 00025 00026 struct table_t 00027 { 00028 const char *name; 00029 solver::pointer (*create)(void); 00030 }; 00031 00032 static const table_t table[] = 00033 { 00034 { "brute-force", &solver_brute_force::create }, 00035 { "fastest", &solver_maze::create }, 00036 { "maze", &solver_maze::create }, 00037 { "taxi", &solver_taxi::create }, 00038 }; 00039 00040 00041 #define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0])) 00042 #define END_OF(a) ((a) + ARRAY_SIZE(a)) 00043 00044 00045 solver::pointer 00046 solver::factory(const char *name) 00047 { 00048 for (const table_t *tp = table; tp < END_OF(table); ++tp) 00049 { 00050 if (0 == strcmp(name, tp->name)) 00051 { 00052 return tp->create(); 00053 } 00054 } 00055 std::cerr << "solver algorithm \"" << name << "\" unknown" << std::endl; 00056 exit(EXIT_FAILURE); 00057 } 00058 00059 00060 void 00061 solver::list_algorithms(void) 00062 { 00063 for (const table_t *tp = table; tp < END_OF(table); ++tp) 00064 std::cout << tp->name << std::endl; 00065 }