From 88b746f877149a8300fb14aa9d5469d092568406 Mon Sep 17 00:00:00 2001 From: knewjade Date: Sun, 15 Jan 2023 16:58:54 +0900 Subject: [PATCH] When a board that satisfies from the beginning is input, it's assumed to be successful, not only in the sequence. --- src/main/java/common/order/OrderLookup.java | 4 +++ .../java/common/order/ReverseOrderLookUp.java | 9 +++++ .../checker/invoker/using_hold/Obj.java | 7 ++-- .../checker/invoker/using_hold/Task.java | 16 ++++++--- .../java/_usecase/path/PathTetfuCaseTest.java | 15 +++++++++ .../percent/PercentTetfuCaseTest.java | 12 +++++++ .../common/order/ReverseOrderLookUpTest.java | 33 +++++++++++++++---- 7 files changed, 82 insertions(+), 14 deletions(-) diff --git a/src/main/java/common/order/OrderLookup.java b/src/main/java/common/order/OrderLookup.java index cc6aea92..7b2ef0c8 100644 --- a/src/main/java/common/order/OrderLookup.java +++ b/src/main/java/common/order/OrderLookup.java @@ -44,6 +44,10 @@ public static ArrayList> reverseBlocks(List blocks, int // blocks -- [hold] --> ??? // toDepth: ???の深さ public static ArrayList> forwardBlocks(List blocks, int toDepth) { + if (toDepth == 0) { + return new ArrayList<>(); + } + if (blocks.size() == 1) { assert toDepth == 1; ArrayList> candidates = new ArrayList<>(); diff --git a/src/main/java/common/order/ReverseOrderLookUp.java b/src/main/java/common/order/ReverseOrderLookUp.java index 0bf0ec9a..627e8571 100644 --- a/src/main/java/common/order/ReverseOrderLookUp.java +++ b/src/main/java/common/order/ReverseOrderLookUp.java @@ -3,6 +3,7 @@ import core.mino.Piece; import java.util.ArrayList; +import java.util.Collections; import java.util.List; import java.util.stream.Collectors; import java.util.stream.IntStream; @@ -23,6 +24,14 @@ public ReverseOrderLookUp(int toDepth, int fromDepth) { } private List> reverse(int toDepth, int fromDepth) { + if (toDepth == 0) { + List integers = new ArrayList<>(); + for (int i = 0; i < fromDepth; i++) { + integers.add(-1); + } + return Collections.singletonList(integers); + } + assert 1 <= toDepth; assert toDepth <= fromDepth; List indexes = IntStream.range(0, toDepth).boxed().collect(Collectors.toList()); diff --git a/src/main/java/concurrent/checker/invoker/using_hold/Obj.java b/src/main/java/concurrent/checker/invoker/using_hold/Obj.java index 71cca6f7..3f5f2727 100644 --- a/src/main/java/concurrent/checker/invoker/using_hold/Obj.java +++ b/src/main/java/concurrent/checker/invoker/using_hold/Obj.java @@ -1,6 +1,5 @@ package concurrent.checker.invoker.using_hold; -import common.order.ReverseOrderLookUp; import common.tree.ConcurrentVisitedTree; import core.field.Field; @@ -11,8 +10,10 @@ class Obj { final ConcurrentVisitedTree visitedTree; Obj(Field field, int maxClearLine, int maxDepth, ConcurrentVisitedTree visitedTree) { - this.field = field; - this.maxClearLine = maxClearLine; + Field freeze = field.freeze(); + int lines_cleared = freeze.clearLine(); + this.field = freeze; + this.maxClearLine = maxClearLine - lines_cleared; this.maxDepth = maxDepth; this.visitedTree = visitedTree; } diff --git a/src/main/java/concurrent/checker/invoker/using_hold/Task.java b/src/main/java/concurrent/checker/invoker/using_hold/Task.java index 40687735..e9903808 100644 --- a/src/main/java/concurrent/checker/invoker/using_hold/Task.java +++ b/src/main/java/concurrent/checker/invoker/using_hold/Task.java @@ -1,12 +1,12 @@ package concurrent.checker.invoker.using_hold; import common.ResultHelper; -import common.buildup.BuildUpStream; -import common.datastore.*; +import common.datastore.Operation; +import common.datastore.Pair; +import common.datastore.Result; import common.datastore.action.Action; import common.datastore.blocks.Pieces; import common.order.OrderLookup; -import common.parser.OperationTransform; import common.tree.VisitedTree; import concurrent.checker.invoker.CheckerCommonObj; import core.action.candidate.Candidate; @@ -29,7 +29,7 @@ class Task implements Callable> { } @Override - public Pair call() throws Exception { + public Pair call() { List pieceList = target.getPieces(); // すでに探索済みならそのまま結果を追加 @@ -37,6 +37,14 @@ public Pair call() throws Exception { if (succeed != VisitedTree.NO_RESULT) return new Pair<>(target, succeed == VisitedTree.SUCCEED); + // すでに条件を満たしている場合は成功として扱う + if (obj.field.isEmpty() && obj.maxClearLine == 0) { + boolean result = true; + obj.visitedTree.set(result, pieceList); + return new Pair<>(target, result); + } + assert 0 < obj.maxClearLine; + // 探索準備 Checker checker = commonObj.checkerThreadLocal.get(); Candidate candidate = commonObj.candidateThreadLocal.get(); diff --git a/src/test/java/_usecase/path/PathTetfuCaseTest.java b/src/test/java/_usecase/path/PathTetfuCaseTest.java index 4aabb113..e12f0217 100644 --- a/src/test/java/_usecase/path/PathTetfuCaseTest.java +++ b/src/test/java/_usecase/path/PathTetfuCaseTest.java @@ -1558,4 +1558,19 @@ void noKicks() throws Exception { assertThat(log.getError()).isEmpty(); } } + + @Test + void filled_lines_already() throws Exception { + String tetfu = "v115@9gn8JeAgH"; + String command = String.format("path -t %s -p T", tetfu); + Log log = RunnerHelper.runnerCatchingLog(() -> EntryPointMain.main(command.split(" "))); + + assertThat(log.getOutput()) + .contains("T") + .contains(Messages.uniqueCount(0)) + .contains(Messages.minimalCount(0)) + .contains(Messages.useHold()); + + assertThat(log.getError()).isEmpty(); + } } diff --git a/src/test/java/_usecase/percent/PercentTetfuCaseTest.java b/src/test/java/_usecase/percent/PercentTetfuCaseTest.java index 76d70e7d..447b9bfe 100644 --- a/src/test/java/_usecase/percent/PercentTetfuCaseTest.java +++ b/src/test/java/_usecase/percent/PercentTetfuCaseTest.java @@ -474,4 +474,16 @@ void noKicks() throws Exception { assertThat(log.getError()).isEmpty(); } } + + @Test + void filled_lines_already() throws Exception { + String tetfu = "v115@9gn8JeAgH"; + String command = String.format("percent -t %s -p T", tetfu); + Log log = RunnerHelper.runnerCatchingLog(() -> EntryPointMain.main(command.split(" "))); + + assertThat(log.getOutput()) + .contains(Messages.success(1, 1)); + + assertThat(log.getError()).isEmpty(); + } } diff --git a/src/test/java/common/order/ReverseOrderLookUpTest.java b/src/test/java/common/order/ReverseOrderLookUpTest.java index b5ca8318..f8532824 100644 --- a/src/test/java/common/order/ReverseOrderLookUpTest.java +++ b/src/test/java/common/order/ReverseOrderLookUpTest.java @@ -4,10 +4,10 @@ import core.mino.Piece; import lib.Randoms; import module.LongTest; -import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; import java.util.Arrays; +import java.util.Collections; import java.util.Comparator; import java.util.List; import java.util.stream.Collectors; @@ -27,7 +27,7 @@ void sample1() { } @Test - void parseJustBlocksCount() throws Exception { + void parseJustBlocksCount() { List pieceList = Piece.valueList(); int toDepth = pieceList.size(); @@ -38,7 +38,7 @@ void parseJustBlocksCount() throws Exception { } @Test - void parseOverBlocksCount() throws Exception { + void parseOverBlocksCount() { List pieceList = Piece.valueList(); int toDepth = pieceList.size() + 1; @@ -49,7 +49,7 @@ void parseOverBlocksCount() throws Exception { } @Test - void parseOver() throws Exception { + void parseOver() { List pieceList = Arrays.asList(Piece.I, Piece.T, Piece.Z, Piece.O, Piece.I, Piece.L); int fromDepth = pieceList.size() + 1; @@ -85,7 +85,7 @@ void parseOver() throws Exception { } @Test - void parseJustRandom() throws Exception { + void parseJustRandom() { Randoms randoms = new Randoms(); for (int size = 2; size <= 13; size++) { List blocks = randoms.blocks(size); @@ -109,7 +109,7 @@ void parseJustRandom() throws Exception { @Test @LongTest - void parseOverRandom() throws Exception { + void parseOverRandom() { Randoms randoms = new Randoms(); for (int size = 2; size <= 13; size++) { List pieces = randoms.blocks(size); @@ -134,7 +134,7 @@ void parseOverRandom() throws Exception { } @Test - void parseOver2Random() throws Exception { + void parseOver2Random() { Randoms randoms = new Randoms(); for (int size = 2; size <= 12; size++) { List pieces = randoms.blocks(size); @@ -157,4 +157,23 @@ void parseOver2Random() throws Exception { } } } + + @Test + void empty() { + { + ReverseOrderLookUp lookUp = new ReverseOrderLookUp(0, 0); + assertThat(lookUp.parse(Collections.emptyList()).map(pieceStream -> pieceStream.collect(Collectors.toList())).collect(Collectors.toList())) + .contains(Collections.emptyList()); + } + { + ReverseOrderLookUp lookUp = new ReverseOrderLookUp(0, 1); + assertThat(lookUp.parse(Collections.emptyList()).map(pieceStream -> pieceStream.collect(Collectors.toList())).collect(Collectors.toList())) + .contains(Collections.singletonList(null)); + } + { + ReverseOrderLookUp lookUp = new ReverseOrderLookUp(0, 2); + assertThat(lookUp.parse(Collections.emptyList()).map(pieceStream -> pieceStream.collect(Collectors.toList())).collect(Collectors.toList())) + .contains(Arrays.asList(null, null)); + } + } } \ No newline at end of file