forked from Wei-1/Scala-Machine-Learning
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMinimax.scala
31 lines (27 loc) · 941 Bytes
/
Minimax.scala
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
// Wei Chen - Minimax
// 2017-07-22
package com.scalaml.algorithm
class Minimax {
def search(
myfirst: Array[Double] = null,
mystate: Array[Double] = null,
enstate: Array[Double] = null,
evaluation: (Array[Double], Array[Double]) => Double,
moves: Array[Double] => Array[Array[Double]],
iter: Int = 2,
whos: Boolean
): (Array[Double], Double) = {
if (iter == 0) {
return (myfirst, evaluation(mystate, enstate))
} else {
if (whos) {
return moves(mystate).map(move => search(
if (myfirst == null) move
else myfirst
, move, enstate, evaluation, moves, iter - 1, false)).maxBy(_._2)
} else {
return moves(enstate).map(move => search(myfirst, mystate, move, evaluation, moves, iter - 1, true)).minBy(_._2)
}
}
}
}