1 10 package examples.gp.tictactoe; 11 12 import org.jgap.gp.*; 13 import org.jgap.*; 14 import org.jgap.gp.impl.*; 15 import org.jgap.util.*; 16 17 public class IsOwnColor 18 extends CommandGene implements ICloneable { 19 20 private final static String CVS_REVISION = "$Revision: 1.3 $"; 21 22 private int m_color; 23 24 private int m_subChildType; 26 public IsOwnColor(final GPConfiguration a_conf, int a_color) 27 throws InvalidConfigurationException { 28 this(a_conf, a_color, 0, 0); 29 } 30 31 public IsOwnColor(final GPConfiguration a_conf, int a_color, 32 int a_subReturnType, int a_subChildType) 33 throws InvalidConfigurationException { 34 super(a_conf, 1, CommandGene.BooleanClass, a_subReturnType, a_subChildType); 35 m_subChildType = a_subChildType; 36 m_color = a_color; 37 } 38 39 public String toString() { 40 return "isOwnColor(&1)"; 41 } 42 43 public boolean execute_boolean(ProgramChromosome c, int n, Object [] args) { 44 check(c); 45 int color = c.execute_int(n, 0, args); 46 return color == m_color; 47 } 48 49 55 public String getName() { 56 return "If Color"; 57 } 58 59 public Object clone() { 60 try { 61 IsOwnColor result = new IsOwnColor(getGPConfiguration(), m_color, 62 getSubReturnType(), m_subChildType); 63 return result; 64 } catch (Throwable t) { 65 throw new CloneException(t); 66 } 67 } 68 69 public Class getChildType(IGPProgram a_ind, int a_chromNum) { 70 return CommandGene.IntegerClass; 71 } 72 } 73 | Popular Tags |