Search in sources :

Example 11 with Result

use of common.datastore.Result in project solution-finder by knewjade.

the class CheckmateUsingHoldReuseTest method randomCheckmateOverMoreBlock.

@Test
@LongTest
void randomCheckmateOverMoreBlock() {
    Randoms randoms = new Randoms();
    for (int count = 0; count < 25; count++) {
        int maxClearLine = randoms.nextInt(3, 8);
        int maxDepth = randoms.nextIntClosed(5, 7);
        List<Piece> pieces = randoms.blocks(maxDepth + 10);
        Field field = randoms.field(maxClearLine, maxDepth);
        Candidate<Action> candidate = new LockedCandidate(minoFactory, minoShifter, minoRotation, maxClearLine);
        Stopwatch stopwatchNoUse = Stopwatch.createStoppedStopwatch();
        Stopwatch stopwatchReuse = Stopwatch.createStoppedStopwatch();
        for (int swap = 0; swap < 250; swap++) {
            int index = randoms.nextInt(3, pieces.size());
            Piece pop = pieces.remove(index);
            pieces.add(pop);
            stopwatchNoUse.start();
            List<Result> result1 = checkmate.search(field, pieces, candidate, maxClearLine, maxDepth);
            stopwatchNoUse.stop();
            stopwatchReuse.start();
            List<Result> result2 = checkmateReuse.search(field, pieces, candidate, maxClearLine, maxDepth);
            stopwatchReuse.stop();
            assertThat(result2).hasSameSizeAs(result1).containsAll(result1);
        }
        assertThat(stopwatchReuse.getNanoAverageTime()).isLessThan(stopwatchNoUse.getNanoAverageTime());
    }
}
Also used : Field(core.field.Field) LockedCandidate(core.action.candidate.LockedCandidate) Randoms(lib.Randoms) Action(common.datastore.action.Action) Piece(core.mino.Piece) Stopwatch(lib.Stopwatch) Result(common.datastore.Result) Test(org.junit.jupiter.api.Test) LongTest(module.LongTest) LongTest(module.LongTest)

Example 12 with Result

use of common.datastore.Result in project solution-finder by knewjade.

the class CheckmateUsingHoldReuseTest method randomCheckmateOverBlock.

@Test
@LongTest
void randomCheckmateOverBlock() {
    Randoms randoms = new Randoms();
    for (int count = 0; count < 25; count++) {
        int maxClearLine = randoms.nextInt(3, 8);
        int maxDepth = randoms.nextIntClosed(5, 7);
        List<Piece> pieces = randoms.blocks(maxDepth + 1);
        Field field = randoms.field(maxClearLine, maxDepth);
        Candidate<Action> candidate = new LockedCandidate(minoFactory, minoShifter, minoRotation, maxClearLine);
        Stopwatch stopwatchNoUse = Stopwatch.createStoppedStopwatch();
        Stopwatch stopwatchReuse = Stopwatch.createStoppedStopwatch();
        for (int swap = 0; swap < 250; swap++) {
            int index = randoms.nextInt(3, pieces.size());
            Piece pop = pieces.remove(index);
            pieces.add(pop);
            stopwatchNoUse.start();
            List<Result> result1 = checkmate.search(field, pieces, candidate, maxClearLine, maxDepth);
            stopwatchNoUse.stop();
            stopwatchReuse.start();
            List<Result> result2 = checkmateReuse.search(field, pieces, candidate, maxClearLine, maxDepth);
            stopwatchReuse.stop();
            assertThat(result2).hasSameSizeAs(result1).containsAll(result1);
        }
        assertThat(stopwatchReuse.getNanoAverageTime()).isLessThan(stopwatchNoUse.getNanoAverageTime());
    }
}
Also used : Field(core.field.Field) LockedCandidate(core.action.candidate.LockedCandidate) Randoms(lib.Randoms) Action(common.datastore.action.Action) Piece(core.mino.Piece) Stopwatch(lib.Stopwatch) Result(common.datastore.Result) Test(org.junit.jupiter.api.Test) LongTest(module.LongTest) LongTest(module.LongTest)

Example 13 with Result

use of common.datastore.Result in project solution-finder by knewjade.

the class CheckmateUsingHoldReuseTest method randomCheckmateWithJustBlockTwice.

