forked from cwthompson/mouse_ai_template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
brain.js
63 lines (50 loc) · 1.74 KB
/
brain.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
var brain = {
socket: {},
mouse: {},
maze: {},
timer: 200,
move: {},
start : function() {
//
var socket = brain.socket;
var mouse = brain.mouse;
var maze = brain.maze;
this.move = setInterval(function() {
var finish = maze.getFinishZone();
// this represents each step the mouse takes
var currentLocation = mouse.getLocation();
if (finish.x == currentLocation.x &&
finish.y == currentLocation.y) {
// // update the number of the mouse and reset details such as steps ect.
//
//mouse.resetMouse();
//
// // socket used update the client side display. e.g display a message saying the mouse has finished
//
// socket.emit('mazeFinished', {
// name: mouse.getName(),
// steps: mouse.getSteps()
// });
brain.stop();
} else {
// // socket used to update the client side display. e.g visually make the mouse move
//
// socket.emit('mouseMoved', {
// name: mouse.getName(),
// location: mouse.getLocation(),
// steps: mouse.getSteps(),
// resetMouse: false // used to determin what message to display - not to be confused with mouse.reset
// });
}
}, brain.timer)
},
stop: function() {
clearInterval(brain.move);
}
}
module.exports.getBrain = function (socket, mouse, maze) {
brain.maze = maze;
brain.mouse = mouse;
brain.socket = socket;
return brain;
}