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:
16: public class ReadBoard extends CommandGene {
17: /** String containing the CVS revision. Read out via reflection!*/
18: private final static String CVS_REVISION = "$Revision: 1.2 $";
19:
20: private Board m_board;
21:
22: public ReadBoard(final GPConfiguration a_conf, Board a_board)
23: throws InvalidConfigurationException {
24: this (a_conf, a_board, 0, null);
25: }
26:
27: public ReadBoard(final GPConfiguration a_conf, Board a_board,
28: int a_subReturnType, int[] a_subChildTypes)
29: throws InvalidConfigurationException {
30: super (a_conf, 2, CommandGene.IntegerClass, a_subReturnType,
31: a_subChildTypes);
32: m_board = a_board;
33: }
34:
35: public String toString() {
36: return "read_board(&1, &2)";
37: }
38:
39: /**
40: * @return textual name of this command
41: *
42: * @author Klaus Meffert
43: * @since 3.2
44: */
45: public String getName() {
46: return "Read Board(x,y)";
47: }
48:
49: public int execute_int(ProgramChromosome c, int n, Object[] args) {
50: check(c);
51: int x = c.execute_int(n, 0, args);
52: int y = c.execute_int(n, 1, args);
53: // Store in memory.
54: // ----------------
55: return m_board.readField(x, y);
56: }
57: }
|