01: /*
02: * This file is part of JGAP.
03: *
04: * JGAP offers a dual license model containing the LGPL as well as the MPL.
05: *
06: * For licencing information please see the file license.txt included with JGAP
07: * or have a look at the top of class org.jgap.Chromosome which representatively
08: * includes the JGAP license policy applicable for any file delivered with JGAP.
09: */
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 extends CommandGene implements ICloneable {
18: /** String containing the CVS revision. Read out via reflection!*/
19: private final static String CVS_REVISION = "$Revision: 1.3 $";
20:
21: private int m_color;
22:
23: private int m_subChildType; // Only needed for cloning!
24:
25: public IsOwnColor(final GPConfiguration a_conf, int a_color)
26: throws InvalidConfigurationException {
27: this (a_conf, a_color, 0, 0);
28: }
29:
30: public IsOwnColor(final GPConfiguration a_conf, int a_color,
31: int a_subReturnType, int a_subChildType)
32: throws InvalidConfigurationException {
33: super (a_conf, 1, CommandGene.BooleanClass, a_subReturnType,
34: 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,
44: Object[] args) {
45: check(c);
46: int color = c.execute_int(n, 0, args);
47: return color == m_color;
48: }
49:
50: /**
51: * @return textual name of this command
52: *
53: * @author Klaus Meffert
54: * @since 3.2
55: */
56: public String getName() {
57: return "If Color";
58: }
59:
60: public Object clone() {
61: try {
62: IsOwnColor result = new IsOwnColor(getGPConfiguration(),
63: m_color, getSubReturnType(), m_subChildType);
64: return result;
65: } catch (Throwable t) {
66: throw new CloneException(t);
67: }
68: }
69:
70: public Class getChildType(IGPProgram a_ind, int a_chromNum) {
71: return CommandGene.IntegerClass;
72: }
73: }
|