Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- this.equals = function(other){
- var toReturn = other !== null;
- for (var r = 0; r < 3 && toReturn; r++) {
- for (var c = 0; c < 3 && toReturn; c++) {
- //Debug//
- document.write(tiles[r][c]); //Works, Prints 2 (correct)
- document.write(other.tiles[r][c]); //Does not, prints nothing
- //-----//
- if(tiles[r][c] !== other.tiles[r][c]) toReturn = false; //Not working, exits function
- }
- }
- return toReturn;
- };
- function assert(expression) {
- var result = eval(expression);
- if (!result) alert("Assertion failed: " + expression);
- }
- var start = new PuzzleState([[2, 8, 3], [1, 6, 4], [7, 0, 5]]);
- var startCopy = new PuzzleState([[2, 8, 3], [1, 6, 4], [7, 0, 5]]);
- var goal = new PuzzleState([[1, 2, 3], [8, 0, 4], [7, 6, 5]]);
- alert(goal.toString());
- assert(start.equals(startCopy));
- assert(!start.equals(goal));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement