// 7:06 PM Sunday, February 24, 2008 // I just started. As a side note, notepad++ is awesome. // 7:17 PM Sunday, February 24, 2008 // I finished. // 7:26 PM Sunday, February 24, 2008 // I like comments. public class MemRobot extends Robot { // Hey, java concepts says 0 and 1 AREN'T magic numbers. static final int I_HAVENT_BEEN_HERE = 0; static final int I_HAVE_BEEN_HERE = 1; // Me too. private int IveBeenHere[][]; // lol, hacks. private int wx; private int wy; public MemRobot(int MazeWidth, int MazeHeight, int initialx, int initialy) { // It's "initially". Learn to spell. // Actually i take that back, at least i didn't make // ypos as "posy". super(initialx, initialy); // Oh man, almost forget ints in Java DON'T have garbage // values when initialized. Java is crazy. IveBeenHere = new int[MazeHeight][MazeWidth]; // This DOESN'T tell you what wx and wy does wx = initialx; wy = initialy; } // 1 = Dead End // 2 = No Intersection // >= 3 = Intersection. // I like how i used constants for "IveBeenHere" but not for this. private int AtIntersection(int MazeArray[][]) { // count number of available movement spaces int Count = 0; // All the curly braces for the if statements except the last pair are unneccesary. // check the left if (MazeArray[ypos][xpos + 1] == Maze.EMPTY) { Count++; } // check the right if (MazeArray[ypos][xpos - 1] == Maze.EMPTY) { Count++; } // check the bottom if (MazeArray[ypos + 1][xpos] == Maze.EMPTY) { Count++; } // check the top if (MazeArray[ypos - 1][xpos] == Maze.EMPTY) { Count++; } // this is a useless if statement. Eh, i think i'll comment it out. //if (Count >= 0) //{ // What does wx and wy mean? Who knows? Do you?! wx = xpos; wy = ypos; //} return Count; } public void move(Maze m) { // My robot HAVE BEEN HERE. IveBeenHere[ypos][xpos] = I_HAVE_BEEN_HERE; // Yes! let's make MORE copies of the maze! int MazeArray = m.getMaze(); // Terrible name choice. int MoveChoices = AtIntersection(MazeArray); // 1 = Dead End // 2 = No Intersection // >= 3 = Intersection. // I should just copy and paste the same code for when MoveChoices // equals 3 instead of handling both. if (MoveChoices == 2 || MoveChoices == 3) { // Ctrl-c, Ctrl-v. // Modified to "else-if" because i only want ONE of these. // All the curly braces for the if statements except the last pai... // check the left if (MazeArray[ypos][xpos + 1] == Maze.EMPTY && MazeArray[ypos][xpos + 1] == I_HAVENT_BEEN_HERE) { // Because xpos++ doesn't cut it anymore xpos += 1; } // check the right else if (MazeArray[ypos][xpos - 1] == Maze.EMPTY && MazeArray[ypos][xpos - 1] == I_HAVENT_BEEN_HERE) { // because xpos-- doesn't cut it anymore xpos -= 1; } // check the bottom else if (MazeArray[ypos + 1][xpos] == Maze.EMPTY && MazeArray[ypos + 1][xpos] == I_HAVENT_BEEN_HERE) { // OH SH-, i regret making these comments if we have to print them out. ypos += 1; } // check the top else if (MazeArray[ypos - 1][xpos] == Maze.EMPTY && MazeArray[ypos - 1][xpos] == I_HAVENT_BEEN_HERE)) { // Funny how this means "up" even though you're subtracting. ypos -= 1; } } // eh, 2 and 3 > 1. if (MoveChoices == 1) { // so THAT'S what wx and wy does! // (it means "warp"x and "warp"y) // This is also a terrible work around for the problem. xpos = wx; ypos = wy; } // I am a useless comment. return; } }