Free cookie consent management tool by TermsFeed Policy Generator

source: branches/OKBJavaConnector/ECJClient/src/ec/app/lawnmower/func/Mow.java @ 9449

Last change on this file since 9449 was 6152, checked in by bfarka, 14 years ago

added ecj and custom statistics to communicate with the okb services #1441

File size: 2.2 KB
Line 
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
8package ec.app.lawnmower.func;
9import ec.*;
10import ec.app.lawnmower.*;
11import ec.gp.*;
12import ec.util.*;
13
14/*
15 * Mow.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
26public class Mow extends GPNode
27    {
28    public String toString() { return "mow"; }
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        Lawnmower p = (Lawnmower)problem;
50        LawnmowerData d = (LawnmowerData)input;
51
52        switch (p.orientation)
53            {
54            case Lawnmower.O_UP:
55                p.posy--;
56                if (p.posy<0) p.posy = p.maxy-1;
57                break;
58            case Lawnmower.O_LEFT:
59                p.posx--;
60                if (p.posx<0) p.posx = p.maxx-1;
61                break;
62            case Lawnmower.O_DOWN:
63                p.posy++;
64                if (p.posy>=p.maxy) p.posy=0;
65                break;
66            case Lawnmower.O_RIGHT:
67                p.posx++;
68                if (p.posx>=p.maxx) p.posx=0;
69                break;
70            default:  // whoa!
71                state.output.fatal("Whoa, somehow I got a bad orientation! (" + p.orientation + ")");
72                break;
73            }
74
75        p.moves++;
76        if (p.map[p.posx][p.posy]==Lawnmower.UNMOWED)
77            {
78            p.sum++;
79            p.map[p.posx][p.posy] = p.moves;
80            }
81
82        // return [0,0]
83        d.x = 0;
84        d.y = 0;
85        }
86    }
87
88
89
Note: See TracBrowser for help on using the repository browser.