package laboratoire4.strategies; import laboratoire4.Action; import laboratoire4.IPawn; import laboratoire4.game.Game; import laboratoire4.pawns.PawnMovement; import java.util.*; import java.util.stream.Collectors; public interface Strategy { int WEIGHT_MAX = 10; EvaluationResult getNextMove(); int getWeight(); static List> getValidActions(Game game) { List maxPawns = Arrays.stream(game.getBoard()) .flatMap(Arrays::stream) .filter(Objects::nonNull) .filter(p -> p.getPlayer() == game.getPlayer()) .collect(Collectors.toList()); return getValidActions(game.getBoard(), maxPawns); } static List> getValidActions(IPawn[][] board, Collection pawns) { return getValidActions(board, pawns, true); } static List> getValidActions(IPawn[][] board, Collection pawns, boolean excludeDefense) { List> validActions = new ArrayList<>(); for (IPawn pawn : pawns) { if (excludeDefense && pawn.getRow() == pawn.getPlayer().getHome()) { int col = pawn.getCol(); // Si possible, on ne bouge pas ces pushers, comme ça on a une défense d'urgence totale if (col == 1 || col == 2 || col == 5 || col == 6) { continue; } } for (PawnMovement movement : PawnMovement.values()) { if (pawn.isMoveValid(board, movement)) { validActions.add(new Action<>(pawn, movement)); } } } if (excludeDefense && validActions.isEmpty()) { return getValidActions(board, pawns, false); } return validActions; } }