1 10 package examples.gp.anttrail; 11 12 19 public class AntMap { 20 21 private final static String CVS_REVISION = "$Revision: 1.5 $"; 22 23 public static final int ERROR = 0; 25 26 public static final int FOOD = -1; 27 28 public static final int EMPTY = 1; 29 30 public static final int TRAIL = 2; 31 32 public static final int ATE = 3; 33 34 public static final int O_UP = 0; 36 37 public static final int O_LEFT = 1; 38 39 public static final int O_DOWN = 2; 40 41 public static final int O_RIGHT = 3; 42 43 private int m_orientation; 44 45 private int m_posx; 46 47 private int m_posy; 48 49 private int m_foodTaken; 50 51 54 private int m_moves; 55 56 59 private int m_sizex; 60 61 64 private int m_sizey; 65 66 69 private int[][] m_map; 70 71 75 private int m_moveMod; 76 77 80 private boolean m_moveModUpper; 81 82 85 private int[][] m_movementMap; 86 87 90 private int m_maxMoves; 91 92 public AntMap(final int[][] a_map, int a_maxMoves) { 93 m_sizex = a_map.length; 94 m_sizey = a_map[0].length; 95 m_map = new int[m_sizex][m_sizey]; 96 for (int x = 0; x < m_sizex; x++) { 97 m_map[x] = (int[]) (a_map[x].clone()); 98 } 99 m_movementMap = new int[m_sizex][m_sizey]; 100 m_orientation = O_RIGHT; 101 m_posx = 0; 102 m_posy = 0; 103 m_moveMod = 0; 104 m_moveModUpper = false; 105 m_maxMoves = a_maxMoves; 106 storeMove(); 107 m_moves = 0; 108 } 109 110 public int[][] getMap() { 111 return m_map; 112 } 113 114 public int getFromMap(int a_x, int a_y) { 115 return m_map[a_x][a_y]; 116 } 117 118 122 public int getPosX() { 123 return m_posx; 124 } 125 126 public int getPosY() { 127 return m_posy; 128 } 129 130 public void setPosX(int a_value) { 131 m_posx = a_value; 132 storeMove(); 133 checkFoodTaken(); 134 } 135 136 public void setPosY(int a_value) { 137 m_posy = a_value; 138 storeMove(); 139 checkFoodTaken(); 140 } 141 142 private void storeMove() { 143 char c; 144 if (!m_moveModUpper) { 145 c = (char) (m_moveMod + 'a'); 146 if (m_moveMod++ >= 25) { 147 m_moveMod = 0; 148 m_moveModUpper = true; 149 } 150 } 151 else { 152 c = (char) (m_moveMod + 'A'); 153 if (m_moveMod++ >= 25) { 154 m_moveMod = 0; 155 m_moveModUpper = false; 156 } 157 } 158 m_movementMap[m_posx][m_posy] = c; 159 } 160 161 public int[][] getMovements() { 162 return m_movementMap; 163 } 164 165 private void checkFoodTaken() { 166 if (m_map[m_posx][m_posy] == AntMap.FOOD) { 167 m_foodTaken++; 168 m_map[m_posx][m_posy] = AntMap.ATE; 169 } 170 else { 171 } 174 } 175 176 public int getOrientation() { 177 return m_orientation; 178 } 179 180 public void setOrientation(int a_orientation) { 181 m_orientation = a_orientation; 182 } 183 184 public int getFoodTaken() { 185 return m_foodTaken; 186 } 187 188 public int getMoveCount() { 189 return m_moves; 190 } 191 192 public void IncrementMoveCounter() { 193 m_moves++; 194 if (m_moves > m_maxMoves) { 195 throw new IllegalStateException ("Maximum number of moves exceeded"); 196 } 197 } 198 199 public int getWidth() { 200 return m_sizex; 201 } 202 203 public int getHeight() { 204 return m_sizey; 205 } 206 207 } 208 | Popular Tags |