#ifndef __CDistribution_HPP__ #define __CDistribution_HPP__ /* "Species" - a CoreWars evolver. Copyright (C) 2003 'Varfar' * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the Free * Software Foundation; either version 1, or (at your option) any later * version. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 675 Mass Ave, Cambridge, MA 02139, USA. */ #include "ini.hpp" #include #include class CDistribution { /* utility provides a very configurable random number with a bias */ public: typedef CDistribution *(*ImplFactoryCallback)(const CDistribution ©); static CDistribution *ImplFactory(const CDistribution ©) { return new CDistribution(copy); } CDistribution(const std::string &context,const int min,const int max); ~CDistribution(); void set(const int min,const int max); // change this into a flat distribution between these points void read_ini(INIFile &ini,bool required = true); CDistribution *read_override_ini(INIFile &ini,ImplFactoryCallback factory=ImplFactory); void write_ini(std::ostream &os); void write_override_ini(std::ostream &os,const CDistribution *parent = 0); int rnd() const; /* return a random number within this distribution */ int min() const { return _data[0]; } int max() const { return _data[_size-1]; } bool ok(const int val) const { return ((min() <= val) && (val < max())); } private: CDistribution(); std::string _context; int _size, /* number of points in the data */ *_data; /* the actual series */ }; #endif // __CDistribution_HPP__