Hi I am a begginner in java and have an assignment to simulate a Langton Ant. Would like some help where to start.
package simulation; /** * * Simulation class * * */ public class Simulation { public int height ; public int width; public int antStartI; public int antStartJ; public String originalDirection; /* @param height - the height of the grid * @param width - the width of the grid * @param antStartI - the original I coordinate of the ant * @param antStartJ - the original J coordinate of the ant * @param originalDirection - the original direction the ant is facing */ public Simulation(int height, int width, int antStartI, int antStartJ, Direction originalDirection, int maxTimeSteps) { height = height; width = width; antStartI = antStartI; antStartJ = antStartJ; originalDirection = originalDirection; } /** * Execute a time step for the simulation. * * The ant must: * * move forward 1 space * - if this movement would cause it to move off the grid, * the simulation is completed. * * rotate depending on the state of the cell the ant is occupying * - if the cell is white, rotate left * - otherwise, rotate right * * change the state of the cell the ant is currently occupying * - if the cell is white, it becomes black * - otherwise, it becomes white * * NOTE: this method should do nothing if the simulation is completed. */ public void executeStep() { switch (direction) { case NORTH: ; break; case SOUTH: ; break; case EAST: ; break; case WEST: ; break; } } /** * Method to check if the simulation is completed. * * The simulation is completed if and only if: * * it has reached the maximum time steps allowed * * the ant has moved off the grid * * @return true - the simulation is completed * @return false - the simulation is not completed */ public boolean isCompleted() { // TODO fill in this method } /** * Method to return a copy of the current grid. * * You should always return a copy of an object if you do not * want your base object to be changed by any code calling this method. * * @return a clone of the grid. */ public Grid cloneCurrentGrid() { // TODO fill in this method } /** * Method to return a copy of the current ant. * * You should always return a copy of an object if you do not * want your base object to be changed by any code calling this method. * * NOTE: Do not canche this value, return a new object for every call. * * @return a clone of the ant. */ public Ant cloneCurrentAnt() { // TODO fill in this method } }
I tried to write execute step but have know idea of hw to set the ant's next position regarding its direction. Any ideas?