Menu game mode + bot idiot
This commit is contained in:
43
fr/iut_fbleau/Bot/IdiotBot.java
Normal file
43
fr/iut_fbleau/Bot/IdiotBot.java
Normal file
@@ -0,0 +1,43 @@
|
||||
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()));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user