@Disabled
@Test
void randomCheckmateWithJustBlockTwice() {
    Randoms randoms = new Randoms();
    for (int count = 0; count < 25; count++) {
        int maxClearLine = randoms.nextInt(3, 8);
        int maxDepth = randoms.nextIntClosed(5, 7);
        List<Piece> pieces = randoms.blocks(maxDepth);
        Field field = randoms.field(maxClearLine, maxDepth);
        Candidate<Action> candidate = new LockedCandidate(minoFactory, minoShifter, minoRotation, maxClearLine);
        Stopwatch stopwatchNoUse = Stopwatch.createStoppedStopwatch();
        Stopwatch stopwatchReuse1 = Stopwatch.createStoppedStopwatch();
        Stopwatch stopwatchReuse2 = Stopwatch.createStoppedStopwatch();
        for (int swap = 0; swap < 250; swap++) {
            int index = randoms.nextInt(3, pieces.size());
            Piece pop = pieces.remove(index);
            pieces.add(pop);
            stopwatchNoUse.start();
            List<Result> result1 = checkmate.search(field, pieces, candidate, maxClearLine, maxDepth);
            stopwatchNoUse.stop();
            stopwatchReuse1.start();
            List<Result> result2 = checkmateReuse.search(field, pieces, candidate, maxClearLine, maxDepth);
            stopwatchReuse1.stop();
            assertThat(result2).hasSameSizeAs(result1).containsAll(result1);
            stopwatchReuse2.start();
            List<Result> result3 = checkmateReuse.search(field, pieces, candidate, maxClearLine, maxDepth);
            stopwatchReuse2.stop();
            assertThat(result3).hasSameSizeAs(result1).containsAll(result1);
        }
        assertThat(stopwatchReuse1.getNanoAverageTime()).isLessThan(stopwatchNoUse.getNanoAverageTime());
        assertThat(stopwatchReuse2.getNanoAverageTime()).isLessThan(stopwatchReuse1.getNanoAverageTime());
    }
}
Also used : Field(core.field.Field) LockedCandidate(core.action.candidate.LockedCandidate) Randoms(lib.Randoms) Action(common.datastore.action.Action) Piece(core.mino.Piece) Stopwatch(lib.Stopwatch) Result(common.datastore.Result) Test(org.junit.jupiter.api.Test) LongTest(module.LongTest) Disabled(org.junit.jupiter.api.Disabled)

Example 14 with Result

use of common.datastore.Result in project solution-finder by knewjade.

the class Task method call.

@Override
public List<Pair<List<Piece>, List<Result>>> call() throws Exception {
    Checkmate<Action> checkmate = obj.checkmateThreadLocal.get();
    Candidate<Action> candidate = obj.candidateThreadLocal.get();
    // 探索
    List<Pair<List<Piece>, List<Result>>> allResults = new ArrayList<>();
    for (ReadOnlyListPieces piece : targets) {
        List<Piece> pieces = piece.getPieces();
        List<Result> results = checkmate.search(obj.field, pieces, candidate, obj.maxClearLine, obj.maxDepth);
        allResults.add(new Pair<>(pieces, results));
    }
    return allResults;
}
Also used : ReadOnlyListPieces(common.datastore.blocks.ReadOnlyListPieces) Action(common.datastore.action.Action) Piece(core.mino.Piece) ArrayList(java.util.ArrayList) Pair(common.datastore.Pair) Result(common.datastore.Result)

Example 15 with Result

use of common.datastore.Result in project solution-finder by knewjade.

the class ResultPCFComparatorTest method compareDiffLastHold1.

@Test
void compareDiffLastHold1() throws Exception {
    Result result1 = new Result(DUMMY_ORDER, Piece.I, MinimalAction.create(0, 1, Rotate.Spawn), Piece.L);
    Result result2 = new Result(DUMMY_ORDER, Piece.I, MinimalAction.create(0, 1, Rotate.Spawn), Piece.I);
    ResultPCFComparator comparator = new ResultPCFComparator();
    // assert is not 0 & sign reversed
    assertThat(comparator.compare(result1, result2) * comparator.compare(result2, result1)).as(result1.toString()).isLessThan(0);
}
Also used : Result(common.datastore.Result) Test(org.junit.jupiter.api.Test)

Aggregations

Result (common.datastore.Result)21 Test (org.junit.jupiter.api.Test)19 Action (common.datastore.action.Action)9 Field (core.field.Field)9 Piece (core.mino.Piece)9 LockedCandidate (core.action.candidate.LockedCandidate)8 Randoms (lib.Randoms)8 Stopwatch (lib.Stopwatch)8 LongTest (module.LongTest)8 OperationHistory (common.OperationHistory)1 Pair (common.datastore.Pair)1 ReadOnlyListPieces (common.datastore.blocks.ReadOnlyListPieces)1 NormalOrder (common.datastore.order.NormalOrder)1 Order (common.datastore.order.Order)1 Mino (core.mino.Mino)1 ArrayList (java.util.ArrayList)1 Disabled (org.junit.jupiter.api.Disabled)1