src/GeneticCode.h

Go to the documentation of this file.
00001 
00008 /*
00009 This file is part of Teapot Colony Wars.
00010 
00011 Teapot Colony Wars is free software: you can redistribute it and/or modify
00012 it under the terms of the GNU General Public License as published by
00013 the Free Software Foundation, either version 2 of the License, or
00014 (at your option) any later version.
00015 
00016 Teapot Colony Wars is distributed in the hope that it will be useful,
00017 but WITHOUT ANY WARRANTY; without even the implied warranty of
00018 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00019 GNU General Public License for more details.
00020 
00021 You should have received a copy of the GNU General Public License
00022 along with Teapot Colony Wars.  If not, see <http://www.gnu.org/licenses/>.
00023 */
00024 
00025 #ifndef GENETICCODE_H
00026 #define GENETICCODE_H
00027 
00028 #include "Constants.h"
00029 
00031 #define NB_BITS_AGGRESSIVENESS 2
00032 
00034 #define NB_BITS_GREEDY         2
00035 
00037 #define NB_BITS_REASONABLE     1
00038 
00040 #define NB_BITS_GENETICCODE   (NB_BITS_SIZE + NB_BITS_AGGRESSIVENESS + NB_BITS_GREEDY + NB_BITS_REASONABLE)
00041 
00045 class GeneticCode 
00046 {
00047 
00058   union __code {
00059 
00070     struct _bitfield {
00071       unsigned size :           NB_BITS_SIZE;           
00072       unsigned aggressiveness : NB_BITS_AGGRESSIVENESS; 
00073       unsigned greedy :         NB_BITS_GREEDY;         
00074       unsigned reasonable :     NB_BITS_REASONABLE;     
00075     } bitfield;
00076 
00078     unsigned value : NB_BITS_GENETICCODE;
00079 
00080   } _code;
00081 
00082 public:
00083 
00087   GeneticCode();
00088 
00094   GeneticCode(GeneticCode const * c);
00095 
00099   virtual ~GeneticCode();
00100 
00106   inline unsigned int getSize() { return _code.bitfield.size; }
00107 
00113   inline unsigned int getAggressiveness() { return _code.bitfield.aggressiveness; }
00114 
00120   inline unsigned int getGreedy() { return _code.bitfield.greedy; }
00121 
00122 
00128   inline unsigned int getReasonable() { return _code.bitfield.reasonable; }
00129 
00135   GeneticCode * mutate() const;
00136 
00143   GeneticCode * crossover(GeneticCode * c) const;
00144 
00148   void print();
00149 
00150 };
00151 
00152 
00153 #endif // GENETICCODE_H

Generated on Sat Feb 2 22:22:54 2008 for Teapot Colony Wars by  doxygen 1.5.4