44 lines
1.1 KiB
Java
44 lines
1.1 KiB
Java
package fr.iut_fbleau.Bot;
|
|
|
|
import fr.iut_fbleau.GameAPI.AbstractGamePlayer;
|
|
import fr.iut_fbleau.GameAPI.AbstractPly;
|
|
import fr.iut_fbleau.GameAPI.IBoard;
|
|
import fr.iut_fbleau.GameAPI.Player;
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.Iterator;
|
|
import java.util.List;
|
|
import java.util.Random;
|
|
|
|
/**
|
|
* Bot idiot : choisit un coup légal au hasard parmi ceux retournés par IBoard.iterator().
|
|
* Compatible avec n'importe quel jeu respectant GameAPI (dont AvalamBoard).
|
|
*/
|
|
public class IdiotBot extends AbstractGamePlayer {
|
|
|
|
private final Random rng;
|
|
|
|
public IdiotBot(Player p) {
|
|
super(p);
|
|
this.rng = new Random();
|
|
}
|
|
|
|
@Override
|
|
public AbstractPly giveYourMove(IBoard board) {
|
|
|
|
// Si la partie est terminée ou qu'il n'y a pas de coups, on ne joue rien.
|
|
if (board == null || board.isGameOver()) return null;
|
|
|
|
Iterator<AbstractPly> it = board.iterator();
|
|
List<AbstractPly> moves = new ArrayList<>();
|
|
|
|
while (it.hasNext()) {
|
|
moves.add(it.next());
|
|
}
|
|
|
|
if (moves.isEmpty()) return null;
|
|
|
|
return moves.get(rng.nextInt(moves.size()));
|
|
}
|
|
}
|