1 | /*
|
---|
2 | Copyright 2006 by Sean Luke
|
---|
3 | Licensed under the Academic Free License version 3.0
|
---|
4 | See the file "LICENSE" for more information
|
---|
5 | */
|
---|
6 |
|
---|
7 |
|
---|
8 | package ec.app.ant.func;
|
---|
9 | import ec.*;
|
---|
10 | import ec.app.ant.*;
|
---|
11 | import ec.gp.*;
|
---|
12 | import ec.util.*;
|
---|
13 |
|
---|
14 | /*
|
---|
15 | * Right.java
|
---|
16 | *
|
---|
17 | * Created: Wed Nov 3 18:26:37 1999
|
---|
18 | * By: Sean Luke
|
---|
19 | */
|
---|
20 |
|
---|
21 | /**
|
---|
22 | * @author Sean Luke
|
---|
23 | * @version 1.0
|
---|
24 | */
|
---|
25 |
|
---|
26 |
|
---|
27 | public class Right extends GPNode implements EvalPrint
|
---|
28 | {
|
---|
29 | public String toString() { return "right"; }
|
---|
30 |
|
---|
31 | public void checkConstraints(final EvolutionState state,
|
---|
32 | final int tree,
|
---|
33 | final GPIndividual typicalIndividual,
|
---|
34 | final Parameter individualBase)
|
---|
35 | {
|
---|
36 | super.checkConstraints(state,tree,typicalIndividual,individualBase);
|
---|
37 | if (children.length!=0)
|
---|
38 | state.output.error("Incorrect number of children for node " +
|
---|
39 | toStringForError() + " at " +
|
---|
40 | individualBase);
|
---|
41 | }
|
---|
42 |
|
---|
43 | public void eval(final EvolutionState state,
|
---|
44 | final int thread,
|
---|
45 | final GPData input,
|
---|
46 | final ADFStack stack,
|
---|
47 | final GPIndividual individual,
|
---|
48 | final Problem problem)
|
---|
49 | {
|
---|
50 | Ant p = (Ant)problem;
|
---|
51 | switch (p.orientation)
|
---|
52 | {
|
---|
53 | case Ant.O_UP:
|
---|
54 | p.orientation = Ant.O_RIGHT;
|
---|
55 | break;
|
---|
56 | case Ant.O_LEFT:
|
---|
57 | p.orientation = Ant.O_UP;
|
---|
58 | break;
|
---|
59 | case Ant.O_DOWN:
|
---|
60 | p.orientation = Ant.O_LEFT;
|
---|
61 | break;
|
---|
62 | case Ant.O_RIGHT:
|
---|
63 | p.orientation = Ant.O_DOWN;
|
---|
64 | break;
|
---|
65 | default: // whoa!
|
---|
66 | state.output.fatal("Whoa, somehow I got a bad orientation! (" + p.orientation + ")");
|
---|
67 | break;
|
---|
68 | }
|
---|
69 | p.moves++;
|
---|
70 | }
|
---|
71 |
|
---|
72 | public void evalPrint(final EvolutionState state,
|
---|
73 | final int thread,
|
---|
74 | final GPData input,
|
---|
75 | final ADFStack stack,
|
---|
76 | final GPIndividual individual,
|
---|
77 | final Problem problem,
|
---|
78 | final int[][] map2)
|
---|
79 | {
|
---|
80 | eval(state,thread,input,stack,individual,problem);
|
---|
81 | }
|
---|
82 | }
|
---|
83 |
|
---|
84 |
|
---|
85 |
|
---|