Skip to content

Commit

Permalink
Merge branch 'filled'
Browse files Browse the repository at this point in the history
  • Loading branch information
knewjade committed Jan 15, 2023
2 parents 9e865d3 + 88b746f commit 47a93cc
Show file tree
Hide file tree
Showing 7 changed files with 82 additions and 14 deletions.
4 changes: 4 additions & 0 deletions src/main/java/common/order/OrderLookup.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ public static ArrayList<StackOrder<Piece>> reverseBlocks(List<Piece> blocks, int
// blocks -- [hold] --> ???
// toDepth: ???の深さ
public static ArrayList<StackOrder<Piece>> forwardBlocks(List<Piece> blocks, int toDepth) {
if (toDepth == 0) {
return new ArrayList<>();
}

if (blocks.size() == 1) {
assert toDepth == 1;
ArrayList<StackOrder<Piece>> candidates = new ArrayList<>();
Expand Down
9 changes: 9 additions & 0 deletions src/main/java/common/order/ReverseOrderLookUp.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -23,6 +24,14 @@ public ReverseOrderLookUp(int toDepth, int fromDepth) {
}

private List<List<Integer>> reverse(int toDepth, int fromDepth) {
if (toDepth == 0) {
List<Integer> integers = new ArrayList<>();
for (int i = 0; i < fromDepth; i++) {
integers.add(-1);
}
return Collections.singletonList(integers);
}

assert 1 <= toDepth;
assert toDepth <= fromDepth;
List<Integer> indexes = IntStream.range(0, toDepth).boxed().collect(Collectors.toList());
Expand Down
7 changes: 4 additions & 3 deletions src/main/java/concurrent/checker/invoker/using_hold/Obj.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package concurrent.checker.invoker.using_hold;

import common.order.ReverseOrderLookUp;
import common.tree.ConcurrentVisitedTree;
import core.field.Field;

Expand All @@ -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;
}
Expand Down
16 changes: 12 additions & 4 deletions src/main/java/concurrent/checker/invoker/using_hold/Task.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -29,14 +29,22 @@ class Task implements Callable<Pair<Pieces, Boolean>> {
}

@Override
public Pair<Pieces, Boolean> call() throws Exception {
public Pair<Pieces, Boolean> call() {
List<Piece> pieceList = target.getPieces();

// すでに探索済みならそのまま結果を追加
int succeed = obj.visitedTree.isSucceed(pieceList);
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<Action> checker = commonObj.checkerThreadLocal.get();
Candidate<Action> candidate = commonObj.candidateThreadLocal.get();
Expand Down
15 changes: 15 additions & 0 deletions src/test/java/_usecase/path/PathTetfuCaseTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
12 changes: 12 additions & 0 deletions src/test/java/_usecase/percent/PercentTetfuCaseTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
33 changes: 26 additions & 7 deletions src/test/java/common/order/ReverseOrderLookUpTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -27,7 +27,7 @@ void sample1() {
}

@Test
void parseJustBlocksCount() throws Exception {
void parseJustBlocksCount() {
List<Piece> pieceList = Piece.valueList();
int toDepth = pieceList.size();

Expand All @@ -38,7 +38,7 @@ void parseJustBlocksCount() throws Exception {
}

@Test
void parseOverBlocksCount() throws Exception {
void parseOverBlocksCount() {
List<Piece> pieceList = Piece.valueList();
int toDepth = pieceList.size() + 1;

Expand All @@ -49,7 +49,7 @@ void parseOverBlocksCount() throws Exception {
}

@Test
void parseOver() throws Exception {
void parseOver() {
List<Piece> pieceList = Arrays.asList(Piece.I, Piece.T, Piece.Z, Piece.O, Piece.I, Piece.L);
int fromDepth = pieceList.size() + 1;

Expand Down Expand Up @@ -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<Piece> blocks = randoms.blocks(size);
Expand All @@ -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<Piece> pieces = randoms.blocks(size);
Expand All @@ -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<Piece> pieces = randoms.blocks(size);
Expand All @@ -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));
}
}
}

0 comments on commit 47a93cc

Please sign in to comment.