From f203223612138006acb91b7409111c3afc0d2ba8 Mon Sep 17 00:00:00 2001 From: newjade Date: Thu, 21 Sep 2017 22:51:22 +0900 Subject: [PATCH] Fix path pattern with hold --- manual/source/path/csv.rst | 2 -- src/main/java/entry/path/PathCore.java | 36 +++++++++++++++++++++++--- 2 files changed, 33 insertions(+), 5 deletions(-) diff --git a/manual/source/path/csv.rst b/manual/source/path/csv.rst index b9fb2fe5..a5156b88 100644 --- a/manual/source/path/csv.rst +++ b/manual/source/path/csv.rst @@ -114,5 +114,3 @@ key: use * ツモ (対パターン) - 「対応ツモ数 (対パターン)」の一覧 - - 使用ミノ,対応地形数,対応パターン数,テト譜,ツモ (対パターン) diff --git a/src/main/java/entry/path/PathCore.java b/src/main/java/entry/path/PathCore.java index 446d59a4..9e4e1c4c 100644 --- a/src/main/java/entry/path/PathCore.java +++ b/src/main/java/entry/path/PathCore.java @@ -25,18 +25,20 @@ class PathCore { private final List candidates; private final FumenParser fumenParser; private final boolean isReduced; + private final boolean isUsingHold; + private final int maxDepth; private final HashSet validPieces; private final HashSet allPieces; - private final ReverseOrderLookUp reverseOrderLookUp; PathCore(List patterns, PackSearcher searcher, int maxDepth, boolean isUsingHold, FumenParser fumenParser) throws ExecutionException, InterruptedException { this.candidates = searcher.toList(); this.fumenParser = fumenParser; BlocksGenerator blocksGenerator = new BlocksGenerator(patterns); this.isReduced = isReducedPieces(blocksGenerator, maxDepth, isUsingHold); + this.isUsingHold = isUsingHold; + this.maxDepth = maxDepth; this.allPieces = getAllPieces(blocksGenerator, maxDepth, isReduced); this.validPieces = getValidPieces(blocksGenerator, allPieces, maxDepth, isReduced); - this.reverseOrderLookUp = new ReverseOrderLookUp(maxDepth, maxDepth + 1); } private boolean isReducedPieces(BlocksGenerator blocksGenerator, int maxDepth, boolean isUsingHold) { @@ -134,6 +136,8 @@ List run(Field field, SizedBit sizedBit) { private HashSet getPiecesPattern(HashSet piecesSolution) { if (isReduced) { // allとvalidが異なる + ReverseOrderLookUp reverseOrderLookUp = new ReverseOrderLookUp(maxDepth, maxDepth + 1); + return piecesSolution.stream() .filter(validPieces::contains) .flatMap(blocks -> { @@ -154,8 +158,34 @@ private HashSet getPiecesPattern(HashSet piecesSolution) }) .filter(allPieces::contains) .collect(Collectors.toCollection(HashSet::new)); + } else if (isUsingHold) { + // allとvalidが同じだが、ホールドが使える + ReverseOrderLookUp reverseOrderLookUp = new ReverseOrderLookUp(maxDepth, maxDepth); + + return piecesSolution.stream() + .filter(validPieces::contains) + .flatMap(blocks -> { + return reverseOrderLookUp.parse(blocks.getBlocks()) + .map(stream -> stream.collect(Collectors.toCollection(ArrayList::new))) + .flatMap(blocksWithHold -> { + int nullIndex = blocksWithHold.indexOf(null); + if (nullIndex < 0) + return Stream.of(new LongBlocks(blocksWithHold)); + + Stream.Builder builder = Stream.builder(); + for (Block block : Block.values()) { + blocksWithHold.set(nullIndex, block); + builder.accept(new LongBlocks(blocksWithHold)); + } + return builder.build(); + }); + }) + .filter(allPieces::contains) + .collect(Collectors.toCollection(HashSet::new)); + } else { - // allとvalidが同じ + // allとvalidが同じで、ホールドも使えない + // そのまま絞り込みだけ実施 return piecesSolution.stream() .filter(validPieces::contains) .collect(Collectors.toCollection(HashSet::new));