#ifndef KINGDOM_HPP #define KINGDOM_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 "species.hpp" class CKingdomFile { friend class CKingdom; public: CKingdomFile(); protected: std::string _filename; FILE *_f; void writeKingdom(const CGeneration::NUM generation,const CWarrior::TUid uid); void readKingdom(CGeneration::NUM &generation,CWarrior::TUid &uid); }; class CKingdom { public: CKingdom(); ~CKingdom(); void load(const bool runnable = true); // if false, a lazy load is allowed void save(); void clear(); /* clears all the genera */ bool in_experiment() const { return _in_experiment; } int size() const { return _num_genera; } int coresize() const { return _coresize; } int processes() const { return _processes; } int cycles() const { return _cycles; } int minsep() const { return _minsep; } int rounds() const { return _rounds; } int pspacesize() const { return _pspacesize; } CWarrior::TUid TUid_NEXT() { return ++_uid; } CWarrior::TUid TUid_CUR() const { return _uid; } CGeneration::NUM generation() const { return _generation; } void set_generation(const CGeneration::NUM num); int num_genera() const { return _num_genera; } int num_evolving_species() const; int num_evolved_warriors() const; int num_warriors() const; /* returns a trivia number of warriors 'live' in the kingdom at this time */ void fight(); /* this will actually do all the fights for a generation */ CFitness *fitness() const { return _fitness; } CLength *length() const { return _length; } CInstGenerator *freq() const { return _freq; } COperand *operands() const { return _operands; } CReproduction *reproduction() const { return _reproduction; } CSpecies *benchmark() const { return _benchmark_species; } float benchmark_n() const { return _benchmark_n; } int benchmark_candidate() const { return _benchmark_candidate; } void core_check() const; const std::string &hill() const { return _hill; } const std::string &author() const { return _author; } const std::string &email() const { return _email; } CWarrior *warrior(const CWarrior::TUid uid) const; /* fetch a particular warrior from this kingdom; NULL if not present */ // array index accessors CGenus &genus(unsigned index) const; protected: bool _in_experiment; CFitness *_fitness; CLength *_length; CInstGenerator *_freq; COperand *_operands; CReproduction *_reproduction; int GEN_NEXT() { return ++_generation; } CGeneration::NUM _generation; CWarrior::TUid _uid; int _num_genera; CGenus **_genus, *_benchmark_genus; CSpecies *_benchmark_species; int _benchmark_candidate; float _benchmark_n; std::string _hill, _author, _email; bool _mars_prepared; void alloc_mars(); void dealloc_mars(); insn_t *_core; /* the actual mars core */ int /* key core metrics */ _coresize, /* size of core */ _processes, /* max. number of processes per warrior */ _cycles, /* cycles until tie */ _rounds, /* rounds per match */ _minsep, /* minimum separation between warriors */ _pspacesize; /* size of pspace */ CKingdomFile *_kingdom_file; void read_ini(INIFile &ini); void write_ini(std::ostream &os); }; #endif // ifdef KINGDOM_HPP