Homepage | Demos | Overview | Downloads | Tutorials | Reference | Credits |
RandomTrans.hGo to the documentation of this file.00001 //-*-c++-*- 00002 #ifndef INCLUDED_RandomTrans_h_ 00003 #define INCLUDED_RandomTrans_h_ 00004 00005 #include "Behaviors/Transitions/NullTrans.h" 00006 #include "Events/EventRouter.h" 00007 00008 //! A transition that fires immediately, randomly choosing one destination node to activate. 00009 00010 /*! This class should be extended in the following way: 00011 * 00012 * setHistoryLength(int n) to maintain a history of recent choices that are 00013 * not to be reused, i.e., drawing without replacement 00014 */ 00015 00016 class RandomTrans : public NullTrans { 00017 public: 00018 //! constructor 00019 RandomTrans(StateNode* destination, float weight=1); 00020 00021 //! constructor 00022 RandomTrans(const std::string& name, StateNode* destination, float weight=1); 00023 00024 //! Add a destination node with an optional weight. 00025 virtual void RandomTrans::addDestination(StateNode* destination) { 00026 addDestination(destination,1); } 00027 00028 void addDestination(StateNode* destination, float weight); 00029 00030 //! Firing this type of transition activates one destination node at random, 00031 //! instead of all nodes. 00032 virtual void fire(); 00033 00034 protected: 00035 //! constructor, only to be called by subclasses (which need to specify their own @a classname) 00036 RandomTrans(const std::string &classname, const std::string &instancename, 00037 StateNode* destination, float weight=1); 00038 00039 private: 00040 std::vector<float> weights; //!< the probably of selection for each source 00041 void addWeight(float weight); //!< adds a weight entry to the back of the queue 00042 }; 00043 00044 #endif |
Tekkotsu v2.2.2 |
Generated Tue Jan 4 15:43:15 2005 by Doxygen 1.4.0 |