KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > examples > gp > anttrail > Right


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.anttrail;
11
12 import org.jgap.*;
13 import org.jgap.gp.*;
14 import org.jgap.gp.impl.*;
15
16 /**
17  * Turn the ant right.
18  *
19  * @author Klaus Meffert
20  * @since 3.01
21  */

22 public class Right
23     extends AntCommand implements IMutateable {
24   /** String containing the CVS revision. Read out via reflection!*/
25   private final static String JavaDoc CVS_REVISION = "$Revision: 1.3 $";
26
27   public Right(final GPConfiguration a_conf)
28       throws InvalidConfigurationException {
29     super(a_conf);
30   }
31
32   public CommandGene applyMutation(int index, double a_percentage)
33       throws InvalidConfigurationException {
34     Left mutant = new Left(getGPConfiguration());
35     return mutant;
36   }
37
38   public void execute_void(ProgramChromosome a_chrom, int a_n, Object JavaDoc[] 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_LEFT;
44         break;
45       case AntMap.O_LEFT:
46         orient = AntMap.O_UP;
47         break;
48       case AntMap.O_RIGHT:
49         orient = AntMap.O_DOWN;
50         break;
51       case AntMap.O_UP:
52         orient = AntMap.O_RIGHT;
53         break;
54     }
55     map.setOrientation(orient);
56     map.IncrementMoveCounter();
57   }
58
59   public String JavaDoc toString() {
60     return "right";
61   }
62 }
63
Popular Tags