Skip to content

Commit

Permalink
Move HeapElement into ghost.js
Browse files Browse the repository at this point in the history
  • Loading branch information
dubzzz committed Apr 24, 2015
1 parent 7c45c18 commit 7ed96ad
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 14 deletions.
6 changes: 3 additions & 3 deletions test/www/tools/heap.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ describe('Heap tests', function() {
});
it('Pop an element reduces the size by 1', function(done) {
var h = new Heap();
h.push(new Elt(50, 50));
h.push(new Elt(50, 50));
h.push(new Elt(50, 50));
h.push(new Elt(10, 10));
h.push(new Elt(20, 20));
h.push(new Elt(30, 30));
h.size().should.equal(3);
h.pop();
h.size().should.equal(2);
Expand Down
11 changes: 10 additions & 1 deletion www/pacman/ghost.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,18 @@ var __conf = require('./configuration.js'),
distanceCells = __conf.distanceCells;

var __heap = require('../tools/heap.js'),
HeapElement = __heap.HeapElement,
Heap = __heap.Heap;

var HeapElement = function(x, y, initial_direction, dist_from_start, dist_to_end) {
this.x = x;
this.y = y;
this.initial_direction = initial_direction;
this.dist_from_start = dist_from_start; // real distance
this.dist_to_end = dist_to_end; // distance measured for a line
this.dist = dist_from_start + dist_to_end;
};


/**
* Ghosts
*/
Expand Down
10 changes: 0 additions & 10 deletions www/tools/heap.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,6 @@
* used to find the "shortest path" to reach the PacMan
*/

var HeapElement = function(x, y, initial_direction, dist_from_start, dist_to_end) {
this.x = x;
this.y = y;
this.initial_direction = initial_direction;
this.dist_from_start = dist_from_start; // real distance
this.dist_to_end = dist_to_end; // distance measured for a line
this.dist = dist_from_start + dist_to_end;
};

var Heap = function() {
this.elements = new Array();
this.num_elements = 0;
Expand Down Expand Up @@ -92,7 +83,6 @@ var Heap = function() {
* Module definition
*/

module.exports.HeapElement = HeapElement;
module.exports.Heap = Heap;

}());
Expand Down

0 comments on commit 7ed96ad

Please sign in to comment.