1 #ifndef __CFitness_HPP__ 2 #define __CFitness_HPP__ 3 4 /* "Species" - a CoreWars evolver. Copyright (C) 2003 'Varfar' 5 * 6 * This program is free software; you can redistribute it and/or modify it 7 * under the terms of the GNU General Public License as published by the Free 8 * Software Foundation; either version 1, or (at your option) any later 9 * version. 10 * 11 * This program is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 14 * more details. 15 * 16 * You should have received a copy of the GNU General Public License along 17 * with this program; if not, write to the Free Software Foundation, Inc., 18 * 675 Mass Ave, Cambridge, MA 02139, USA. 19 */ 20 21 #include "ini.hpp" 22 #include <iostream> 23 24 class CFitness { /* manages the scoring that determines the fitness of a warrior based upon it's success in combat */ 25 public: 26 enum RESULT { 27 WIN, 28 TIE, 29 LOSE, 30 RESULT_LAST 31 }; 32 enum CAT { 33 ATTACK, 34 DEFENCE, 35 CAT_LAST 36 }; 37 typedef float NUM; 38 static const char *MNEMONIC_RESULT(const RESULT res); 39 static const char *MNEMONIC_CAT(const CAT cat); zero(NUM & num) const40 void zero(NUM &num) const { num = 0.0F; } score(const CAT,const RESULT res,const NUM weighting,NUM & num,int rounds)41 void score(const CAT /*cat*/,const RESULT res,const NUM weighting,NUM &num,int rounds) { /* adjust a score with this result */ 42 // if(cat == ATTACK) 43 num += ((_data[ATTACK][res] * weighting) * rounds); 44 /* else // DEFENCE 45 num -= ((_data[DEFENCE][res] * weighting) * rounds); //*/ 46 } 47 void read_ini(INIFile &ini); /* loads fitness values; values are REQUIRED */ 48 CFitness *read_override_ini(INIFile &ini); /* loads fitness values; if any fitness values are 49 specified, then a copy of this fitness will be made; all unspecified values in the new 50 class will be "inherited" from this one, and any specified values will be overriden. If nothing 51 is specified, then this will be returned */ 52 void write_ini(std::ostream &os); 53 void write_override_ini(std::ostream &os,const CFitness *parent); 54 protected: 55 NUM _data[CAT_LAST][RESULT_LAST]; 56 }; 57 58 #endif // __CFitness_HPP__ 59