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.anttrail;
11:
12: import org.jgap.*;
13: import org.jgap.gp.*;
14: import org.jgap.gp.impl.*;
15:
16: /**
17: * Turn the ant left.
18: *
19: * @author Klaus Meffert
20: * @since 3.01
21: */
22: public class Left extends AntCommand implements IMutateable {
23: /** String containing the CVS revision. Read out via reflection!*/
24: private final static String CVS_REVISION = "$Revision: 1.3 $";
25:
26: public Left(final GPConfiguration a_conf)
27: throws InvalidConfigurationException {
28: super (a_conf);
29: }
30:
31: public CommandGene applyMutation(int index, double a_percentage)
32: throws InvalidConfigurationException {
33: Right mutant = new Right(getGPConfiguration());
34: return mutant;
35: }
36:
37: public void execute_void(ProgramChromosome a_chrom, int a_n,
38: Object[] a_args) {
39: AntMap map = getMap(a_chrom);
40: int orient = map.getOrientation();
41: switch (orient) {
42: case AntMap.O_DOWN:
43: orient = AntMap.O_RIGHT;
44: break;
45: case AntMap.O_LEFT:
46: orient = AntMap.O_DOWN;
47: break;
48: case AntMap.O_RIGHT:
49: orient = AntMap.O_UP;
50: break;
51: case AntMap.O_UP:
52: orient = AntMap.O_LEFT;
53: break;
54: }
55: map.setOrientation(orient);
56: map.IncrementMoveCounter();
57: }
58:
59: public String toString() {
60: return "left";
61: }
62: }
|