KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > examples > gp > tictactoe > IsOwnColor


1 /*
2  * This file is part of JGAP.
3  *
4  * JGAP offers a dual license model containing the LGPL as well as the MPL.
5  *
6  * For licencing information please see the file license.txt included with JGAP
7  * or have a look at the top of class org.jgap.Chromosome which representatively
8  * includes the JGAP license policy applicable for any file delivered with JGAP.
9  */

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   /** String containing the CVS revision. Read out via reflection!*/
20   private final static String JavaDoc CVS_REVISION = "$Revision: 1.3 $";
21
22   private int m_color;
23
24   private int m_subChildType; // Only needed for cloning!
25

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 JavaDoc toString() {
40     return "isOwnColor(&1)";
41   }
42
43   public boolean execute_boolean(ProgramChromosome c, int n, Object JavaDoc[] args) {
44     check(c);
45     int color = c.execute_int(n, 0, args);
46     return color == m_color;
47   }
48
49   /**
50    * @return textual name of this command
51    *
52    * @author Klaus Meffert
53    * @since 3.2
54    */

55   public String JavaDoc getName() {
56     return "If Color";
57   }
58
59   public Object JavaDoc clone() {
60     try {
61       IsOwnColor result = new IsOwnColor(getGPConfiguration(), m_color,
62           getSubReturnType(), m_subChildType);
63       return result;
64     } catch (Throwable JavaDoc t) {
65       throw new CloneException(t);
66     }
67   }
68
69   public Class JavaDoc getChildType(IGPProgram a_ind, int a_chromNum) {
70     return CommandGene.IntegerClass;
71   }
72 }
73
Popular Tags