use of lib.Randoms in project solution-finder by knewjade.
the class NeighborTest method getNextRightRotateDestinations.
@Test
void getNextRightRotateDestinations() {
OriginalPiece piece = new OriginalPiece(new Mino(Piece.T, Rotate.Spawn), 1, 0, 4);
Neighbor neighbor = new Neighbor(piece);
OriginalPieceFactory factory = new OriginalPieceFactory(4);
List<OriginalPiece> pieces = new ArrayList<>(factory.create());
Randoms randoms = new Randoms();
List<Neighbor> samples = randoms.sample(pieces, 4).stream().map(Neighbor::new).collect(Collectors.toList());
neighbor.updateRightRotateDestination(samples);
assertThat(neighbor.getNextRightRotateDestinations()).containsAll(samples);
}
use of lib.Randoms in project solution-finder by knewjade.
the class HoldBreakEnumeratePiecesTest method enumerateJustRandom.
@Test
void enumerateJustRandom() throws Exception {
Randoms randoms = new Randoms();
for (int size = 3; size <= 15; size++) {
List<Piece> blocks = randoms.blocks(size);
String pattern = blocks.stream().map(Piece::getName).collect(Collectors.joining(","));
PatternGenerator blocksGenerator = new LoadedPatternGenerator(pattern);
HoldBreakEnumeratePieces core = new HoldBreakEnumeratePieces(blocksGenerator, size);
Set<LongPieces> pieces = core.enumerate();
for (int count = 0; count < 10000; count++) {
ArrayList<Piece> sample = new ArrayList<>();
int holdIndex = 0;
for (int index = 1; index < size; index++) {
if (randoms.nextBoolean(0.3)) {
// そのまま追加
sample.add(blocks.get(index));
} else {
// ホールドを追加
sample.add(blocks.get(holdIndex));
holdIndex = index;
}
}
// ホールドを追加
sample.add(blocks.get(holdIndex));
assertThat(new LongPieces(sample)).isIn(pieces);
}
}
}
use of lib.Randoms in project solution-finder by knewjade.
the class ForwardOrderLookUpTest method parseOver2BlocksRandom.
@Test
void parseOver2BlocksRandom() throws Exception {
Randoms randoms = new Randoms();
for (int size = 4; size <= 15; size++) {
List<Piece> pieces = randoms.blocks(size);
int toDepth = pieces.size();
ForwardOrderLookUp lookUp = new ForwardOrderLookUp(toDepth - 2, pieces.size());
HashSet<LongPieces> forward = lookUp.parse(pieces).map(LongPieces::new).collect(Collectors.toCollection(HashSet::new));
for (int count = 0; count < 10000; count++) {
ArrayList<Piece> sample = new ArrayList<>();
int holdIndex = 0;
for (int index = 1; index < size - 1; index++) {
if (randoms.nextBoolean(0.3)) {
// そのまま追加
sample.add(pieces.get(index));
} else {
// ホールドを追加
sample.add(pieces.get(holdIndex));
holdIndex = index;
}
}
assertThat(new LongPieces(sample)).isIn(forward);
}
}
}
use of lib.Randoms in project solution-finder by knewjade.
the class OrderLookupTest method forwardOver2BlocksRandom.
@Test
void forwardOver2BlocksRandom() throws Exception {
Randoms randoms = new Randoms();
for (int size = 4; size <= 13; size++) {
List<Piece> pieceList = randoms.blocks(size);
int toDepth = pieceList.size() - 2;
PiecesNumberComparator comparator = new PiecesNumberComparator();
List<LongPieces> forward1 = OrderLookup.forwardBlocks(pieceList, toDepth).stream().map(StackOrder::toList).map(LongPieces::new).sorted(comparator).collect(Collectors.toList());
ForwardOrderLookUp lookUp = new ForwardOrderLookUp(toDepth, pieceList.size());
List<LongPieces> forward2 = lookUp.parse(pieceList).map(blockStream -> blockStream.collect(Collectors.toList())).map(LongPieces::new).sorted(comparator).collect(Collectors.toList());
assertThat(forward2).isEqualTo(forward1);
}
}
use of lib.Randoms in project solution-finder by knewjade.
the class OrderLookupTest method forwardJustBlocksRandom.
@Test
void forwardJustBlocksRandom() throws Exception {
Randoms randoms = new Randoms();
for (int size = 2; size <= 13; size++) {
List<Piece> pieceList = randoms.blocks(size);
int toDepth = pieceList.size();
PiecesNumberComparator comparator = new PiecesNumberComparator();
List<LongPieces> forward1 = OrderLookup.forwardBlocks(pieceList, toDepth).stream().map(StackOrder::toList).map(LongPieces::new).sorted(comparator).collect(Collectors.toList());
ForwardOrderLookUp lookUp = new ForwardOrderLookUp(toDepth, pieceList.size());
List<LongPieces> forward2 = lookUp.parse(pieceList).map(blockStream -> blockStream.collect(Collectors.toList())).map(LongPieces::new).sorted(comparator).collect(Collectors.toList());
assertThat(forward2).isEqualTo(forward1);
}
}
Aggregations