-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathPlayers.js
29 lines (28 loc) · 878 Bytes
/
Players.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
class AIRandom {
constructor(config) {
this.config = config
}
getAction(state) {
let legalAction = BoardState.getLegalActions(this.config.player, state.getBoard());
legalAction = legalAction[Math.floor(Math.random() * legalAction.length)]
if (legalAction == undefined)
return null
return legalAction
}
}
class AIGreedy {
constructor(config) {
this.config = config
}
getAction(state) {
let legalAction = BoardState.getLegalActions(this.config.player, state.getBoard());
let action = null
legalAction.forEach((x) => {
if (Math.abs(x[0].x - x[1].x) == 2)
action = x
})
if (action == null && legalAction.length >= 1)
return legalAction[Math.floor(Math.random() * legalAction.length)]
return action
}
}