Created
February 26, 2022 17:19
-
-
Save hube12/4d04f2d59d3c3241716e7c018789e016 to your computer and use it in GitHub Desktop.
Simple Dungeon reversal with latticg (here 1.12 pos order)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.seedfinding.neil; | |
import com.seedfinding.latticg.reversal.DynamicProgram; | |
import com.seedfinding.latticg.reversal.calltype.java.JavaCalls; | |
import com.seedfinding.latticg.util.LCG; | |
import com.seedfinding.mcseed.rand.JRand; | |
import java.util.List; | |
// repositories { | |
// maven { | |
// url "https://maven.latticg.com/" | |
// } | |
// maven { | |
// url "https://maven.seedfinding.com/" | |
// } | |
// maven { | |
// url "https://maven-snapshots.seedfinding.com/" | |
// } | |
// } | |
// dependencies { | |
// implementation('com.seedfinding:latticg:1.06') | |
// implementation('com.seedfinding:mc_seed:5518e3ba3ee567fb0b51c15958967f70a6a19e02') { transitive = false } | |
// } | |
public class Main { | |
public static void main(String[] args) { | |
// World seed = -1700538326672817507 | |
// Dungeon seed = 14581818956973 | |
String stringPattern = "111110101111111110110110111110011111111111111111111111101111011"; | |
int posX = 137; | |
int posY = 27; | |
int posZ = -147; | |
int sizeX=7; | |
int sizeZ=9; | |
DynamicProgram dynamicProgram = DynamicProgram.create(LCG.JAVA); | |
posX -= 8; | |
posZ -= 8; | |
int offsetX = posX & 15; | |
int offsetZ = posZ & 15; | |
dynamicProgram.add(JavaCalls.nextInt(16).equalTo(offsetX)); | |
dynamicProgram.add(JavaCalls.nextInt(256).equalTo(posY)); | |
dynamicProgram.add(JavaCalls.nextInt(16).equalTo(offsetZ)); | |
dynamicProgram.add(JavaCalls.nextInt(2).equalTo((sizeX-7)/2)); | |
dynamicProgram.add(JavaCalls.nextInt(2).equalTo((sizeZ-7)/2)); | |
Integer[] pattern = stringPattern.chars().mapToObj(c -> c == '0' ? 0 : c == '1' ? 1 : 2).toArray(Integer[]::new); | |
for (Integer integer : pattern) { | |
if (integer == 0) { | |
dynamicProgram.add(JavaCalls.nextInt(4).equalTo(0)); | |
} else if (integer == 1) { | |
dynamicProgram.filteredSkip(r->r.nextInt(4)!=0,1); | |
} else { | |
dynamicProgram.skip(1); | |
} | |
} | |
long time=System.currentTimeMillis(); | |
List<Long> list = dynamicProgram.reverse().parallel().boxed().toList(); | |
System.out.println("Took "+(System.currentTimeMillis()-time)+" ms"); | |
System.out.println("Count: " + list.size()); | |
int counter = 0; | |
for (long seed : list) { | |
if (!checkBack(pattern, seed ^ LCG.JAVA.multiplier)) { | |
counter++; | |
} | |
} | |
System.out.println("Pruned : " + counter); | |
} | |
public static boolean checkBack(Integer[] pattern, long seed) { | |
JRand rand = new JRand(seed); | |
rand.nextInt(16); | |
rand.nextInt(256); | |
rand.nextInt(16); | |
rand.nextInt(2); | |
rand.nextInt(2); | |
for (Integer integer : pattern) { | |
if (integer == 0) { | |
if (rand.nextInt(4) != 0) { | |
return false; | |
} | |
} else if (integer == 1) { | |
if (rand.nextInt(4) == 0) { | |
return false; | |
} | |
} else { | |
rand.nextInt(4); | |
} | |
} | |
return true; | |
} | |
} |
Author
hube12
commented
Feb 26, 2022
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment