random.hpp

Go to the documentation of this file.
00001 /* $Id: random.hpp 25481 2008-04-02 22:10:35Z jhinrichs $ */
00002 /*
00003    Copyright (C) 2003 by David White <dave@whitevine.net>
00004    Copyright (C) 2005 - 2008 by Yann Dirson <ydirson@altern.org>
00005    Part of the Battle for Wesnoth Project http://www.wesnoth.org/
00006 
00007    This program is free software; you can redistribute it and/or modify
00008    it under the terms of the GNU General Public License version 2
00009    or at your option any later version.
00010    This program is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY.
00012 
00013    See the COPYING file for more details.
00014 */
00015 
00016 //! @file random.hpp
00017 //!
00018 
00019 #ifndef RANDOM_H_INCLUDED
00020 #define RANDOM_H_INCLUDED
00021 
00022 #include "SDL_types.h"
00023 
00024 class config;
00025 
00026 int get_random();
00027 const config* get_random_results();
00028 void set_random_results(const config& cfg);
00029 
00030 class rng
00031 {
00032 public:
00033     rng();
00034     int get_random();
00035 
00036     const config* get_random_results();
00037     void set_random_results(const config& cfg);
00038 
00039 protected:
00040     config* random();
00041     void set_random(config*);
00042 
00043 private:
00044     config* random_;
00045     size_t random_child_;
00046 };
00047 
00048 struct set_random_generator {
00049     set_random_generator(rng* r);
00050     ~set_random_generator();
00051 
00052 private:
00053     rng* old_;
00054 };
00055 
00056 class simple_rng
00057 {
00058 public:
00059     simple_rng();
00060     simple_rng(const config& cfg);
00061 
00062     //! Get a new random number.
00063     int get_random();
00064 
00065     //! Seeds the random pool.
00066     void seed_random(const unsigned call_count = 0);
00067     //! Seeds the random pool.
00068     void seed_random(const int seed, const unsigned call_count = 0);
00069 
00070     //! Resets the random to the 0 calls and the seed to the random
00071     //! this way we stay in the same sequence but don't have a lot
00072     //! calls. Used when moving to the next scenario.
00073     void rotate_random()
00074         { random_seed_ = random_pool_; random_calls_ = 0; }
00075 
00076 
00077     int get_random_seed() const { return random_seed_; }
00078     int get_random_calls() const { return random_calls_; }
00079 
00080 private:
00081     //! Initial seed for the pool.
00082     int random_seed_;
00083 
00084     //! State for the random pool.
00085     int random_pool_;
00086 
00087     //! Number of time a random number is generated.
00088     unsigned random_calls_;
00089 
00090     //! Sets the next random number in the pool.
00091     void random_next();
00092 };
00093 
00094 #endif

Generated by doxygen 1.5.5 on 23 May 2008 for The Battle for Wesnoth
Gna! | Forum | Wiki | CIA | devdocs