-
Notifications
You must be signed in to change notification settings - Fork 0
/
minMax.js
40 lines (30 loc) · 878 Bytes
/
minMax.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
class MinMax {
// depth argument refers to the tree search max depth
constructor(depth = null){
if (depth < 0) {
console.log("Invalid depth for MinMax algorithm. Depth must be positive.\nMinMax - constructor")
depth = null;
}
else
this.depth = depth;
}
nextMove(problem){
print("nextMove chiamata");
var move = null;
// all possibile actions
let fringe = problem.action(problem.state);
this.min_max_search(problem, fringe);
return move;
}
min_max_search(problem, fringe){
print("Min Max Search. Fringe lenght: ", fringe.lenght);
var move = null;
fringe.forEach((item, i) => {
print("Iterazione: ", i);
console.log("fringe: ", item);
var childState = problem.result(item, problem.player_turn);
console.log("nuovo stato: ", childState);
});
return move;
}
}