-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathRandomAI.java
66 lines (52 loc) · 1.48 KB
/
RandomAI.java
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
package random;
import java.util.concurrent.ThreadLocalRandom;
import game.Game;
import main.collections.FastArrayList;
import other.AI;
import other.context.Context;
import other.move.Move;
import utils.AIUtils;
/**
* Example third-party implementation of a random AI for Ludii
*
* @author Dennis Soemers
*/
public class RandomAI extends AI
{
//-------------------------------------------------------------------------
/** Our player index */
protected int player = -1;
//-------------------------------------------------------------------------
/**
* Constructor
*/
public RandomAI()
{
this.friendlyName = "Example Random AI";
}
//-------------------------------------------------------------------------
@Override
public Move selectAction
(
final Game game,
final Context context,
final double maxSeconds,
final int maxIterations,
final int maxDepth
)
{
FastArrayList<Move> legalMoves = game.moves(context).moves();
// If we're playing a simultaneous-move game, some of the legal moves may be
// for different players. Extract only the ones that we can choose.
if (!game.isAlternatingMoveGame())
legalMoves = AIUtils.extractMovesForMover(legalMoves, player);
final int r = ThreadLocalRandom.current().nextInt(legalMoves.size());
return legalMoves.get(r);
}
@Override
public void initAI(final Game game, final int playerID)
{
this.player = playerID;
}
//-------------------------------------------------------------------------
}