cell.js 612 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. var Cell = function(x, y) {
  2. this.x = x;
  3. this.y = y;
  4. this.visited = false;
  5. // When solving the maze, this represents
  6. // the previous node in the navigated path.
  7. this.parent = null;
  8. this.heuristic = 0;
  9. this.visit = function () {
  10. this.visited = true;
  11. };
  12. this.score = function () {
  13. var total = 0;
  14. var p = this.parent;
  15. while(p) {
  16. ++total;
  17. p = p.parent;
  18. }
  19. return total;
  20. };
  21. this.pathToOrigin = function () {
  22. var path = [this];
  23. var p = this.parent;
  24. while(p) {
  25. path.push(p);
  26. p = p.parent;
  27. }
  28. path.reverse();
  29. return path;
  30. };
  31. };