package fr.iut_fbleau.HexGame;

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;

public class RandomBot extends AbstractGamePlayer {

    private final Random rng;

    public RandomBot(Player me, Random rng) {
        super(me);
        this.rng = rng;
    }

    public Boolean jesuisMinimax(){
        return false;
    }

    public RandomBot(Player me, long seed) {
        this(me, new Random(seed));
    }

    @Override
    public AbstractPly giveYourMove(IBoard board) {
        List<AbstractPly> legal = new ArrayList<>();
        Iterator<AbstractPly> it = board.iterator();
        while (it.hasNext()) {
            legal.add(it.next());
        }

        if (legal.isEmpty()) {
            throw new IllegalStateException("No legal move available (board is full?)");
        }

        return legal.get(rng.nextInt(legal.size()));
    }
}
