1 
2 #ifndef GENUS_HPP
3 #define GENUS_HPP
4 
5 /* "Species" - a CoreWars evolver.  Copyright (C) 2003 'Varfar'
6  *
7  * This program is free software; you can redistribute it and/or modify it
8  * under the terms of the GNU General Public License as published by the Free
9  * Software Foundation; either version 1, or (at your option) any later
10  * version.
11  *
12  * This program is distributed in the hope that it will be useful, but WITHOUT
13  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15  * more details.
16  *
17  * You should have received a copy of the GNU General Public License along
18  * with this program; if not, write to the Free Software Foundation, Inc.,
19  * 675 Mass Ave, Cambridge, MA 02139, USA.
20  */
21 
22 #include "species.hpp"
23 
24 class CGenus: public CHookable {
25 	public:
26 		CGenus(CKingdom *kingdom,const std::string &name);
27 		~CGenus();
28 		void clear(); // removes all species from this genus */
29 		void read_ini(INIFile &ini); /* expects to be in the correct section */
30 		void write_ini(std::ostream &os);
31 		void save();
32 		void ready(); /* this will blank all fitness metrics preceeding the fighting of a generation */
33 		int fight(CGenus &enemy); /* this will actually do all the fights for a generation; returns number of rounds fought */
34 		CWarrior *selection(); /* this will do selection on all the warriors in this genus; returns pointer to the best */
name() const35 		const std::string name() const { return _name; }
num_species() const36 		int num_species() const { return _num_species; }
37 		int num_evolving_species() const;
38 		int num_evolved_warriors() const;
39 		int num_warriors() const; /* returns a trivia number of warriors 'live' in this genus at this time */
size() const40 		int size() const { return _num_species; }
kingdom() const41 		CKingdom *kingdom() const { return _kingdom; }
fitness() const42 		CFitness *fitness() const { return _fitness; }
length() const43 		CLength *length() const { return _length; }
freq() const44 		CInstGenerator *freq() const { return _freq; }
operands() const45 		COperand *operands() const { return _operands; }
reproduction() const46 		CReproduction *reproduction() const { return _reproduction; }
47 		CWarrior *warrior(const CWarrior::TUid uid) const; /* fetch a particular warrior from this genus; NULL if not present */
48 		// array access
49 		CSpecies &species(unsigned index) const;
50 	protected:
51 		CSpecies **_species;
52 		int _num_species;
53 		CKingdom *_kingdom;
54 		CFitness *_fitness; // might be referencing CKingdom::_fitness if not overriden
55 		CLength *_length; // might be referencing CKingdom::_length if not overriden
56 		CInstGenerator *_freq; // might be referencing CKingdom::_freq if not overriden
57 		COperand *_operands; // might be referencing CKingdom::_operands if not overriden
58 		CReproduction *_reproduction; // might be referencing CKingdom::_reproduction if not overriden
59 		std::string _name;
60 };
61 
62 #endif // ifndef GENUS_HPP
63