KickJava   Java API By Example, From Geeks To Geeks.

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


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
16 public class ReadBoard
17     extends CommandGene {
18   /** String containing the CVS revision. Read out via reflection!*/
19   private final static String JavaDoc CVS_REVISION = "$Revision: 1.2 $";
20
21   private Board m_board;
22
23   public ReadBoard(final GPConfiguration a_conf, Board a_board)
24       throws InvalidConfigurationException {
25     this(a_conf, a_board, 0, null);
26   }
27
28   public ReadBoard(final GPConfiguration a_conf, Board a_board,
29                    int a_subReturnType, int[] a_subChildTypes)
30       throws InvalidConfigurationException {
31     super(a_conf, 2, CommandGene.IntegerClass, a_subReturnType, a_subChildTypes);
32     m_board = a_board;
33   }
34
35   public String JavaDoc 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 JavaDoc getName() {
46     return "Read Board(x,y)";
47   }
48
49   public int execute_int(ProgramChromosome c, int n, Object JavaDoc[] 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 }
58
Popular Tags