package langton;
public class LangtonAnt{
import simulation.Ant;
import simulation.Grid;
import simulation.Simulation;
import core.Direction;
/**
* Main method.
*
* You do not need to modify this method. It will not be part of the
* automated or hand marking
*
*/
public static void main(String[] args) {
// create a simulation with given parameters
Simulation sim = new Simulation(10, 10, 5, 5, Direction.NORTH, 10);
// while the simulation is not finished
while (!sim.isCompleted()) {
// get current board
Grid board = sim.cloneCurrentGrid();
// get current ant
Ant ant = sim.cloneCurrentAnt();
// print out the ant and board
System.out.print("+");
for (int j = 0; j < board.getWidth(); ++j) {
System.out.print("-");
}
System.out.println("+");
for (int i = 0; i < board.getHeight(); ++i) {
System.out.print("|");
for (int j = 0; j < board.getWidth(); ++j) {
if (i == ant.getIPos() && j == ant.getJPos()) {
switch (ant.getDirection()) {
case NORTH:
System.out.print("^");
break;
case SOUTH:
System.out.print("V");
break;
case EAST:
System.out.print(">");
break;
case WEST:
System.out.print("<");
break;
}
} else {
if (board.isWhite(i, j)) {
System.out.print(" ");
} else {
System.out.print("*");
}
}
}
System.out.println("|");
}
System.out.print("+");
for (int j = 0; j < board.getWidth(); ++j) {
System.out.print("-");
}
System.out.println("+");
/*
* make the computer wait 150 ms to make it easier to view the ant's
* progression
*/
try {
Thread.sleep(150);
} catch (InterruptedException e) {
// do nothing
}
// execute a step
sim.executeStep();
// buffer to make it easier to read
System.out.println();
}
}
}
}