Search in sources :

Example 96 with Predicate

use of java.util.function.Predicate in project L4J8 by stelar7.

the class FrameToImageTest method generateMinimap.

private void generateMinimap(Match match) {
    // Load map data
    try {
        BufferedImage image = ImageIO.read(new URL(api.getImageAPI().getMap("map" + match.getMap().getId(), null, null)));
        Rectangle mapBounds = match.getMap().getBounds();
        // load icon data
        int championSquareOffset = (int) (120d / 4d);
        int championSquarePadding = (int) (120d / 12d);
        Map<Integer, Item> items = api.getStaticAPI().getItems(Platform.EUW1, null, null, null).getData();
        Map<Integer, StaticChampion> champs = api.getStaticAPI().getChampions(Platform.EUW1, null, null, null);
        Map<Integer, BufferedImage> championImages = new HashMap<>();
        Map<Integer, BufferedImage> itemImages = new HashMap<>();
        match.getParticipants().forEach(p -> {
            try {
                BufferedImage before = ImageIO.read(new URL(api.getImageAPI().getSquare(champs.get(p.getChampionId()), null, null)));
                double scaleFactor = 1d / 4d;
                BufferedImage after = scaleImage(before, scaleFactor);
                championImages.put(p.getParticipantId(), after);
            } catch (IOException e) {
                e.printStackTrace();
            }
        });
        items.values().parallelStream().forEach(i -> {
            try {
                BufferedImage before = ImageIO.read(new URL(api.getImageAPI().getItem(i, null, null)));
                double scaleFactor = 1d / 2d;
                BufferedImage after = scaleImage(before, scaleFactor);
                itemImages.put(i.getId(), after);
            } catch (IOException e) {
                e.printStackTrace();
            }
        });
        if (turretIcon == null) {
            try {
                turretIcon = new EnumMap<>(TeamType.class);
                BufferedImage temp = ImageIO.read(new URL("http://matchhistory.na.leagueoflegends.com/assets/1.0.32/images/normal/event_icons/turret_100.png"));
                turretIcon.put(TeamType.BLUE, scaleImage(temp, .4));
                temp = ImageIO.read(new URL("http://matchhistory.na.leagueoflegends.com/assets/1.0.32/images/normal/event_icons/turret_200.png"));
                turretIcon.put(TeamType.RED, scaleImage(temp, .4));
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        if (inhibIcon == null) {
            try {
                inhibIcon = new EnumMap<>(TeamType.class);
                BufferedImage temp = ImageIO.read(new URL("http://matchhistory.na.leagueoflegends.com/assets/1.0.32/images/normal/event_icons/inhibitor_building_100.png"));
                inhibIcon.put(TeamType.BLUE, scaleImage(temp, .25));
                temp = ImageIO.read(new URL("http://matchhistory.na.leagueoflegends.com/assets/1.0.32/images/normal/event_icons/inhibitor_building_200.png"));
                inhibIcon.put(TeamType.RED, scaleImage(temp, .25));
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        if (swordIcon == null) {
            try {
                swordIcon = ImageIO.read(new URL("http://matchhistory.na.leagueoflegends.com/assets/1.0.32/css/resources/images/scoreboardicon_score.png"));
                swordIcon = scaleImage(swordIcon, 1.5);
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        Map<Integer, List<Pair<Item, Integer>>> inventory = new HashMap<>();
        Map<Integer, Triplet<Integer>> kda = new HashMap<>();
        IntStream.rangeClosed(1, 10).forEach(i -> kda.put(i, new Triplet<>(0, 0, 0)));
        match.getTimeline().getFrames().forEach(frame -> {
            try {
                // Generate file output data
                String path = match.getPlatform().getValue() + File.separator + match.getMatchId();
                File outputFile = new File(path, frame.getTimestamp() + ".png");
                outputFile.getParentFile().mkdirs();
                // Make sure map is large enough for all the data
                int imgW = image.getWidth() + (championSquareOffset + championSquarePadding) * 4;
                int imgH = (image.getHeight() + (championSquareOffset + championSquarePadding) * 11);
                BufferedImage newMap = new BufferedImage(imgW, imgH, BufferedImage.TYPE_INT_ARGB);
                Graphics2D g = (Graphics2D) newMap.getGraphics();
                // set background
                g.setColor(Color.black);
                g.fillRect(0, 0, newMap.getWidth(), newMap.getHeight());
                // set separator line
                g.setColor(Color.white);
                g.fillRect(0, image.getHeight() + (int) (championSquareOffset / 1.5f) + championSquarePadding / 2, newMap.getWidth(), championSquareOffset / 4);
                g.fillRect(image.getWidth() + (int) (championSquareOffset / 1.5f), 0, championSquareOffset / 4, newMap.getHeight());
                // set minimap
                g.drawImage(image, 0, 0, null);
                int[] killCount = { 0 };
                frame.getEvents().forEach(me -> {
                    Predicate<Pair<Item, Integer>> itemIdFilter = p -> p.getKey().getId() == me.getItemId();
                    Predicate<Pair<Item, Integer>> itemAfterFilter = p -> p.getKey().getId() == me.getItemAfter();
                    Predicate<Pair<Item, Integer>> itemBeforeFilter = p -> p.getKey().getId() == me.getItemBefore();
                    if (!inhibDestroyTime.isEmpty()) {
                        Map<Pair<Integer, Integer>, Long> clone = new HashMap<>(inhibDestroyTime);
                        clone.forEach((k, v) -> {
                            if (v + (60000 * 5) <= me.getTimestamp()) {
                                inhib.add(k);
                                inhibDestroyTime.remove(k);
                            }
                        });
                    }
                    switch(me.getEventType()) {
                        case ITEM_PURCHASED:
                            {
                                handlePurchaseEvent(items, inventory, me, itemIdFilter);
                                break;
                            }
                        case ITEM_DESTROYED:
                        case ITEM_SOLD:
                            {
                                handleSoldEvent(inventory, me, itemIdFilter);
                                break;
                            }
                        case ITEM_UNDO:
                            {
                                handleUndoEvent(items, inventory, me, itemBeforeFilter, itemAfterFilter);
                                break;
                            }
                        case CHAMPION_KILL:
                            {
                                handleKillEvent(image, mapBounds, championSquareOffset, championSquarePadding, championImages, g, killCount, me, kda);
                                break;
                            }
                        // ignored events
                        case SKILL_LEVEL_UP:
                        case WARD_KILL:
                        case WARD_PLACED:
                        case ELITE_MONSTER_KILL:
                            {
                                break;
                            }
                        case BUILDING_KILL:
                            {
                                handleBuildingEvent(me);
                                break;
                            }
                        default:
                            {
                                System.out.println(me);
                                break;
                            }
                    }
                });
                turrets.forEach(p -> {
                    BufferedImage turretImage = turretIcon.get(turretTeam.get(p));
                    int xPos = scale(p.getKey(), (int) mapBounds.getX(), (int) mapBounds.getWidth(), 0, image.getWidth());
                    int yPos = image.getHeight() - scale(p.getValue(), (int) mapBounds.getY(), (int) mapBounds.getHeight(), 0, image.getHeight());
                    int xOffset = (int) (-turretImage.getWidth() / 1.25f);
                    int yOffset = -(turretImage.getHeight() / 2);
                    xPos += xOffset;
                    yPos += yOffset;
                    g.drawImage(turretImage, xPos, yPos, null);
                });
                inhib.forEach(p -> {
                    BufferedImage inhibImage = inhibIcon.get(inhibTeam.get(p));
                    int xPos = scale(p.getKey(), (int) mapBounds.getX(), (int) mapBounds.getWidth(), 0, image.getWidth());
                    int yPos = image.getHeight() - scale(p.getValue(), (int) mapBounds.getY(), (int) mapBounds.getHeight(), 0, image.getHeight());
                    int xOffset = (int) (-inhibImage.getWidth() / 1.1f);
                    int yOffset = -(inhibImage.getHeight() / 3);
                    xPos += xOffset;
                    yPos += yOffset;
                    g.drawImage(inhibImage, xPos, yPos, null);
                });
                frame.getParticipantFrames().values().forEach(mpf -> {
                    drawPosition(image, mapBounds, g, mpf, championImages);
                    drawInventory(image, championSquareOffset, championSquarePadding, itemImages, inventory, g, mpf, championImages);
                    drawKDA(kda, image, g, championSquareOffset, championSquarePadding);
                });
                for (int i = 0; i < killList.size(); i++) {
                    Pair<Integer, Integer> k = killList.get(i);
                    int xPos = k.getKey();
                    int yPos = k.getValue();
                    g.setColor(Color.red);
                    g.fillOval(xPos - 8, yPos - 8, 16, 16);
                    g.setColor(Color.black);
                    g.drawString(String.valueOf(i + 1), xPos - 3, yPos + 5);
                    g.drawOval(xPos - 8, yPos - 8, 16, 16);
                }
                killList.clear();
                ImageIO.write(newMap, "png", outputFile);
            } catch (IOException e) {
                e.printStackTrace();
            }
        });
    } catch (IOException e) {
        e.printStackTrace();
    }
}
Also used : IntStream(java.util.stream.IntStream) Platform(no.stelar7.api.l4j8.basic.constants.api.Platform) no.stelar7.api.l4j8.basic.utils(no.stelar7.api.l4j8.basic.utils) java.awt.image(java.awt.image) java.util(java.util) Item(no.stelar7.api.l4j8.pojo.staticdata.item.Item) no.stelar7.api.l4j8.basic.constants.types(no.stelar7.api.l4j8.basic.constants.types) URL(java.net.URL) Predicate(java.util.function.Predicate) no.stelar7.api.l4j8.pojo.match(no.stelar7.api.l4j8.pojo.match) SummonerBuilder(no.stelar7.api.l4j8.impl.builders.summoner.SummonerBuilder) AffineTransform(java.awt.geom.AffineTransform) L4J8(no.stelar7.api.l4j8.impl.L4J8) FileSystemCacheProvider(no.stelar7.api.l4j8.basic.cache.impl.FileSystemCacheProvider) java.awt(java.awt) List(java.util.List) Summoner(no.stelar7.api.l4j8.pojo.summoner.Summoner) java.io(java.io) MatchListBuilder(no.stelar7.api.l4j8.impl.builders.match.MatchListBuilder) SecretFile(no.stelar7.api.l4j8.tests.SecretFile) ImageIO(javax.imageio.ImageIO) org.junit(org.junit) StaticChampion(no.stelar7.api.l4j8.pojo.staticdata.champion.StaticChampion) DataCall(no.stelar7.api.l4j8.basic.calling.DataCall) URL(java.net.URL) Item(no.stelar7.api.l4j8.pojo.staticdata.item.Item) List(java.util.List) StaticChampion(no.stelar7.api.l4j8.pojo.staticdata.champion.StaticChampion) SecretFile(no.stelar7.api.l4j8.tests.SecretFile)

Example 97 with Predicate

use of java.util.function.Predicate in project L4J8 by stelar7.

the class FrameToImageTest method handleUndoEvent.

private void handleUndoEvent(Map<Integer, Item> items, Map<Integer, List<Pair<Item, Integer>>> inventory, MatchEvent me, Predicate<Pair<Item, Integer>> itemBeforeFilter, Predicate<Pair<Item, Integer>> afterItemFilter) {
    List<Pair<Item, Integer>> inv = inventory.getOrDefault(me.getParticipantId(), new ArrayList<>());
    Optional<Pair<Item, Integer>> optional = inv.stream().filter(itemBeforeFilter).findFirst();
    if (optional.isPresent()) {
        Pair<Item, Integer> op = optional.get();
        Pair<Item, Integer> np = new Pair<>(op.getKey(), op.getValue() - 1);
        inv.remove(op);
        if (np.getValue() > 0) {
            inv.add(np);
        }
        Item parent = items.get(op.getKey().getId());
        if (parent.getFrom() != null) {
            for (String s : items.get(op.getKey().getId()).getFrom()) {
                int iid = Integer.parseInt(s);
                Optional<Pair<Item, Integer>> innerO = inv.stream().filter(p -> p.getKey().getId() == iid).findFirst();
                if (innerO.isPresent()) {
                    Pair<Item, Integer> iop = innerO.get();
                    Pair<Item, Integer> inp = new Pair<>(iop.getKey(), iop.getValue() + 1);
                    inv.remove(iop);
                    inv.add(inp);
                } else {
                    Pair<Item, Integer> inp = new Pair<>(items.get(iid), 1);
                    inv.add(inp);
                }
            }
        }
    } else {
        Optional<Pair<Item, Integer>> iopiotnal = inv.stream().filter(afterItemFilter).findFirst();
        if (iopiotnal.isPresent()) {
            Pair<Item, Integer> op = iopiotnal.get();
            Pair<Item, Integer> np = new Pair<>(op.getKey(), op.getValue() + 1);
            inv.remove(op);
            inv.add(np);
        } else {
            Pair<Item, Integer> np = new Pair<>(items.get(me.getItemAfter()), 1);
            inv.add(np);
        }
    }
    inventory.put(me.getParticipantId(), inv);
}
Also used : IntStream(java.util.stream.IntStream) Platform(no.stelar7.api.l4j8.basic.constants.api.Platform) no.stelar7.api.l4j8.basic.utils(no.stelar7.api.l4j8.basic.utils) java.awt.image(java.awt.image) java.util(java.util) Item(no.stelar7.api.l4j8.pojo.staticdata.item.Item) no.stelar7.api.l4j8.basic.constants.types(no.stelar7.api.l4j8.basic.constants.types) URL(java.net.URL) Predicate(java.util.function.Predicate) no.stelar7.api.l4j8.pojo.match(no.stelar7.api.l4j8.pojo.match) SummonerBuilder(no.stelar7.api.l4j8.impl.builders.summoner.SummonerBuilder) AffineTransform(java.awt.geom.AffineTransform) L4J8(no.stelar7.api.l4j8.impl.L4J8) FileSystemCacheProvider(no.stelar7.api.l4j8.basic.cache.impl.FileSystemCacheProvider) java.awt(java.awt) List(java.util.List) Summoner(no.stelar7.api.l4j8.pojo.summoner.Summoner) java.io(java.io) MatchListBuilder(no.stelar7.api.l4j8.impl.builders.match.MatchListBuilder) SecretFile(no.stelar7.api.l4j8.tests.SecretFile) ImageIO(javax.imageio.ImageIO) org.junit(org.junit) StaticChampion(no.stelar7.api.l4j8.pojo.staticdata.champion.StaticChampion) DataCall(no.stelar7.api.l4j8.basic.calling.DataCall) Item(no.stelar7.api.l4j8.pojo.staticdata.item.Item)

Example 98 with Predicate

use of java.util.function.Predicate in project solution-finder by knewjade.

the class BuildUpStreamTest method randomLong.

@Test
@LongTest
void randomLong() throws ExecutionException, InterruptedException {
    // Initialize
    Randoms randoms = new Randoms();
    MinoFactory minoFactory = new MinoFactory();
    MinoShifter minoShifter = new MinoShifter();
    MinoRotation minoRotation = new MinoRotation();
    // Define size
    int height = 4;
    int basicWidth = 3;
    SizedBit sizedBit = new SizedBit(basicWidth, height);
    SeparableMinos separableMinos = SeparableMinos.createSeparableMinos(minoFactory, minoShifter, sizedBit);
    // Create basic solutions
    TaskResultHelper taskResultHelper = new Field4x10MinoPackingHelper();
    LockedReachableThreadLocal lockedReachableThreadLocal = new LockedReachableThreadLocal(minoFactory, minoShifter, minoRotation, height);
    Predicate<ColumnField> memorizedPredicate = (columnField) -> true;
    OnDemandBasicSolutions basicSolutions = new OnDemandBasicSolutions(separableMinos, sizedBit, memorizedPredicate);
    AtomicInteger counter = new AtomicInteger();
    for (int count = 0; count < 10; count++) {
        // Create field
        int numOfMinos = randoms.nextIntClosed(7, 9);
        Field field = randoms.field(height, numOfMinos);
        // Search
        List<InOutPairField> inOutPairFields = InOutPairField.createInOutPairFields(basicWidth, height, field);
        SolutionFilter solutionFilter = createRandomSolutionFilter(randoms, sizedBit, lockedReachableThreadLocal, field);
        PerfectPackSearcher searcher = new PerfectPackSearcher(inOutPairFields, basicSolutions, sizedBit, solutionFilter, taskResultHelper);
        Optional<Result> resultOptional = searcher.findAny();
        // If found solution
        resultOptional.ifPresent(result -> {
            counter.incrementAndGet();
            LinkedList<MinoOperationWithKey> operationWithKeys = result.getMemento().getSeparableMinoStream(basicWidth).map(SeparableMino::toMinoOperationWithKey).collect(Collectors.toCollection(LinkedList::new));
            // Create Pieces
            LockedReachable reachable = lockedReachableThreadLocal.get();
            Set<List<MinoOperationWithKey>> valid = new BuildUpStream(reachable, height).existsValidBuildPattern(field, operationWithKeys).collect(Collectors.toSet());
            PermutationIterable<MinoOperationWithKey> permutations = new PermutationIterable<>(operationWithKeys, operationWithKeys.size());
            for (List<MinoOperationWithKey> permutation : permutations) {
                boolean canBuild = BuildUp.cansBuild(field, permutation, height, reachable);
                if (canBuild) {
                    assertThat(valid).as(FieldView.toString(field)).contains(permutation);
                } else {
                    assertThat(valid).as(FieldView.toString(field)).doesNotContain(permutation);
                }
            }
        });
    }
    System.out.println(counter);
}
Also used : TaskResultHelper(searcher.pack.task.TaskResultHelper) Randoms(lib.Randoms) OperationTransform(common.parser.OperationTransform) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) ColumnField(core.column_field.ColumnField) MinoOperationWithKey(common.datastore.MinoOperationWithKey) OperationInterpreter(common.parser.OperationInterpreter) AllPassedSolutionFilter(searcher.pack.memento.AllPassedSolutionFilter) FieldView(core.field.FieldView) SizedBit(searcher.pack.SizedBit) MinoFactory(core.mino.MinoFactory) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) SeparableMinos(searcher.pack.SeparableMinos) FieldFactory(core.field.FieldFactory) Tag(org.junit.jupiter.api.Tag) LinkedList(java.util.LinkedList) MinoRotation(core.srs.MinoRotation) LockedReachable(core.action.reachable.LockedReachable) PerfectPackSearcher(searcher.pack.task.PerfectPackSearcher) OperationWithKey(common.datastore.OperationWithKey) Field4x10MinoPackingHelper(searcher.pack.task.Field4x10MinoPackingHelper) MinoShifter(core.mino.MinoShifter) Piece(core.mino.Piece) PermutationIterable(common.iterable.PermutationIterable) Predicate(java.util.function.Predicate) Result(searcher.pack.task.Result) InOutPairField(searcher.pack.InOutPairField) Set(java.util.Set) Collectors(java.util.stream.Collectors) Test(org.junit.jupiter.api.Test) ExecutionException(java.util.concurrent.ExecutionException) Operations(common.datastore.Operations) SolutionFilter(searcher.pack.memento.SolutionFilter) List(java.util.List) Field(core.field.Field) SeparableMino(searcher.pack.separable_mino.SeparableMino) SRSValidSolutionFilter(searcher.pack.memento.SRSValidSolutionFilter) Optional(java.util.Optional) OnDemandBasicSolutions(searcher.pack.solutions.OnDemandBasicSolutions) LockedReachableThreadLocal(concurrent.LockedReachableThreadLocal) LongTest(module.LongTest) OnDemandBasicSolutions(searcher.pack.solutions.OnDemandBasicSolutions) TaskResultHelper(searcher.pack.task.TaskResultHelper) LockedReachableThreadLocal(concurrent.LockedReachableThreadLocal) Result(searcher.pack.task.Result) ColumnField(core.column_field.ColumnField) InOutPairField(searcher.pack.InOutPairField) Field(core.field.Field) MinoOperationWithKey(common.datastore.MinoOperationWithKey) SeparableMinos(searcher.pack.SeparableMinos) InOutPairField(searcher.pack.InOutPairField) PerfectPackSearcher(searcher.pack.task.PerfectPackSearcher) MinoFactory(core.mino.MinoFactory) LinkedList(java.util.LinkedList) List(java.util.List) Field4x10MinoPackingHelper(searcher.pack.task.Field4x10MinoPackingHelper) PermutationIterable(common.iterable.PermutationIterable) ColumnField(core.column_field.ColumnField) MinoRotation(core.srs.MinoRotation) Randoms(lib.Randoms) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) SizedBit(searcher.pack.SizedBit) AllPassedSolutionFilter(searcher.pack.memento.AllPassedSolutionFilter) SolutionFilter(searcher.pack.memento.SolutionFilter) SRSValidSolutionFilter(searcher.pack.memento.SRSValidSolutionFilter) MinoShifter(core.mino.MinoShifter) LockedReachable(core.action.reachable.LockedReachable) Test(org.junit.jupiter.api.Test) LongTest(module.LongTest) LongTest(module.LongTest)

Example 99 with Predicate

use of java.util.function.Predicate in project solution-finder by knewjade.

the class BuildUpStreamTest method randomShort.

@Test
void randomShort() throws ExecutionException, InterruptedException {
    // Initialize
    Randoms randoms = new Randoms();
    MinoFactory minoFactory = new MinoFactory();
    MinoShifter minoShifter = new MinoShifter();
    MinoRotation minoRotation = new MinoRotation();
    // Define size
    int height = 4;
    int basicWidth = 3;
    SizedBit sizedBit = new SizedBit(basicWidth, height);
    SeparableMinos separableMinos = SeparableMinos.createSeparableMinos(minoFactory, minoShifter, sizedBit);
    // Create basic solutions
    TaskResultHelper taskResultHelper = new Field4x10MinoPackingHelper();
    LockedReachableThreadLocal lockedReachableThreadLocal = new LockedReachableThreadLocal(minoFactory, minoShifter, minoRotation, height);
    Predicate<ColumnField> memorizedPredicate = (columnField) -> true;
    OnDemandBasicSolutions basicSolutions = new OnDemandBasicSolutions(separableMinos, sizedBit, memorizedPredicate);
    AtomicInteger counter = new AtomicInteger();
    for (int count = 0; count < 10000; count++) {
        // Create field
        int numOfMinos = randoms.nextInt(1, 7);
        Field field = randoms.field(height, numOfMinos);
        // Search
        List<InOutPairField> inOutPairFields = InOutPairField.createInOutPairFields(basicWidth, height, field);
        SolutionFilter solutionFilter = createRandomSolutionFilter(randoms, sizedBit, lockedReachableThreadLocal, field);
        PerfectPackSearcher searcher = new PerfectPackSearcher(inOutPairFields, basicSolutions, sizedBit, solutionFilter, taskResultHelper);
        Optional<Result> resultOptional = searcher.findAny();
        // If found solution
        resultOptional.ifPresent(result -> {
            counter.incrementAndGet();
            LinkedList<MinoOperationWithKey> operationWithKeys = result.getMemento().getSeparableMinoStream(basicWidth).map(SeparableMino::toMinoOperationWithKey).collect(Collectors.toCollection(LinkedList::new));
            // Create Pieces
            LockedReachable reachable = lockedReachableThreadLocal.get();
            Set<List<MinoOperationWithKey>> valid = new BuildUpStream(reachable, height).existsValidBuildPattern(field, operationWithKeys).collect(Collectors.toSet());
            PermutationIterable<MinoOperationWithKey> permutations = new PermutationIterable<>(operationWithKeys, operationWithKeys.size());
            for (List<MinoOperationWithKey> permutation : permutations) {
                boolean canBuild = BuildUp.cansBuild(field, permutation, height, reachable);
                if (canBuild) {
                    assertThat(valid).as(FieldView.toString(field)).contains(permutation);
                } else {
                    assertThat(valid).as(FieldView.toString(field)).doesNotContain(permutation);
                }
            }
        });
    }
    System.out.println(counter);
}
Also used : TaskResultHelper(searcher.pack.task.TaskResultHelper) Randoms(lib.Randoms) OperationTransform(common.parser.OperationTransform) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) ColumnField(core.column_field.ColumnField) MinoOperationWithKey(common.datastore.MinoOperationWithKey) OperationInterpreter(common.parser.OperationInterpreter) AllPassedSolutionFilter(searcher.pack.memento.AllPassedSolutionFilter) FieldView(core.field.FieldView) SizedBit(searcher.pack.SizedBit) MinoFactory(core.mino.MinoFactory) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) SeparableMinos(searcher.pack.SeparableMinos) FieldFactory(core.field.FieldFactory) Tag(org.junit.jupiter.api.Tag) LinkedList(java.util.LinkedList) MinoRotation(core.srs.MinoRotation) LockedReachable(core.action.reachable.LockedReachable) PerfectPackSearcher(searcher.pack.task.PerfectPackSearcher) OperationWithKey(common.datastore.OperationWithKey) Field4x10MinoPackingHelper(searcher.pack.task.Field4x10MinoPackingHelper) MinoShifter(core.mino.MinoShifter) Piece(core.mino.Piece) PermutationIterable(common.iterable.PermutationIterable) Predicate(java.util.function.Predicate) Result(searcher.pack.task.Result) InOutPairField(searcher.pack.InOutPairField) Set(java.util.Set) Collectors(java.util.stream.Collectors) Test(org.junit.jupiter.api.Test) ExecutionException(java.util.concurrent.ExecutionException) Operations(common.datastore.Operations) SolutionFilter(searcher.pack.memento.SolutionFilter) List(java.util.List) Field(core.field.Field) SeparableMino(searcher.pack.separable_mino.SeparableMino) SRSValidSolutionFilter(searcher.pack.memento.SRSValidSolutionFilter) Optional(java.util.Optional) OnDemandBasicSolutions(searcher.pack.solutions.OnDemandBasicSolutions) LockedReachableThreadLocal(concurrent.LockedReachableThreadLocal) LongTest(module.LongTest) OnDemandBasicSolutions(searcher.pack.solutions.OnDemandBasicSolutions) TaskResultHelper(searcher.pack.task.TaskResultHelper) LockedReachableThreadLocal(concurrent.LockedReachableThreadLocal) Result(searcher.pack.task.Result) ColumnField(core.column_field.ColumnField) InOutPairField(searcher.pack.InOutPairField) Field(core.field.Field) MinoOperationWithKey(common.datastore.MinoOperationWithKey) SeparableMinos(searcher.pack.SeparableMinos) InOutPairField(searcher.pack.InOutPairField) PerfectPackSearcher(searcher.pack.task.PerfectPackSearcher) MinoFactory(core.mino.MinoFactory) LinkedList(java.util.LinkedList) List(java.util.List) Field4x10MinoPackingHelper(searcher.pack.task.Field4x10MinoPackingHelper) PermutationIterable(common.iterable.PermutationIterable) ColumnField(core.column_field.ColumnField) MinoRotation(core.srs.MinoRotation) Randoms(lib.Randoms) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) SizedBit(searcher.pack.SizedBit) AllPassedSolutionFilter(searcher.pack.memento.AllPassedSolutionFilter) SolutionFilter(searcher.pack.memento.SolutionFilter) SRSValidSolutionFilter(searcher.pack.memento.SRSValidSolutionFilter) MinoShifter(core.mino.MinoShifter) LockedReachable(core.action.reachable.LockedReachable) Test(org.junit.jupiter.api.Test) LongTest(module.LongTest)

