Problem.
Fish needs to start at position x,y on a grid where ENV_ROWS is user defined and ENV_COLS = ENV_ROWS, the fish continues to move till it hits a wall, when it hits a wall the fish will turn right. The fish can turn if you use s1.changeDirection(Direction.SOUTH); when you change the direction it will run till you tell it to change directions again or it hits a wall. I need the fish to run starting at position 0,ENV_ROWS; It needs to run a path like this http://www.circlemakers.org/Img/square_spiral.jpg till it reaches the center.
Currently i can predefine its movements for an enviroment 11x11 using this
Location loc1 = new Location(env.numRows() - env.numCols(),env.numCols() - 1);
Location loc2 = new Location(env.numRows() -1,env.numCols() -2);
Location loc3 = new Location(env.numRows() - 2,env.numCols() - env.numRows());
Location loc4 = new Location(env.numRows() - env.numCols(),env.numCols() - 10);
Location loc5 = new Location(env.numRows() - (env.numRows() -1),env.numCols() -2);
Location loc6 = new Location(env.numRows() - 2,env.numCols() -3);
Location loc7 = new Location(env.numRows() - 3,env.numCols() -10);
Location loc8 = new Location(env.numRows() - 10,env.numCols() -9);
Location loc9 = new Location(env.numRows() - 9,env.numCols() -3);
Location loc10 = new Location(env.numRows() - 3,env.numCols() -4);
Location loc11 = new Location(env.numRows() - 4,env.numCols() -9);
Location loc12 = new Location(env.numRows() - 9,env.numCols() -8);
Location loc13 = new Location(env.numRows() - 8,env.numCols() -4);
Location loc14 = new Location(env.numRows() - 4,env.numCols() -5);
Location loc15 = new Location(env.numRows() - 5,env.numCols() -8);
Location loc16 = new Location(env.numRows() - 8,env.numCols() -7);
Location loc17 = new Location(env.numRows() - 7,env.numCols() -5);
Location loc18 = new Location(env.numRows() - 5,env.numCols() -6);
Location loc19 = new Location(env.numRows() - 6,env.numCols() -7);
Location loc20 = new Location(env.numRows() - 7,env.numCols() -6);
Location locend = new Location(env.numRows() - 6,env.numCols() -6);
if (s1.nextLocation().equals(loc1)) {
s1.changeDirection(Direction.SOUTH);
}
if (s1.nextLocation().equals(loc2)) {
s1.changeDirection(Direction.WEST);
}
if (s1.nextLocation().equals(loc3)) {
s1.changeDirection(Direction.NORTH);
}
if (s1.nextLocation().equals(loc4)) {
s1.changeDirection(Direction.EAST);
}
if (s1.nextLocation().equals(loc5)) {
s1.changeDirection(Direction.SOUTH);
}
if (s1.nextLocation().equals(loc6)) {
s1.changeDirection(Direction.WEST);
}
if (s1.nextLocation().equals(loc7)) {
s1.changeDirection(Direction.NORTH);
}
if (s1.nextLocation().equals(loc8)) {
s1.changeDirection(Direction.EAST);
}
if (s1.nextLocation().equals(loc9)) {
s1.changeDirection(Direction.SOUTH);
}
if (s1.nextLocation().equals(loc10)) {
s1.changeDirection(Direction.WEST);
}
if (s1.nextLocation().equals(loc11)) {
s1.changeDirection(Direction.NORTH);
}
if (s1.nextLocation().equals(loc12)) {
s1.changeDirection(Direction.EAST);
}
if (s1.nextLocation().equals(loc13)) {
s1.changeDirection(Direction.SOUTH);
}
if (s1.nextLocation().equals(loc14)) {
s1.changeDirection(Direction.WEST);
}
if (s1.nextLocation().equals(loc15)) {
s1.changeDirection(Direction.NORTH);
}
if (s1.nextLocation().equals(loc16)) {
s1.changeDirection(Direction.EAST);
}
if (s1.nextLocation().equals(loc17)) {
s1.changeDirection(Direction.SOUTH);
}
if (s1.nextLocation().equals(loc18)) {
s1.changeDirection(Direction.WEST);
}
if (s1.nextLocation().equals(loc19)) {
s1.changeDirection(Direction.NORTH);
}
if (s1.nextLocation().equals(loc20)) {
s1.changeDirection(Direction.EAST);
}
if (s1.location().equals(locend)) {
System.out.println("End!");
}
I need to have a fomula / function that does this automaticially based on the enviroment size so it always spirals. The steps that i can think of are,
if end of line
turn
line = maxline
if turn = 3(wich is the last one of a square)
decrease maxline
if turn = 0(new square) decrease maxline
maxline by default = square size(11)
so it do 0,10
then turn
then 0-10
then turn
then 0-10 then turn
then 0-9
turn again
then 0-8
and it keep like this
until maxline = 0
I can provide full code samples for what i have coded if this will help.