Advertisement
Guest User

Untitled

a guest
Dec 6th, 2016
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | None | 0 0
  1. this.equals = function(other){
  2.  
  3. var toReturn = other !== null;
  4.  
  5. for (var r = 0; r < 3 && toReturn; r++) {
  6. for (var c = 0; c < 3 && toReturn; c++) {
  7.  
  8. //Debug//
  9. document.write(tiles[r][c]); //Works, Prints 2 (correct)
  10. document.write(other.tiles[r][c]); //Does not, prints nothing
  11. //-----//
  12.  
  13. if(tiles[r][c] !== other.tiles[r][c]) toReturn = false; //Not working, exits function
  14. }
  15. }
  16. return toReturn;
  17. };
  18.  
  19. function assert(expression) {
  20. var result = eval(expression);
  21. if (!result) alert("Assertion failed: " + expression);
  22. }
  23.  
  24. var start = new PuzzleState([[2, 8, 3], [1, 6, 4], [7, 0, 5]]);
  25. var startCopy = new PuzzleState([[2, 8, 3], [1, 6, 4], [7, 0, 5]]);
  26. var goal = new PuzzleState([[1, 2, 3], [8, 0, 4], [7, 6, 5]]);
  27.  
  28. alert(goal.toString());
  29.  
  30. assert(start.equals(startCopy));
  31. assert(!start.equals(goal));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement