1 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 17 extends CommandGene { 18 19 private final static String CVS_REVISION = "$Revision: 1.1 $"; 20 21 private Board m_board; 22 23 private int m_startMemoryIndex; 24 25 public TransferBoardToMemory(final GPConfiguration a_conf, Board a_board, 26 int a_startMemoryIndex) 27 throws InvalidConfigurationException { 28 this(a_conf, a_board, a_startMemoryIndex, 0); 29 } 30 31 public TransferBoardToMemory(final GPConfiguration a_conf, Board a_board, 32 int a_startMemoryIndex, int a_subReturnType) 33 throws InvalidConfigurationException { 34 super(a_conf, 0, CommandGene.VoidClass, a_subReturnType, null); 35 m_board = a_board; 36 m_startMemoryIndex = a_startMemoryIndex; 37 } 38 39 public String toString() { 40 return "transfer_Board_to_Mem(" + m_startMemoryIndex + ")"; 41 } 42 43 49 public String getName() { 50 return "Transfer Board to Memory (index " + m_startMemoryIndex + ")"; 51 } 52 53 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++, new Integer (boardValue)); 70 } 71 } 72 } 73 } 74 | Popular Tags |