-
Notifications
You must be signed in to change notification settings - Fork 0
/
common.js
70 lines (59 loc) · 2.17 KB
/
common.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
64
65
66
67
68
69
70
<!--
// verbose mode
if (verbose) {verboseMode("load: common.js");}
// these functions define the behaviour of the enviroment in the simulation
// lukas
lib = getLibs();
for (i=0;lib[i]!=null;i++) {
document.write('<script language="JavaScript" type="text/javascript" src="'+lib[i]+'.js"></script>');
}
function Boot()
{
window.status = "booting...";
startTail = 0; maxtail = 500; survivalRate = 250; foodQuality = 500; updateStats = false; tail = new Array(); last_direction = new Array(); location_x = new Array(); location_y = new Array(); genePool = new Array(); historyN = new Array(); historyL = new Array(); historyC = 0; alive = new Array(); breedingProgram = new Array(); lastBite = new Array();
colorSnakes();
for (z=0;z<sC;z++) { Init(z, randomGenes("God", "Top")); }
feedSnake();
if (verbose) {verboseMode("completed: BOOT");}
}
function Init(n,genes)
{
window.status = "initializing snake ["+n+"]...";
location_x[n*maxtail] = Math.ceil(s * Math.random()) - 1; location_y[n*maxtail] = Math.ceil(s * Math.random()) - 1;
if (wallHere(location_x[n*maxtail], location_y[n*maxtail])) {Init(n, genes);}
else {InitBasic(n, genes);}
if (verbose) {verboseMode("completed: INIT("+n+")");}
}
function InitXY(n,x,y,genes)
{
window.status = "initializing snake ["+n+"]...";
location_x[n*maxtail] = x; location_y[n*maxtail] = y;
InitBasic(n,genes);
}
function InitBasic(n,genes) {
last_direction[n] = 1; tail[n] = startTail; lastBite[n] = 0;
for (x=1;x<=tail[n];x++)
{ location_x[x+(n*maxtail)] = location_x[(n*maxtail)];
location_y[x+(n*maxtail)] = location_y[(n*maxtail)]; }
colorSnake(n);
genePool[n] = genes;
addtoHist(n);
alive[n] = true;
window.status = "running...";
}
function feedSnake()
{
HideBite();
bite_x = Math.ceil(s * Math.random()) - 1; bite_y = Math.ceil(s * Math.random()) - 1;
while (snakeHere(bite_x, bite_y) || wallHere(bite_x, bite_y)) {bite_x = Math.ceil(s * Math.random()) - 1; bite_y = Math.ceil(s * Math.random()) - 1;}
runtime = 0;
}
function feedSnakeXY(x,y)
{
HideBite();
bite_x = x; bite_y = y;
runtime = 0;
}
// verbose mode
if (verbose) {verboseMode("done: common.js");}
-->