Problem: No matter what I did in terms of editing the panel, nothing showed up.
Solution: After declaring all the colours and foregrounds and backgrounds of all the little buttons, I redeclared it, which cleared everything beforehand. Whoops.
Problem: I had the board game up a couple weeks ago! And then, when I tried to convert it to a 2-D array, it failed and will only added three times.
Solution: I missed four characters in the answer that he gave me. OMR. Such an idiot. I even double checked it like......10 times! And then I emailed him back! SHEESH! He says that array.length find the number of rows, while array[row].length finds the number of columns in the row that is being looked at. Now this all makes sense....if only I knew that before. Well. That's drilled into my brain hard enough!
Problem: The program just kept throwing an arrayOutOfBoundsEcxeption, constantly crashing.
Solution: I realized I was using a counter with the value of 20, when the array only went up to index 19.
Problem: The recursion is only happening a couple times. I thought it was supposed to continue it until it hits the exit. But, instead, it's going up in like increments of one or two, so the first time, it runs once, and then the second time, it runs twice.
Solution: Something wrong with the recursion because it was doing it all wrong. I didn't account for whether it was going to hit a boundary (because it was on the edge) and a lot of other things. With Ryk's help, I've fixed it though.
Problem: The mazes' solution feels compelled to jump two or more squares just because it's so naughty.
Solution: The tried variable, the one that judges which direction the maze can or cannot go (example: at the corner, there are only 2 directions that it may go) was increased at the wrong time, therein, when the recursion goes backwards, it tries another direction.
Problem: The program would create a maze the first time it was run. After solving it, when you pressed "Create Maze" again, the new maze would not be a maze. It was either half a maze with no entrance or no exit - or no maze at all. When the "Solve Maze" button was clicked, the good pathway would be shown, but with no valid entrances or exits!
Solution: The first time the refresh method was called, it updated the board. And not realizing it was already called, I called it again, causing it to be recalled, and entire board overwritten. I found this out by putting in tracing statements, and seeing duplicate lines of code. Upon looking at the mouseClicked method, the solution to this was obvious.
Problem: No matter what I did when I pressed solve maze, it wasn't doing anything.
Solution: I put tracing statements in almost all the places possible, and finally realized that the program was running, it's just that it was redoing the same piece of code, so it ended in the same. But all the tracing statements that I typed out were, in fact displayed to the screen. Just because of the duplication of the gameBoard method, it was overwriting everything.
"Uses recursion and describes problems encountered in creating and testing it"
Problem 1:
When I was creating the maze, it was quite difficult because when creating the pathway, I kept running into problems. The pathway would sometimes backtrack and go backwards, and then in one of the four directions (and would be diagonally). I thought I had plenty of tracing statements (and that there were enough) to tell me what was wrong with the program. Ryk looked at it for a while, placing a lot of tracing statements through ... basically the whole lot of code, and I found out what was wrong. That the tried variable was being increased at the wrong time - it was supposed to be placed inside an if statement. Because the tried variable was initially increased every time the row or the column was within the bounds and equal to a certain multiple of a simple number.
Problem 2:
When I was writing the solve maze method, it was also kind of hard. I thought it would just be taking Ryk's code and altering it; making sure it was within the bounds and whatnot. But really, it wasn't. Cause whenever I used it to solve, it wouldn't even solve the whole maze. Only a few directions, and then it would just stop - and the plusses would stop there, too.
Testing this, too, took a multitude of tracing statements and I still didn't quite know what was wrong. From what I understood, the value of row and column were actually never going above the highest point, but in the if statements, the recursion did involve row++ or column++.
I didn't know what to do after a week or so of debugging and finding out what was wrong with it. So I emailed Ryk asking whether it was necessary for the solving of the maze to be solved using recursion, and he said no.
In that case, the "ATTEMPTED" variable looks like '-' while the "OPEN" variable looks like '_'. However, on the maze, there is no difference - each just looks like a line anyways. So in the createMaze method, all the good spots are equal to "ATTEMPTED", and then in the maze, they are equal to "GOOD" which is a plus.
Problem 3:
When I was reformatting the "create maze" button so if you press it after creating another one previously, and I had to call the createMaze(); method for that to work. And when I did that, all of the sudden, the maze just kind of cut in half, and the exit (or the entrance) went missing. I thought there was, initially something wrong with the recursion, so I turned on the tracing, but everything looked right.
It happened that by returning true in the simplest case, the createMaze(); method was supposed to call the addWalls(); method. And the addWalls(); method is supposed to call the gameBoard(); method. But as said before, the gameBoard method was called twice, overwriting what it first wrote.
It was a really stupid mistake, but it took the longest time to find because it was so subtle.
No comments:
Post a Comment