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 | * Left.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 | public class Left extends GPNode implements EvalPrint
|
---|
27 | {
|
---|
28 | public String toString() { return "left"; }
|
---|
29 |
|
---|
30 | public void checkConstraints(final EvolutionState state,
|
---|
31 | final int tree,
|
---|
32 | final GPIndividual typicalIndividual,
|
---|
33 | final Parameter individualBase)
|
---|
34 | {
|
---|
35 | super.checkConstraints(state,tree,typicalIndividual,individualBase);
|
---|
36 | if (children.length!=0)
|
---|
37 | state.output.error("Incorrect number of children for node " +
|
---|
38 | toStringForError() + " at " +
|
---|
39 | individualBase);
|
---|
40 | }
|
---|
41 |
|
---|
42 | public void eval(final EvolutionState state,
|
---|
43 | final int thread,
|
---|
44 | final GPData input,
|
---|
45 | final ADFStack stack,
|
---|
46 | final GPIndividual individual,
|
---|
47 | final Problem problem)
|
---|
48 | {
|
---|
49 | Ant p = (Ant)problem;
|
---|
50 | switch (p.orientation)
|
---|
51 | {
|
---|
52 | case Ant.O_UP:
|
---|
53 | p.orientation = Ant.O_LEFT;
|
---|
54 | break;
|
---|
55 | case Ant.O_LEFT:
|
---|
56 | p.orientation = Ant.O_DOWN;
|
---|
57 | break;
|
---|
58 | case Ant.O_DOWN:
|
---|
59 | p.orientation = Ant.O_RIGHT;
|
---|
60 | break;
|
---|
61 | case Ant.O_RIGHT:
|
---|
62 | p.orientation = Ant.O_UP;
|
---|
63 | break;
|
---|
64 | default: // whoa!
|
---|
65 | state.output.fatal("Whoa, somehow I got a bad orientation! (" + p.orientation + ")");
|
---|
66 | break;
|
---|
67 | }
|
---|
68 | p.moves++;
|
---|
69 | }
|
---|
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 |
|
---|