Skip to content

Commit

Permalink
Fix path pattern with hold
Browse files Browse the repository at this point in the history
  • Loading branch information
knewjade committed Sep 21, 2017
1 parent 9c88ed9 commit f203223
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 5 deletions.
2 changes: 0 additions & 2 deletions manual/source/path/csv.rst
Original file line number Diff line number Diff line change
Expand Up @@ -114,5 +114,3 @@ key: use

* ツモ (対パターン)
- 「対応ツモ数 (対パターン)」の一覧

使用ミノ,対応地形数,対応パターン数,テト譜,ツモ (対パターン)
36 changes: 33 additions & 3 deletions src/main/java/entry/path/PathCore.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,20 @@ class PathCore {
private final List<Result> candidates;
private final FumenParser fumenParser;
private final boolean isReduced;
private final boolean isUsingHold;
private final int maxDepth;
private final HashSet<LongBlocks> validPieces;
private final HashSet<LongBlocks> allPieces;
private final ReverseOrderLookUp reverseOrderLookUp;

PathCore(List<String> 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) {
Expand Down Expand Up @@ -134,6 +136,8 @@ List<PathPair> run(Field field, SizedBit sizedBit) {
private HashSet<LongBlocks> getPiecesPattern(HashSet<LongBlocks> piecesSolution) {
if (isReduced) {
// allとvalidが異なる
ReverseOrderLookUp reverseOrderLookUp = new ReverseOrderLookUp(maxDepth, maxDepth + 1);

return piecesSolution.stream()
.filter(validPieces::contains)
.flatMap(blocks -> {
Expand All @@ -154,8 +158,34 @@ private HashSet<LongBlocks> getPiecesPattern(HashSet<LongBlocks> 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<LongBlocks> 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));
Expand Down

0 comments on commit f203223

Please sign in to comment.