-
Notifications
You must be signed in to change notification settings - Fork 6
/
MonAgentLudique.java
45 lines (36 loc) · 1.29 KB
/
MonAgentLudique.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
import game.Game;
import main.collections.FastArrayList;
import other.AI;
import other.context.Context;
import other.move.Move;
import utils.AIUtils;
import java.util.Arrays;
import java.util.concurrent.ThreadLocalRandom;
public class MonAgentLudique extends AI {
//-------------------------------------------------------------------------
/** Our player index */
protected int player = -1;
//-------------------------------------------------------------------------
/**
* Constructor
*/
public MonAgentLudique()
{
this.friendlyName = "Jeu aleatoire";
}
@Override
public Move selectAction(Game game, Context context, double maxSeconds, int maxIterations, 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;
}
}