forked from rikkiprince/mastermind-june-2014-dojo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
52 lines (46 loc) · 1.33 KB
/
server.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
var http = require('http');
function initialise() {
gameObject = {
gameState: [],
correct: [randInt(0, 5), randInt(0, 5), randInt(0, 5), randInt(0, 5)],
makeTurn: function(turn) {
this.gameState.push(turn);
return this.score(turn);
},
score: function(turn) {
red = 0;
white = 0;
reds = [false, false, false, false]
for(i = 0; i < 4; i++) {
if(turn[i] == this.correct[i]) {
red++;
reds[i] = true;
}
}
for(i = 0; i < 4; i++) {
if(reds[i]) {
continue;
}
for(j = 0; j < 4; j++) {
if(reds[j]) {
continue;
}
if(turn[i] == this.correct[j]) {
white++;
break;
}
}
}
return [red, white];
}
}
return gameObject;
}
function randInt(low, high) {
return Math.floor(low + (Math.random() * high));
}
http.createServer(function(request, response) {
response.writeHead(200, {"Content-Type": "text/plain"});
response.write("Hello World");
response.end();
}).listen(8080);