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 TransferBoardToMemory extends CommandGene {
17: /** String containing the CVS revision. Read out via reflection!*/
18: private final static String CVS_REVISION = "$Revision: 1.1 $";
19:
20: private Board m_board;
21:
22: private int m_startMemoryIndex;
23:
24: public TransferBoardToMemory(final GPConfiguration a_conf,
25: Board a_board, int a_startMemoryIndex)
26: throws InvalidConfigurationException {
27: this (a_conf, a_board, a_startMemoryIndex, 0);
28: }
29:
30: public TransferBoardToMemory(final GPConfiguration a_conf,
31: Board a_board, int a_startMemoryIndex, int a_subReturnType)
32: throws InvalidConfigurationException {
33: super (a_conf, 0, CommandGene.VoidClass, a_subReturnType, null);
34: m_board = a_board;
35: m_startMemoryIndex = a_startMemoryIndex;
36: }
37:
38: public String toString() {
39: return "transfer_Board_to_Mem(" + m_startMemoryIndex + ")";
40: }
41:
42: /**
43: * @return textual name of this command
44: *
45: * @author Klaus Meffert
46: * @since 3.2
47: */
48: public String getName() {
49: return "Transfer Board to Memory (index " + m_startMemoryIndex
50: + ")";
51: }
52:
53: /**
54: * Executes the command.
55: *
56: * @param c ProgramChromosome
57: * @param n ignored here
58: * @param args ignored here
59: *
60: * @author Klaus Meffert
61: * @since 3.2
62: */
63: public void execute_void(ProgramChromosome c, int n, Object[] args) {
64: check(c);
65: int index = m_startMemoryIndex;
66: for (int x = 0; x < Board.WIDTH; x++) {
67: for (int y = 0; y < Board.HEIGHT; y++) {
68: int boardValue = m_board.readField(x + 1, y + 1);
69: getGPConfiguration().storeIndexedMemory(index++,
70: new Integer(boardValue));
71: }
72: }
73: }
74: }
|