/*
 * World.java
 *
 * Created on 5 of December 2006, 2:20
 */
/**
 *
 * @author Eng. Paulo Roque Silva
 */
public class World {
    
    // The robot movement orientation
    final static int NORTH = 1,      // Move to North - DON'T CHANGE
                     EAST  = 2,      // Move to East  - DON'T CHANGE
                     SOUTH = 3,      // Move to South - DON'T CHANGE
                     WEST  = 4;      // Move to West  - DON'T CHANGE
    public static final int    EARTH = 1,  // World's Elements
                               WATER = 2,
                               FOOD  = 3;
    // Places in the World... (consider locals from 1 to 9)
    public static final int    WALL  = 10;
    // elements[local] gives food, water or earth
    int         []elements = {EARTH, EARTH, FOOD,
                              WATER, EARTH, EARTH,
                              EARTH, EARTH, EARTH};
    // place[local][orientation] gives the next local or WALL
    // local from 0 to 8; orientation from North to West clockwise
    int         [][]place = {{WALL,    2, WALL, WALL},
                             {WALL, WALL,    5,    1},
                             {WALL, WALL,    6, WALL},
                             {WALL, WALL,    7, WALL},
                             {   2, WALL,    8, WALL},
                             {   3, WALL,    9, WALL},
                             {   4,    8, WALL, WALL},
                             {   5,    9, WALL,    7},
                             {   6, WALL, WALL,    8}};
    // orientation[orientationBefore][roboTurn] gives the new orientation of the robot
    // orientationBefore: from North to West clockwise
    // roboTurn: 0 to turn left and 1 to turn right
    int         [][]orientation = {{ WEST,  EAST},
                                   {NORTH, SOUTH},
                                   { EAST,  WEST},
                                   {SOUTH, NORTH}};
    
    /** Creates a new instance of World */
    public World() {
    }

    // The Liberu moves forward...  from <localBefore> in the <orientation>
    //            returns the new <local> or WALL
    public int move(int localBefore, int orientation) {
        
        return place[localBefore-1][orientation-1];
    }
    
    // To which place gives the local element
    public int element(int local) {
        
        return elements[local-1];
    }
    
    // For a given orientationBefore and roboTurn returns the new orientation
    public int orientate(int orientationBefore, int roboTurn) {
        
        return orientation[orientationBefore - 1][roboTurn - Liberu.TURN_LEFT];
    }
    
    // For a given local and an orientation returns the next local at one movement in that direction
    public int vision(int local, int orientation) {
        
        return move(local, orientation);
    }
}