Example 100 with Predicate

use of java.util.function.Predicate in project solution-finder by knewjade.

the class OnDemandBasicSolutionsTest method get3x5.

@Test
void get3x5() throws Exception {
    assertTimeout(ofMinutes(1), () -> {
        SizedBit sizedBit = new SizedBit(3, 5);
        SeparableMinos separableMinos = createSeparableMinos(sizedBit);
        Predicate<ColumnField> memorizedPredicate = columnField -> true;
        OnDemandBasicSolutions solutions = new OnDemandBasicSolutions(separableMinos, sizedBit, memorizedPredicate);
        Stream<? extends MinoField> stream = solutions.parse(ColumnFieldFactory.createField()).stream();
        assertThat(stream.count()).isEqualTo(260179L);
    });
}
Also used : MinoShifter(core.mino.MinoShifter) Predicate(java.util.function.Predicate) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) ColumnField(core.column_field.ColumnField) Duration.ofSeconds(java.time.Duration.ofSeconds) ColumnFieldFactory(core.column_field.ColumnFieldFactory) Test(org.junit.jupiter.api.Test) SizedBit(searcher.pack.SizedBit) Stream(java.util.stream.Stream) MinoFactory(core.mino.MinoFactory) SeparableMinos(searcher.pack.SeparableMinos) Duration.ofMinutes(java.time.Duration.ofMinutes) MinoField(searcher.pack.mino_field.MinoField) Assertions.assertTimeout(org.junit.jupiter.api.Assertions.assertTimeout) SeparableMinos(searcher.pack.SeparableMinos) SizedBit(searcher.pack.SizedBit) ColumnField(core.column_field.ColumnField) Test(org.junit.jupiter.api.Test)

Aggregations

Predicate (java.util.function.Predicate)589 List (java.util.List)266 ArrayList (java.util.ArrayList)170 Collectors (java.util.stream.Collectors)167 Map (java.util.Map)164 Set (java.util.Set)137 Test (org.junit.Test)133 IOException (java.io.IOException)122 Collections (java.util.Collections)118 Arrays (java.util.Arrays)110 HashMap (java.util.HashMap)105 Collection (java.util.Collection)93 Optional (java.util.Optional)87 HashSet (java.util.HashSet)85 Stream (java.util.stream.Stream)69 Function (java.util.function.Function)61 File (java.io.File)60 Iterator (java.util.Iterator)55 Logger (org.slf4j.Logger)53 LoggerFactory (org.slf4j.LoggerFactory)52