00001 00027 #ifndef MSMAZES_CORE_FSM_BUILDER_N_BIT_HPP 00028 #define MSMAZES_CORE_FSM_BUILDER_N_BIT_HPP 00029 00030 #define MSMAZES_CORE_FSM_ARITY 6 00031 00032 // BOOST_PP_LESS 00033 #include <boost/preprocessor/comparison/less.hpp> 00034 // boost::remove_const 00035 #include <boost/type_traits/remove_const.hpp> 00036 // boost::remove_reference 00037 #include <boost/type_traits/remove_reference.hpp> 00038 // boost::mpl::apply1 00039 #include <boost/mpl/apply.hpp> 00040 // boost::random_number_generator 00041 #include <boost/random/random_number_generator.hpp> 00042 // Boost.Parameter keyword objects used by the Core FSM Layer 00043 #include <msmazes/core/fsm/keywords.hpp> 00044 00045 #if BOOST_PP_LESS(BOOST_PARAMETER_MAX_ARITY, MSMAZES_CORE_FSM_ARITY) 00046 #error Set BOOST_PARAMETER_MAX_ARITY to 6 or higher. 00047 #endif 00048 00049 // msmazes::FSMDirectionInputMaker 00050 #include <msmazes/core/fsm/input/maker_direction.hpp> 00051 // msmazes::FSMBuilder 00052 #include <msmazes/core/fsm/builder.hpp> 00053 // msmazes::MazeMakerTraits 00054 #include <msmazes/core/maze/traits_maker.hpp> 00055 // msmazes::NBitPattern 00056 #include <msmazes/core/pattern/n_bit.hpp> 00057 00058 namespace msmazes { 00059 namespace _n_bit_builder { 00060 00065 struct parameters 00066 : boost::parameter::parameters< 00067 boost::parameter::required<keyword_tag::rng_engine_arg> 00068 , boost::parameter::required<keyword_tag::maze_maker_arg> 00069 , boost::parameter::required<keyword_tag::init_bit_count_arg> 00070 , boost::parameter::required<keyword_tag::init_entrance_cell_arg> 00071 , boost::parameter::required<keyword_tag::init_exit_cell_arg> 00072 , boost::parameter::optional<keyword_tag::maze_policy_arg> 00073 > 00074 { 00075 }; 00076 } // namespace _n_bit_builder 00077 00079 00175 template < 00176 #ifndef MSMAZES_DOX 00177 typename CellContainerSelector = boost::vecS 00178 , typename Block = unsigned long 00179 , typename Allocator = std::allocator<Block> 00180 #endif /* MSMAZES_DOX */ 00181 > 00182 class NBitFSMBuilder 00183 #ifndef MSMAZES_DOX 00184 : public FSMBuilder< 00185 NBitPattern< 00186 CellContainerSelector 00187 , Block 00188 , Allocator 00189 > 00190 > 00191 #endif /* MSMAZES_DOX */ 00192 { 00193 #ifndef MSMAZES_DOX 00194 private: 00195 typedef FSMBuilder< 00196 NBitPattern< 00197 CellContainerSelector 00198 , Block 00199 , Allocator 00200 > 00201 > 00202 ParentBuilder; 00203 #endif /* MSMAZES_DOX */ 00204 00205 public: 00211 #ifdef MSMAZES_DOX 00212 typedef implementation_defined StateIndex; 00213 #else 00214 typedef typename ParentBuilder::StateIndex 00215 StateIndex; 00216 #endif /* MSMAZES_DOX */ 00217 00223 #ifdef MSMAZES_DOX 00224 typedef implementation_defined InputIndex; 00225 #else 00226 typedef typename ParentBuilder::InputIndex 00227 InputIndex; 00228 #endif /* MSMAZES_DOX */ 00229 00235 #ifdef MSMAZES_DOX 00236 typedef implementation_defined MazeGraph; 00237 #else 00238 typedef typename ParentBuilder::MazeGraph 00239 MazeGraph; 00240 #endif /* MSMAZES_DOX */ 00241 00247 #ifdef MSMAZES_DOX 00248 typedef implementation_defined Pattern; 00249 #else 00250 typedef typename ParentBuilder::Pattern 00251 Pattern; 00252 #endif /* MSMAZES_DOX */ 00253 00259 #ifdef MSMAZES_DOX 00260 typedef implementation_defined Cell; 00261 #else 00262 typedef typename ParentBuilder::Cell 00263 Cell; 00264 #endif /* MSMAZES_DOX */ 00265 00272 #ifdef MSMAZES_DOX 00273 typedef implementation_defined Direction; 00274 #else 00275 typedef typename ParentBuilder::Direction 00276 Direction; 00277 #endif /* MSMAZES_DOX */ 00278 00285 #ifdef MSMAZES_DOX 00286 typedef implementation_defined ArgumentValidationPolicy; 00287 #else 00288 typedef typename ParentBuilder::ArgumentValidationPolicy 00289 ArgumentValidationPolicy; 00290 #endif /* MSMAZES_DOX */ 00291 00292 private: 00293 NBitFSMBuilder(const NBitFSMBuilder& copy) 00294 { 00295 } 00296 00297 public: 00299 00303 NBitFSMBuilder() 00304 : ParentBuilder() 00305 { 00306 } 00307 00309 00312 virtual ~NBitFSMBuilder() 00313 { 00314 } 00315 00316 public: 00317 #ifdef MSMAZES_DOX 00318 00411 template < 00412 typename RNGEngine 00413 , typename MazeMaker 00414 , typename MazePolicy 00415 > 00416 bool initialize( 00417 RNGEngine& rng_engine_arg 00418 , const MazeMaker& maze_maker_arg 00419 , const unsigned long init_bit_count_arg 00420 , const unsigned long init_bit_count_arg 00421 , const unsigned long init_bit_count_arg 00422 , const MazePolicy& maze_policy_arg 00423 ); 00424 00431 template <typename Params> 00432 bool initialize_with_named_params(Params& p) 00433 #else 00434 BOOST_PARAMETER_MEMFUN( 00435 bool 00436 , initialize 00437 , 4 00438 , 5 00439 , _n_bit_builder::parameters 00440 ) 00441 #endif /* MSMAZES_DOX */ 00442 { 00443 typedef typename boost::remove_const< 00444 typename boost::remove_reference< 00445 typename boost::parameter::binding< 00446 Params 00447 , keyword_tag::rng_engine_arg 00448 >::type 00449 >::type 00450 >::type 00451 RNGEngine; 00452 typedef boost::random_number_generator<RNGEngine,Direction> 00453 Shuffler; 00454 typedef typename boost::remove_const< 00455 typename boost::remove_reference< 00456 typename boost::parameter::binding< 00457 Params 00458 , keyword_tag::maze_maker_arg 00459 >::type 00460 >::type 00461 >::type 00462 MazeMaker; 00463 00464 RNGEngine& rng_engine = p[rng_engine_arg]; 00465 Shuffler shuffler(rng_engine); 00466 00467 return 00468 ParentBuilder::initialize( 00469 rng_engine 00470 , p[maze_maker_arg] 00471 , FSMDirectionInputMaker() 00472 , p[ 00473 maze_policy_arg 00474 | typename MazeMakerTraits<MazeMaker>::DefaultPolicy() 00475 ] 00476 , ( 00477 init_bit_count_arg 00478 = p[init_bit_count_arg] 00479 , init_entrance_cell_arg 00480 = p[init_entrance_cell_arg] 00481 , init_entrance_direction_arg 00482 = shuffler(p[init_bit_count_arg]) 00483 , init_exit_cell_arg 00484 = p[init_exit_cell_arg] 00485 , init_exit_direction_arg 00486 = shuffler(p[init_bit_count_arg]) 00487 ) 00488 ); 00489 } 00490 00496 inline const Pattern& getPattern() const 00497 { 00498 return ParentBuilder::getPattern(); 00499 } 00500 00506 inline const MazeGraph& getMazeGraph() const 00507 { 00508 return ParentBuilder::getMazeGraph(); 00509 } 00510 00516 inline bool isReady() const 00517 { 00518 return ParentBuilder::isReady(); 00519 } 00520 00527 template <typename TransitionFunction> 00528 void 00529 buildTransitionFunction( 00530 TransitionFunction& transition_function 00531 ) const 00532 { 00533 ParentBuilder::buildTransitionFunction(transition_function); 00534 } 00535 00541 inline StateIndex getSourceState() const 00542 { 00543 return ParentBuilder::getSourceState(); 00544 } 00545 00551 inline StateIndex getTargetState() const 00552 { 00553 return ParentBuilder::getTargetState(); 00554 } 00555 00562 bool hasSolutionFromState(const StateIndex source_state) const 00563 { 00564 return ParentBuilder::hasSolutionFromState(source_state); 00565 } 00566 00572 InputIndex getCorrectInput(const StateIndex source_state) const 00573 { 00574 return ParentBuilder::getCorrectInput(source_state); 00575 } 00576 00582 const Cell& getStateCell(const StateIndex state) const 00583 { 00584 return ParentBuilder::getStateCell(state); 00585 } 00586 00593 Direction getStateDirection(const StateIndex state) const 00594 { 00595 return ParentBuilder::getStateDirection(state); 00596 } 00597 }; 00598 } // namespace msmazes 00599 00600 #undef MSMAZES_CORE_FSM_ARITY 00601 00602 #endif /* MSMAZES_CORE_FSM_BUILDER_N_BIT_HPP */
Multi-State Mazes in C++ is hosted by . Use the Table of Contents for navigation.