-
Notifications
You must be signed in to change notification settings - Fork 0
/
AIPolicy.js
49 lines (35 loc) · 1.04 KB
/
AIPolicy.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
function AIPolicy(){
}
AIPolicy.prototype.evaluate = function(state, gamePolicy){
let evaluation = 1;
for (var i = 0 ; i < state.balls.length; i++){
for(var j = i + 1 ; j < state.balls.length ; j++){
let firstBall = state.balls[i];
let secondBall = state.balls[j];
if(firstBall === state.whiteBall || secondBall === state.whiteBall
||
firstBall.inHole || secondBall.inHole){
continue;
}
evaluation += firstBall.position.distanceFrom(secondBall.position);
}
}
evaluation = evaluation/5800;
if(!gamePolicy.firstCollision){
evaluation+= 100;
}
evaluation += 2000 * gamePolicy.validBallsInsertedOnTurn;
gamePolicy.updateTurnOutcome();
if(gamePolicy.won){
if(!gamePolicy.foul){
evaluation += 10000;
}
else{
evaluation -= 10000;
}
}
if(gamePolicy.foul){
evaluation = evaluation - 3000;
}
return evaluation;
}